• 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/ftrace/ftrace_descriptors.h"
23 #include "src/trace_processor/importers/ftrace/rss_stat_tracker.h"
24 #include "src/trace_processor/importers/ftrace/sched_event_tracker.h"
25 #include "src/trace_processor/timestamped_trace_piece.h"
26 #include "src/trace_processor/types/trace_processor_context.h"
27 
28 namespace perfetto {
29 namespace trace_processor {
30 
31 class FtraceParser {
32  public:
33   explicit FtraceParser(TraceProcessorContext* context);
34 
35   void ParseFtraceStats(protozero::ConstBytes);
36 
37   util::Status ParseFtraceEvent(uint32_t cpu, const TimestampedTracePiece& ttp);
38 
39  private:
40   void ParseGenericFtrace(int64_t timestamp,
41                           uint32_t cpu,
42                           uint32_t pid,
43                           protozero::ConstBytes);
44   void ParseTypedFtraceToRaw(uint32_t ftrace_id,
45                              int64_t timestamp,
46                              uint32_t cpu,
47                              uint32_t pid,
48                              protozero::ConstBytes,
49                              PacketSequenceStateGeneration*);
50   void ParseSchedSwitch(uint32_t cpu, int64_t timestamp, protozero::ConstBytes);
51   void ParseSchedWakeup(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
52   void ParseSchedWaking(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
53   void ParseSchedProcessFree(int64_t timestamp, protozero::ConstBytes);
54   void ParseCpuFreq(int64_t timestamp, protozero::ConstBytes);
55   void ParseGpuFreq(int64_t timestamp, protozero::ConstBytes);
56   void ParseCpuIdle(int64_t timestamp, protozero::ConstBytes);
57   void ParsePrint(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
58   void ParseZero(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
59   void ParseSdeTracingMarkWrite(int64_t timestamp,
60                                 uint32_t pid,
61                                 protozero::ConstBytes);
62   void ParseDpuTracingMarkWrite(int64_t timestamp,
63                                 uint32_t pid,
64                                 protozero::ConstBytes);
65   void ParseG2dTracingMarkWrite(int64_t timestamp,
66                                 uint32_t pid,
67                                 protozero::ConstBytes);
68   void ParseMaliTracingMarkWrite(int64_t timestamp,
69                                  uint32_t pid,
70                                  protozero::ConstBytes);
71   void ParseIonHeapGrowOrShrink(int64_t timestamp,
72                                 uint32_t pid,
73                                 protozero::ConstBytes,
74                                 bool grow);
75   void ParseIonStat(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
76   void ParseDmaHeapStat(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
77   void ParseSignalGenerate(int64_t timestamp, protozero::ConstBytes);
78   void ParseSignalDeliver(int64_t timestamp,
79                           uint32_t pid,
80                           protozero::ConstBytes);
81   void ParseLowmemoryKill(int64_t timestamp, protozero::ConstBytes);
82   void ParseOOMScoreAdjUpdate(int64_t timestamp, protozero::ConstBytes);
83   void ParseOOMKill(int64_t timestamp, protozero::ConstBytes);
84   void ParseMmEventRecord(int64_t timestamp,
85                           uint32_t pid,
86                           protozero::ConstBytes);
87   void ParseSysEvent(int64_t timestamp,
88                      uint32_t pid,
89                      bool is_enter,
90                      protozero::ConstBytes);
91   void ParseTaskNewTask(int64_t timestamp,
92                         uint32_t source_tid,
93                         protozero::ConstBytes);
94   void ParseTaskRename(protozero::ConstBytes);
95   void ParseBinderTransaction(int64_t timestamp,
96                               uint32_t pid,
97                               protozero::ConstBytes);
98   void ParseBinderTransactionReceived(int64_t timestamp,
99                                       uint32_t pid,
100                                       protozero::ConstBytes);
101   void ParseBinderTransactionAllocBuf(int64_t timestamp,
102                                       uint32_t pid,
103                                       protozero::ConstBytes);
104   void ParseBinderLocked(int64_t timestamp,
105                          uint32_t pid,
106                          protozero::ConstBytes);
107   void ParseBinderLock(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
108   void ParseBinderUnlock(int64_t timestamp,
109                          uint32_t pid,
110                          protozero::ConstBytes);
111   void ParseClockSetRate(int64_t timestamp, protozero::ConstBytes);
112   void ParseClockEnable(int64_t timestamp, protozero::ConstBytes);
113   void ParseClockDisable(int64_t timestamp, protozero::ConstBytes);
114   void ClockRate(int64_t timestamp,
115                  base::StringView clock_name,
116                  base::StringView subtitle,
117                  uint64_t rate);
118   void ParseScmCallStart(int64_t timestamp,
119                          uint32_t pid,
120                          protozero::ConstBytes);
121   void ParseScmCallEnd(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
122   void ParseDirectReclaimBegin(int64_t timestamp,
123                                uint32_t pid,
124                                protozero::ConstBytes);
125   void ParseDirectReclaimEnd(int64_t timestamp,
126                              uint32_t pid,
127                              protozero::ConstBytes);
128   void ParseWorkqueueExecuteStart(uint32_t cpu,
129                                   int64_t timestamp,
130                                   uint32_t pid,
131                                   protozero::ConstBytes,
132                                   PacketSequenceStateGeneration* seq_state);
133   void ParseWorkqueueExecuteEnd(int64_t timestamp,
134                                 uint32_t pid,
135                                 protozero::ConstBytes);
136   void ParseIrqHandlerEntry(uint32_t cpu,
137                             int64_t timestamp,
138                             protozero::ConstBytes);
139   void ParseIrqHandlerExit(uint32_t cpu,
140                            int64_t timestamp,
141                            protozero::ConstBytes);
142   void ParseSoftIrqEntry(uint32_t cpu,
143                          int64_t timestamp,
144                          protozero::ConstBytes);
145   void ParseSoftIrqExit(uint32_t cpu, int64_t timestamp, protozero::ConstBytes);
146   void ParseGpuMemTotal(int64_t timestamp, protozero::ConstBytes);
147   void ParseThermalTemperature(int64_t timestamp, protozero::ConstBytes);
148   void ParseCdevUpdate(int64_t timestamp, protozero::ConstBytes);
149   void ParseSchedBlockedReason(int64_t timestamp,
150                                protozero::ConstBytes,
151                                PacketSequenceStateGeneration*);
152   void ParseFastRpcDmaStat(int64_t timestamp,
153                            uint32_t pid,
154                            protozero::ConstBytes);
155   void ParseCpuhpPause(int64_t, uint32_t, protozero::ConstBytes);
156   void ParseNetifReceiveSkb(uint32_t cpu,
157                             int64_t timestamp,
158                             protozero::ConstBytes);
159   void ParseNetDevXmit(uint32_t cpu, int64_t timestamp, protozero::ConstBytes);
160   void ParseInetSockSetState(int64_t timestamp,
161                              uint32_t pid,
162                              protozero::ConstBytes);
163   void ParseTcpRetransmitSkb(int64_t timestamp, protozero::ConstBytes);
164   void ParseNapiGroReceiveEntry(uint32_t cpu,
165                                 int64_t timestamp,
166                                 protozero::ConstBytes);
167   void ParseNapiGroReceiveExit(uint32_t cpu,
168                                int64_t timestamp,
169                                protozero::ConstBytes);
170   void ParseCpuFrequencyLimits(int64_t timestamp, protozero::ConstBytes);
171   void ParseKfreeSkb(int64_t timestamp, protozero::ConstBytes);
172   void ParseUfshcdCommand(int64_t timestamp, protozero::ConstBytes);
173   void ParseUfshcdClkGating(int64_t timestamp, protozero::ConstBytes);
174 
175   void ParseCrosEcSensorhubData(int64_t timestamp, protozero::ConstBytes);
176   void ParseWakeSourceActivate(int64_t timestamp, protozero::ConstBytes);
177   void ParseWakeSourceDeactivate(int64_t timestamp, protozero::ConstBytes);
178   void ParseSuspendResume(int64_t timestamp, protozero::ConstBytes);
179 
180   TraceProcessorContext* context_;
181   RssStatTracker rss_stat_tracker_;
182 
183   const StringId sched_wakeup_name_id_;
184   const StringId sched_waking_name_id_;
185   const StringId cpu_id_;
186   const StringId cpu_freq_name_id_;
187   const StringId gpu_freq_name_id_;
188   const StringId cpu_idle_name_id_;
189   const StringId suspend_resume_name_id_;
190   const StringId kfree_skb_name_id_;
191   const StringId ion_total_id_;
192   const StringId ion_change_id_;
193   const StringId ion_buffer_id_;
194   const StringId dma_heap_total_id_;
195   const StringId dma_heap_change_id_;
196   const StringId dma_buffer_id_;
197   const StringId ion_total_unknown_id_;
198   const StringId ion_change_unknown_id_;
199   const StringId signal_generate_id_;
200   const StringId signal_deliver_id_;
201   const StringId oom_score_adj_id_;
202   const StringId lmk_id_;
203   const StringId comm_name_id_;
204   const StringId signal_name_id_;
205   const StringId oom_kill_id_;
206   const StringId workqueue_id_;
207   const StringId irq_id_;
208   const StringId tcp_state_id_;
209   const StringId tcp_event_id_;
210   const StringId protocol_arg_id_;
211   const StringId napi_gro_id_;
212   const StringId tcp_retransmited_name_id_;
213   const StringId ret_arg_id_;
214   const StringId len_arg_id_;
215   const StringId direct_reclaim_nr_reclaimed_id_;
216   const StringId direct_reclaim_order_id_;
217   const StringId direct_reclaim_may_writepage_id_;
218   const StringId direct_reclaim_gfp_flags_id_;
219   const StringId vec_arg_id_;
220   const StringId gpu_mem_total_name_id_;
221   const StringId gpu_mem_total_unit_id_;
222   const StringId gpu_mem_total_global_desc_id_;
223   const StringId gpu_mem_total_proc_desc_id_;
224   const StringId sched_blocked_reason_id_;
225   const StringId io_wait_id_;
226   const StringId function_id_;
227   const StringId waker_utid_id_;
228   const StringId cros_ec_arg_num_id_;
229   const StringId cros_ec_arg_ec_id_;
230   const StringId cros_ec_arg_sample_ts_id_;
231   const StringId ufs_clkgating_id_;
232   const StringId ufs_command_count_id_;
233 
234   struct FtraceMessageStrings {
235     // The string id of name of the event field (e.g. sched_switch's id).
236     StringId message_name_id = kNullStringId;
237     std::array<StringId, kMaxFtraceEventFields> field_name_ids;
238   };
239   std::vector<FtraceMessageStrings> ftrace_message_strings_;
240 
241   struct MmEventCounterNames {
242     MmEventCounterNames() = default;
MmEventCounterNamesMmEventCounterNames243     MmEventCounterNames(StringId _count, StringId _max_lat, StringId _avg_lat)
244         : count(_count), max_lat(_max_lat), avg_lat(_avg_lat) {}
245 
246     StringId count = kNullStringId;
247     StringId max_lat = kNullStringId;
248     StringId avg_lat = kNullStringId;
249   };
250 
251   static constexpr size_t kFastRpcCounterSize = 4;
252   std::array<StringId, kFastRpcCounterSize> fast_rpc_delta_names_;
253   std::array<StringId, kFastRpcCounterSize> fast_rpc_total_names_;
254 
255   // Keep kMmEventCounterSize equal to mm_event_type::MM_TYPE_NUM in the kernel.
256   static constexpr size_t kMmEventCounterSize = 7;
257   std::array<MmEventCounterNames, kMmEventCounterSize> mm_event_counter_names_;
258 
259   // Record number of received bytes from the network interface card.
260   std::unordered_map<StringId, uint64_t> nic_received_bytes_;
261 
262   // Record number of transmitted bytes to the network interface card.
263   std::unordered_map<StringId, uint64_t> nic_transmitted_bytes_;
264 
265   // Record number of kfree_skb with ip protocol.
266   uint64_t num_of_kfree_skb_ip_prot = 0;
267 
268   // Keep sock to stream number mapping.
269   std::unordered_map<uint64_t, uint32_t> skaddr_to_stream_;
270 
271   // Record number of tcp steams.
272   uint32_t num_of_tcp_stream_ = 0;
273 
274   // A name collision is possible, always show if active wakelock exists
275   // with a give name
276   std::unordered_map<std::string, uint32_t> active_wakelock_to_count_;
277 
278   bool has_seen_first_ftrace_packet_ = false;
279 
280   // Stores information about the timestamp from the metadata table which is
281   // used to filter ftrace packets which happen before this point.
282   int64_t drop_ftrace_data_before_ts_ = 0;
283 };
284 
285 }  // namespace trace_processor
286 }  // namespace perfetto
287 
288 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_FTRACE_PARSER_H_
289