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 "protos/perfetto/trace/sys_stats/sys_stats.pbzero.h" 26 #include "src/trace_processor/storage/trace_storage.h" 27 28 namespace perfetto { 29 namespace trace_processor { 30 31 class TraceProcessorContext; 32 33 class SystemProbesParser { 34 public: 35 using ConstBytes = protozero::ConstBytes; 36 using ConstChars = protozero::ConstChars; 37 38 explicit SystemProbesParser(TraceProcessorContext*); 39 40 void ParseProcessTree(ConstBytes); 41 void ParseProcessStats(int64_t timestamp, ConstBytes); 42 void ParseSysStats(int64_t ts, ConstBytes); 43 void ParseSystemInfo(ConstBytes); 44 void ParseCpuInfo(ConstBytes); 45 46 private: 47 void ParseThreadStats(int64_t timestamp, uint32_t pid, ConstBytes); 48 void ParseDiskStats(int64_t ts, ConstBytes blob); 49 void ParseProcessFds(int64_t ts, uint32_t pid, ConstBytes); 50 51 TraceProcessorContext* const context_; 52 53 const StringId utid_name_id_; 54 const StringId num_forks_name_id_; 55 const StringId num_irq_total_name_id_; 56 const StringId num_softirq_total_name_id_; 57 const StringId num_irq_name_id_; 58 const StringId num_softirq_name_id_; 59 const StringId cpu_times_user_ns_id_; 60 const StringId cpu_times_user_nice_ns_id_; 61 const StringId cpu_times_system_mode_ns_id_; 62 const StringId cpu_times_idle_ns_id_; 63 const StringId cpu_times_io_wait_ns_id_; 64 const StringId cpu_times_irq_ns_id_; 65 const StringId cpu_times_softirq_ns_id_; 66 const StringId oom_score_adj_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 = 21; 76 std::array<StringId, kProcStatsProcessSize> proc_stats_process_names_{}; 77 78 uint64_t ms_per_tick_ = 0; 79 uint32_t page_size_ = 0; 80 81 int64_t prev_read_amount = -1; 82 int64_t prev_write_amount = -1; 83 int64_t prev_discard_amount = -1; 84 int64_t prev_flush_count = -1; 85 int64_t prev_read_time = -1; 86 int64_t prev_write_time = -1; 87 int64_t prev_discard_time = -1; 88 int64_t prev_flush_time = -1; 89 }; 90 91 } // namespace trace_processor 92 } // namespace perfetto 93 94 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_SYSTEM_PROBES_PARSER_H_ 95