• 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_PROTO_SYSTEM_PROBES_PARSER_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_SYSTEM_PROBES_PARSER_H_
19 
20 #include <array>
21 #include <set>
22 #include <vector>
23 
24 #include "perfetto/protozero/field.h"
25 #include "src/trace_processor/storage/trace_storage.h"
26 
27 namespace perfetto {
28 namespace trace_processor {
29 
30 class TraceProcessorContext;
31 
32 class SystemProbesParser {
33  public:
34   using ConstBytes = protozero::ConstBytes;
35   using ConstChars = protozero::ConstChars;
36 
37   explicit SystemProbesParser(TraceProcessorContext*);
38 
39   void ParseProcessTree(ConstBytes);
40   void ParseProcessStats(int64_t timestamp, ConstBytes);
41   void ParseSysStats(int64_t ts, ConstBytes);
42   void ParseSystemInfo(ConstBytes);
43   void ParseCpuInfo(ConstBytes);
44 
45  private:
46   void ParseThreadStats(int64_t timestamp, uint32_t pid, ConstBytes);
47   inline bool IsValidCpuFreqIndex(uint32_t freq) const;
48 
49   TraceProcessorContext* const context_;
50 
51   const StringId utid_name_id_;
52   const StringId num_forks_name_id_;
53   const StringId num_irq_total_name_id_;
54   const StringId num_softirq_total_name_id_;
55   const StringId num_irq_name_id_;
56   const StringId num_softirq_name_id_;
57   const StringId cpu_times_user_ns_id_;
58   const StringId cpu_times_user_nice_ns_id_;
59   const StringId cpu_times_system_mode_ns_id_;
60   const StringId cpu_times_idle_ns_id_;
61   const StringId cpu_times_io_wait_ns_id_;
62   const StringId cpu_times_irq_ns_id_;
63   const StringId cpu_times_softirq_ns_id_;
64   const StringId oom_score_adj_id_;
65   const StringId thread_time_in_state_id_;
66   const StringId thread_time_in_state_cpu_id_;
67   const StringId cpu_freq_id_;
68   std::vector<StringId> meminfo_strs_id_;
69   std::vector<StringId> vmstat_strs_id_;
70 
71   // Maps a proto field number for memcounters in ProcessStats::Process to
72   // their StringId. Keep kProcStatsProcessSize equal to 1 + max proto field
73   // id of ProcessStats::Process. Also update the value in
74   // ChromeSystemProbesParser.
75   static constexpr size_t kProcStatsProcessSize = 15;
76   std::array<StringId, kProcStatsProcessSize> proc_stats_process_names_{};
77 
78   uint64_t ms_per_tick_ = 0;
79 
80   // Maps CPU frequency indices to frequencies from the cpu_freq table to be
81   // stored in the args table as a dimension of the time_in_state counter.
82   // Includes guards at both ends.
83   std::vector<uint32_t> thread_time_in_state_cpu_freqs_;
84 
85   // thread_time_in_state_freq_index_[cpu] points to the first frequency for
86   // cpu in thread_time_in_state_cpu_freq_ids_. Includes a guard at the end.
87   std::vector<size_t> thread_time_in_state_freq_index_;
88 
89   // Exhaustive set of CPU indices that are reported by time_in_state. Ticks are
90   // counted per core cluster. See time_in_state_cpu_id column of the cpu table.
91   // For example: on bonito (Pixel 3a XL) this set is 0 (little) and 6 (big).
92   std::set<uint32_t> thread_time_in_state_cpus_;
93 };
94 }  // namespace trace_processor
95 }  // namespace perfetto
96 
97 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_SYSTEM_PROBES_PARSER_H_
98