• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_FTRACE_PARSER_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_FTRACE_PARSER_H_
19 
20 #include "perfetto/trace_processor/status.h"
21 #include "src/trace_processor/importers/common/event_tracker.h"
22 #include "src/trace_processor/importers/common/trace_blob_view.h"
23 #include "src/trace_processor/importers/ftrace/ftrace_descriptors.h"
24 #include "src/trace_processor/importers/ftrace/rss_stat_tracker.h"
25 #include "src/trace_processor/importers/ftrace/sched_event_tracker.h"
26 #include "src/trace_processor/timestamped_trace_piece.h"
27 #include "src/trace_processor/types/trace_processor_context.h"
28 
29 namespace perfetto {
30 namespace trace_processor {
31 
32 class FtraceParser {
33  public:
34   explicit FtraceParser(TraceProcessorContext* context);
35 
36   void ParseFtraceStats(protozero::ConstBytes);
37 
38   util::Status ParseFtraceEvent(uint32_t cpu, const TimestampedTracePiece& ttp);
39 
40  private:
41   void ParseGenericFtrace(int64_t timestamp,
42                           uint32_t cpu,
43                           uint32_t pid,
44                           protozero::ConstBytes);
45   void ParseTypedFtraceToRaw(uint32_t ftrace_id,
46                              int64_t timestamp,
47                              uint32_t cpu,
48                              uint32_t pid,
49                              protozero::ConstBytes,
50                              PacketSequenceStateGeneration*);
51   void ParseSchedSwitch(uint32_t cpu, int64_t timestamp, protozero::ConstBytes);
52   void ParseSchedWakeup(int64_t timestamp, protozero::ConstBytes);
53   void ParseSchedWaking(int64_t timestamp, protozero::ConstBytes);
54   void ParseSchedProcessFree(int64_t timestamp, protozero::ConstBytes);
55   void ParseCpuFreq(int64_t timestamp, protozero::ConstBytes);
56   void ParseGpuFreq(int64_t timestamp, protozero::ConstBytes);
57   void ParseCpuIdle(int64_t timestamp, protozero::ConstBytes);
58   void ParsePrint(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
59   void ParseZero(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
60   void ParseSdeTracingMarkWrite(int64_t timestamp,
61                                 uint32_t pid,
62                                 protozero::ConstBytes);
63   void ParseDpuTracingMarkWrite(int64_t timestamp,
64                                 uint32_t pid,
65                                 protozero::ConstBytes);
66   void ParseG2dTracingMarkWrite(int64_t timestamp,
67                                 uint32_t pid,
68                                 protozero::ConstBytes);
69   void ParseMaliTracingMarkWrite(int64_t timestamp,
70                                  uint32_t pid,
71                                  protozero::ConstBytes);
72   void ParseIonHeapGrowOrShrink(int64_t timestamp,
73                                 uint32_t pid,
74                                 protozero::ConstBytes,
75                                 bool grow);
76   void ParseIonStat(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
77   void ParseDmaHeapStat(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
78   void ParseSignalGenerate(int64_t timestamp, protozero::ConstBytes);
79   void ParseSignalDeliver(int64_t timestamp,
80                           uint32_t pid,
81                           protozero::ConstBytes);
82   void ParseLowmemoryKill(int64_t timestamp, protozero::ConstBytes);
83   void ParseOOMScoreAdjUpdate(int64_t timestamp, protozero::ConstBytes);
84   void ParseOOMKill(int64_t timestamp, protozero::ConstBytes);
85   void ParseMmEventRecord(int64_t timestamp,
86                           uint32_t pid,
87                           protozero::ConstBytes);
88   void ParseSysEvent(int64_t timestamp,
89                      uint32_t pid,
90                      bool is_enter,
91                      protozero::ConstBytes);
92   void ParseTaskNewTask(int64_t timestamp,
93                         uint32_t source_tid,
94                         protozero::ConstBytes);
95   void ParseTaskRename(protozero::ConstBytes);
96   void ParseBinderTransaction(int64_t timestamp,
97                               uint32_t pid,
98                               protozero::ConstBytes);
99   void ParseBinderTransactionReceived(int64_t timestamp,
100                                       uint32_t pid,
101                                       protozero::ConstBytes);
102   void ParseBinderTransactionAllocBuf(int64_t timestamp,
103                                       uint32_t pid,
104                                       protozero::ConstBytes);
105   void ParseBinderLocked(int64_t timestamp,
106                          uint32_t pid,
107                          protozero::ConstBytes);
108   void ParseBinderLock(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
109   void ParseBinderUnlock(int64_t timestamp,
110                          uint32_t pid,
111                          protozero::ConstBytes);
112   void ParseClockSetRate(int64_t timestamp, protozero::ConstBytes);
113   void ParseClockEnable(int64_t timestamp, protozero::ConstBytes);
114   void ParseClockDisable(int64_t timestamp, protozero::ConstBytes);
115   void ClockRate(int64_t timestamp,
116                  base::StringView clock_name,
117                  base::StringView subtitle,
118                  uint64_t rate);
119   void ParseScmCallStart(int64_t timestamp,
120                          uint32_t pid,
121                          protozero::ConstBytes);
122   void ParseScmCallEnd(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
123   void ParseWorkqueueExecuteStart(int64_t timestamp,
124                                   uint32_t pid,
125                                   protozero::ConstBytes,
126                                   PacketSequenceStateGeneration* seq_state);
127   void ParseWorkqueueExecuteEnd(int64_t timestamp,
128                                 uint32_t pid,
129                                 protozero::ConstBytes);
130   void ParseIrqHandlerEntry(uint32_t cpu,
131                             int64_t timestamp,
132                             protozero::ConstBytes);
133   void ParseIrqHandlerExit(uint32_t cpu,
134                            int64_t timestamp,
135                            protozero::ConstBytes);
136   void ParseSoftIrqEntry(uint32_t cpu,
137                          int64_t timestamp,
138                          protozero::ConstBytes);
139   void ParseSoftIrqExit(uint32_t cpu, int64_t timestamp, protozero::ConstBytes);
140   void ParseGpuMemTotal(int64_t timestamp, protozero::ConstBytes);
141   void ParseThermalTemperature(int64_t timestamp, protozero::ConstBytes);
142   void ParseCdevUpdate(int64_t timestamp, protozero::ConstBytes);
143   void ParseSchedBlockedReason(int64_t timestamp,
144                                protozero::ConstBytes,
145                                PacketSequenceStateGeneration*);
146   void ParseFastRpcDmaStat(int64_t timestamp,
147                            uint32_t pid,
148                            protozero::ConstBytes);
149   void ParseCpuhpPause(int64_t, uint32_t, protozero::ConstBytes);
150 
151   TraceProcessorContext* context_;
152   RssStatTracker rss_stat_tracker_;
153 
154   const StringId sched_wakeup_name_id_;
155   const StringId sched_waking_name_id_;
156   const StringId cpu_freq_name_id_;
157   const StringId gpu_freq_name_id_;
158   const StringId cpu_idle_name_id_;
159   const StringId ion_total_id_;
160   const StringId ion_change_id_;
161   const StringId ion_buffer_id_;
162   const StringId dma_heap_total_id_;
163   const StringId dma_heap_change_id_;
164   const StringId dma_buffer_id_;
165   const StringId ion_total_unknown_id_;
166   const StringId ion_change_unknown_id_;
167   const StringId signal_generate_id_;
168   const StringId signal_deliver_id_;
169   const StringId oom_score_adj_id_;
170   const StringId lmk_id_;
171   const StringId comm_name_id_;
172   const StringId signal_name_id_;
173   const StringId oom_kill_id_;
174   const StringId workqueue_id_;
175   const StringId irq_id_;
176   const StringId ret_arg_id_;
177   const StringId vec_arg_id_;
178   const StringId gpu_mem_total_name_id_;
179   const StringId gpu_mem_total_unit_id_;
180   const StringId gpu_mem_total_global_desc_id_;
181   const StringId gpu_mem_total_proc_desc_id_;
182   const StringId sched_blocked_reason_id_;
183   const StringId io_wait_id_;
184   const StringId function_id_;
185 
186   struct FtraceMessageStrings {
187     // The string id of name of the event field (e.g. sched_switch's id).
188     StringId message_name_id = kNullStringId;
189     std::array<StringId, kMaxFtraceEventFields> field_name_ids;
190   };
191   std::vector<FtraceMessageStrings> ftrace_message_strings_;
192 
193   struct MmEventCounterNames {
194     MmEventCounterNames() = default;
MmEventCounterNamesMmEventCounterNames195     MmEventCounterNames(StringId _count, StringId _max_lat, StringId _avg_lat)
196         : count(_count), max_lat(_max_lat), avg_lat(_avg_lat) {}
197 
198     StringId count = kNullStringId;
199     StringId max_lat = kNullStringId;
200     StringId avg_lat = kNullStringId;
201   };
202 
203   static constexpr size_t kFastRpcCounterSize = 4;
204   std::array<StringId, kFastRpcCounterSize> fast_rpc_delta_names_;
205   std::array<StringId, kFastRpcCounterSize> fast_rpc_total_names_;
206 
207   // Keep kMmEventCounterSize equal to mm_event_type::MM_TYPE_NUM in the kernel.
208   static constexpr size_t kMmEventCounterSize = 7;
209   std::array<MmEventCounterNames, kMmEventCounterSize> mm_event_counter_names_;
210 
211   bool has_seen_first_ftrace_packet_ = false;
212 
213   // Stores information about the timestamp from the metadata table which is
214   // used to filter ftrace packets which happen before this point.
215   int64_t drop_ftrace_data_before_ts_ = 0;
216 };
217 
218 }  // namespace trace_processor
219 }  // namespace perfetto
220 
221 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_FTRACE_PARSER_H_
222