• 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/binder_tracker.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/trace_blob_view.h"
28 #include "src/trace_processor/types/trace_processor_context.h"
29 
30 namespace perfetto {
31 namespace trace_processor {
32 
33 class FtraceParser {
34  public:
35   explicit FtraceParser(TraceProcessorContext* context);
36 
37   void ParseFtraceStats(protozero::ConstBytes);
38 
39   util::Status ParseFtraceEvent(uint32_t cpu, const TimestampedTracePiece& ttp);
40 
41  private:
42   void ParseGenericFtrace(int64_t timestamp,
43                           uint32_t cpu,
44                           uint32_t pid,
45                           protozero::ConstBytes);
46   void ParseTypedFtraceToRaw(uint32_t ftrace_id,
47                              int64_t timestamp,
48                              uint32_t cpu,
49                              uint32_t pid,
50                              protozero::ConstBytes);
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 ParseIonHeapGrowOrShrink(int64_t ts,
64                                 uint32_t pid,
65                                 protozero::ConstBytes,
66                                 bool grow);
67   void ParseIonStat(int64_t ts, uint32_t pid, protozero::ConstBytes);
68   void ParseSignalGenerate(int64_t ts, protozero::ConstBytes);
69   void ParseSignalDeliver(int64_t ts, uint32_t pid, protozero::ConstBytes);
70   void ParseLowmemoryKill(int64_t ts, protozero::ConstBytes);
71   void ParseOOMScoreAdjUpdate(int64_t ts, protozero::ConstBytes);
72   void ParseOOMKill(int64_t ts, protozero::ConstBytes);
73   void ParseMmEventRecord(int64_t ts, uint32_t pid, protozero::ConstBytes);
74   void ParseSysEvent(int64_t ts,
75                      uint32_t pid,
76                      bool is_enter,
77                      protozero::ConstBytes);
78   void ParseTaskNewTask(int64_t timestamp,
79                         uint32_t source_tid,
80                         protozero::ConstBytes);
81   void ParseTaskRename(protozero::ConstBytes);
82   void ParseBinderTransaction(int64_t timestamp,
83                               uint32_t pid,
84                               protozero::ConstBytes);
85   void ParseBinderTransactionReceived(int64_t timestamp,
86                                       uint32_t pid,
87                                       protozero::ConstBytes);
88   void ParseBinderTransactionAllocBuf(int64_t timestamp,
89                                       uint32_t pid,
90                                       protozero::ConstBytes);
91   void ParseBinderLocked(int64_t timestamp,
92                          uint32_t pid,
93                          protozero::ConstBytes);
94   void ParseBinderLock(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
95   void ParseBinderUnlock(int64_t timestamp,
96                          uint32_t pid,
97                          protozero::ConstBytes);
98 
99   TraceProcessorContext* context_;
100   RssStatTracker rss_stat_tracker_;
101 
102   const StringId sched_wakeup_name_id_;
103   const StringId sched_waking_name_id_;
104   const StringId cpu_freq_name_id_;
105   const StringId gpu_freq_name_id_;
106   const StringId cpu_idle_name_id_;
107   const StringId ion_total_id_;
108   const StringId ion_change_id_;
109   const StringId ion_total_unknown_id_;
110   const StringId ion_change_unknown_id_;
111   const StringId signal_generate_id_;
112   const StringId signal_deliver_id_;
113   const StringId oom_score_adj_id_;
114   const StringId lmk_id_;
115   const StringId comm_name_id_;
116   const StringId signal_name_id_;
117   const StringId oom_kill_id_;
118 
119   struct FtraceMessageStrings {
120     // The string id of name of the event field (e.g. sched_switch's id).
121     StringId message_name_id = kNullStringId;
122     std::array<StringId, kMaxFtraceEventFields> field_name_ids;
123   };
124   std::vector<FtraceMessageStrings> ftrace_message_strings_;
125 
126   struct MmEventCounterNames {
127     MmEventCounterNames() = default;
MmEventCounterNamesMmEventCounterNames128     MmEventCounterNames(StringId _count, StringId _max_lat, StringId _avg_lat)
129         : count(_count), max_lat(_max_lat), avg_lat(_avg_lat) {}
130 
131     StringId count = kNullStringId;
132     StringId max_lat = kNullStringId;
133     StringId avg_lat = kNullStringId;
134   };
135 
136   // Keep kMmEventCounterSize equal to mm_event_type::MM_TYPE_NUM in the kernel.
137   static constexpr size_t kMmEventCounterSize = 7;
138   std::array<MmEventCounterNames, kMmEventCounterSize> mm_event_counter_names_;
139 };
140 
141 }  // namespace trace_processor
142 }  // namespace perfetto
143 
144 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_FTRACE_PARSER_H_
145