• 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 #include "src/trace_processor/importers/proto/system_probes_module.h"
18 #include "perfetto/base/build_config.h"
19 #include "src/trace_processor/importers/proto/system_probes_parser.h"
20 #include "src/trace_processor/timestamped_trace_piece.h"
21 
22 #include "protos/perfetto/trace/trace_packet.pbzero.h"
23 
24 namespace perfetto {
25 namespace trace_processor {
26 
27 using perfetto::protos::pbzero::TracePacket;
28 
SystemProbesModule(TraceProcessorContext * context)29 SystemProbesModule::SystemProbesModule(TraceProcessorContext* context)
30     : parser_(context) {
31   RegisterForField(TracePacket::kProcessTreeFieldNumber, context);
32   RegisterForField(TracePacket::kProcessStatsFieldNumber, context);
33   RegisterForField(TracePacket::kSysStatsFieldNumber, context);
34   RegisterForField(TracePacket::kSystemInfoFieldNumber, context);
35   RegisterForField(TracePacket::kCpuInfoFieldNumber, context);
36 }
37 
TokenizePacket(const protos::pbzero::TracePacket::Decoder & decoder,TraceBlobView *,int64_t,PacketSequenceState *,uint32_t field_id)38 ModuleResult SystemProbesModule::TokenizePacket(
39     const protos::pbzero::TracePacket::Decoder& decoder,
40     TraceBlobView*,
41     int64_t,
42     PacketSequenceState*,
43     uint32_t field_id) {
44   switch (field_id) {
45     case TracePacket::kSystemInfoFieldNumber:
46       parser_.ParseSystemInfo(decoder.system_info());
47       return ModuleResult::Handled();
48     case TracePacket::kCpuInfoFieldNumber:
49       parser_.ParseCpuInfo(decoder.cpu_info());
50       return ModuleResult::Handled();
51   }
52   return ModuleResult::Ignored();
53 }
54 
ParsePacket(const TracePacket::Decoder & decoder,const TimestampedTracePiece & ttp,uint32_t field_id)55 void SystemProbesModule::ParsePacket(const TracePacket::Decoder& decoder,
56                                      const TimestampedTracePiece& ttp,
57                                      uint32_t field_id) {
58   switch (field_id) {
59     case TracePacket::kProcessTreeFieldNumber:
60       parser_.ParseProcessTree(decoder.process_tree());
61       return;
62     case TracePacket::kProcessStatsFieldNumber:
63       parser_.ParseProcessStats(ttp.timestamp, decoder.process_stats());
64       return;
65     case TracePacket::kSysStatsFieldNumber:
66       parser_.ParseSysStats(ttp.timestamp, decoder.sys_stats());
67       return;
68   }
69 }
70 
71 }  // namespace trace_processor
72 }  // namespace perfetto
73