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