blob: b58b8bc310b56240b12633dd0b56d1e20c2fbf7b [file] [log] [blame]
Eric Secklerde589952019-10-17 12:46:07 +01001/*
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_TRACK_EVENT_MODULE_H_
18#define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_TRACK_EVENT_MODULE_H_
19
20#include "perfetto/base/build_config.h"
21#include "src/trace_processor/importers/proto/proto_importer_module.h"
Eric Seckler771960c2019-10-22 15:37:12 +010022#include "src/trace_processor/importers/proto/track_event_parser.h"
23#include "src/trace_processor/importers/proto/track_event_tokenizer.h"
24#include "src/trace_processor/timestamped_trace_piece.h"
Eric Secklerde589952019-10-17 12:46:07 +010025
Eric Secklerd2af9892019-11-01 10:10:53 +000026#include "protos/perfetto/config/trace_config.pbzero.h"
27#include "protos/perfetto/trace/trace_packet.pbzero.h"
28
Eric Secklerde589952019-10-17 12:46:07 +010029namespace perfetto {
30namespace trace_processor {
31
32class TrackEventModule : public ProtoImporterModuleBase</*IsEnabled=*/1> {
33 public:
34 explicit TrackEventModule(TraceProcessorContext* context)
Eric Seckler771960c2019-10-22 15:37:12 +010035 : ProtoImporterModuleBase(context),
36 tokenizer_(context),
37 parser_(context) {}
Eric Secklerde589952019-10-17 12:46:07 +010038
Eric Seckler771960c2019-10-22 15:37:12 +010039 ModuleResult TokenizePacket(
40 const protos::pbzero::TracePacket::Decoder& decoder,
41 TraceBlobView* packet,
42 int64_t packet_timestamp,
43 PacketSequenceState* state) {
44 if (decoder.has_track_descriptor()) {
45 tokenizer_.TokenizeTrackDescriptorPacket(decoder);
46 return ModuleResult::Handled();
47 }
48
49 if (decoder.has_track_event()) {
50 tokenizer_.TokenizeTrackEventPacket(state, decoder, packet,
51 packet_timestamp);
52 return ModuleResult::Handled();
53 }
54
55 // TODO(eseckler): Remove these once Chrome has switched fully over to
56 // TrackDescriptors.
57 if (decoder.has_thread_descriptor()) {
58 tokenizer_.TokenizeThreadDescriptorPacket(state, decoder);
59 return ModuleResult::Handled();
60 }
61 if (decoder.has_process_descriptor()) {
62 tokenizer_.TokenizeProcessDescriptorPacket(decoder);
63 return ModuleResult::Handled();
64 }
65
Eric Secklerde589952019-10-17 12:46:07 +010066 return ModuleResult::Ignored();
67 }
68
Eric Seckler771960c2019-10-22 15:37:12 +010069 ModuleResult ParsePacket(const protos::pbzero::TracePacket::Decoder& decoder,
70 const TimestampedTracePiece& ttp) {
Eric Seckler771960c2019-10-22 15:37:12 +010071 if (decoder.has_track_event()) {
72 parser_.ParseTrackEvent(
73 ttp.timestamp, ttp.thread_timestamp, ttp.thread_instruction_count,
74 ttp.packet_sequence_state, ttp.packet_sequence_state_generation,
75 decoder.track_event());
76 return ModuleResult::Handled();
77 }
Eric Secklerde589952019-10-17 12:46:07 +010078 return ModuleResult::Ignored();
79 }
Eric Seckler771960c2019-10-22 15:37:12 +010080
81 private:
82 TrackEventTokenizer tokenizer_;
83 TrackEventParser parser_;
Eric Secklerde589952019-10-17 12:46:07 +010084};
85
86} // namespace trace_processor
87} // namespace perfetto
88
89#endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_TRACK_EVENT_MODULE_H_