• 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 <vector>
22 
23 #include "perfetto/protozero/field.h"
24 #include "protos/perfetto/trace/sys_stats/sys_stats.pbzero.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   void ParseDiskStats(int64_t ts, ConstBytes blob);
48   void ParseProcessFds(int64_t ts, uint32_t pid, ConstBytes);
49 
50   TraceProcessorContext* const context_;
51 
52   const StringId utid_name_id_;
53   const StringId ns_unit_id_;
54   const StringId bytes_unit_id_;
55   const StringId available_chunks_unit_id_;
56 
57   const StringId num_forks_name_id_;
58   const StringId num_irq_total_name_id_;
59   const StringId num_softirq_total_name_id_;
60   const StringId num_irq_name_id_;
61   const StringId num_softirq_name_id_;
62   const StringId cpu_times_user_ns_id_;
63   const StringId cpu_times_user_nice_ns_id_;
64   const StringId cpu_times_system_mode_ns_id_;
65   const StringId cpu_times_idle_ns_id_;
66   const StringId cpu_times_io_wait_ns_id_;
67   const StringId cpu_times_irq_ns_id_;
68   const StringId cpu_times_softirq_ns_id_;
69   const StringId oom_score_adj_id_;
70   const StringId cpu_freq_id_;
71   std::vector<StringId> meminfo_strs_id_;
72   std::vector<StringId> vmstat_strs_id_;
73 
74   // Maps a proto field number for memcounters in ProcessStats::Process to
75   // their StringId. Keep kProcStatsProcessSize equal to 1 + max proto field
76   // id of ProcessStats::Process. Also update the value in
77   // ChromeSystemProbesParser.
78   static constexpr size_t kProcStatsProcessSize = 24;
79   std::array<StringId, kProcStatsProcessSize> proc_stats_process_names_{};
80 
81   // Maps a SysStats::PsiSample::PsiResource type to its StringId.
82   std::array<StringId, protos::pbzero::SysStats_PsiSample_PsiResource_MAX + 1>
83       sys_stats_psi_resource_names_{};
84 
85   uint32_t page_size_ = 0;
86 
87   int64_t prev_read_amount = -1;
88   int64_t prev_write_amount = -1;
89   int64_t prev_discard_amount = -1;
90   int64_t prev_flush_count = -1;
91   int64_t prev_read_time = -1;
92   int64_t prev_write_time = -1;
93   int64_t prev_discard_time = -1;
94   int64_t prev_flush_time = -1;
95 };
96 
97 }  // namespace trace_processor
98 }  // namespace perfetto
99 
100 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_SYSTEM_PROBES_PARSER_H_
101