trace_processor: Migrate android_probes_module to the new base class
Bug: 141459049
Change-Id: I4b7109d23892579bde8b9c0d9d325b33f9e2441e
diff --git a/Android.bp b/Android.bp
index 437aed1..0cfcb0d 100644
--- a/Android.bp
+++ b/Android.bp
@@ -4790,6 +4790,7 @@
"src/trace_processor/importers/fuchsia/fuchsia_trace_parser.cc",
"src/trace_processor/importers/fuchsia/fuchsia_trace_tokenizer.cc",
"src/trace_processor/importers/fuchsia/fuchsia_trace_utils.cc",
+ "src/trace_processor/importers/proto/android_probes_module.cc",
"src/trace_processor/importers/proto/android_probes_parser.cc",
"src/trace_processor/importers/proto/args_table_utils.cc",
"src/trace_processor/importers/proto/graphics_event_module.cc",
diff --git a/BUILD b/BUILD
index 7593b58..2b7853b 100644
--- a/BUILD
+++ b/BUILD
@@ -815,6 +815,7 @@
"src/trace_processor/importers/json/json_trace_tokenizer.h",
"src/trace_processor/importers/json/json_trace_utils.cc",
"src/trace_processor/importers/json/json_trace_utils.h",
+ "src/trace_processor/importers/proto/android_probes_module.cc",
"src/trace_processor/importers/proto/android_probes_module.h",
"src/trace_processor/importers/proto/android_probes_parser.cc",
"src/trace_processor/importers/proto/android_probes_parser.h",
diff --git a/src/trace_processor/BUILD.gn b/src/trace_processor/BUILD.gn
index a5a74d6..b5fd0c3 100644
--- a/src/trace_processor/BUILD.gn
+++ b/src/trace_processor/BUILD.gn
@@ -197,7 +197,10 @@
deps += [ "../../include/perfetto/ext/traced:sys_stats_counters" ]
}
if (enable_perfetto_trace_processor_android_probes) {
- sources += [ "importers/proto/android_probes_parser.cc" ]
+ sources += [
+ "importers/proto/android_probes_module.cc",
+ "importers/proto/android_probes_parser.cc",
+ ]
}
if (enable_perfetto_trace_processor_heap_graphs) {
sources += [
diff --git a/src/trace_processor/importers/proto/android_probes_module.cc b/src/trace_processor/importers/proto/android_probes_module.cc
new file mode 100644
index 0000000..5f6c034
--- /dev/null
+++ b/src/trace_processor/importers/proto/android_probes_module.cc
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "src/trace_processor/importers/proto/android_probes_module.h"
+#include "perfetto/base/build_config.h"
+#include "src/trace_processor/importers/proto/android_probes_parser.h"
+#include "src/trace_processor/timestamped_trace_piece.h"
+
+#include "protos/perfetto/config/trace_config.pbzero.h"
+#include "protos/perfetto/trace/trace_packet.pbzero.h"
+
+namespace perfetto {
+namespace trace_processor {
+
+using perfetto::protos::pbzero::TracePacket;
+
+AndroidProbesModule::AndroidProbesModule(TraceProcessorContext* context)
+ : parser_(context) {
+ RegisterForField(TracePacket::kBatteryFieldNumber, context);
+ RegisterForField(TracePacket::kPowerRailsFieldNumber, context);
+ RegisterForField(TracePacket::kAndroidLogFieldNumber, context);
+ RegisterForField(TracePacket::kPackagesListFieldNumber, context);
+}
+
+void AndroidProbesModule::ParsePacket(const TracePacket::Decoder& decoder,
+ const TimestampedTracePiece& ttp,
+ uint32_t field_id) {
+ switch (field_id) {
+ case TracePacket::kBatteryFieldNumber:
+ parser_.ParseBatteryCounters(ttp.timestamp, decoder.battery());
+ return;
+ case TracePacket::kPowerRailsFieldNumber:
+ parser_.ParsePowerRails(ttp.timestamp, decoder.power_rails());
+ return;
+ case TracePacket::kAndroidLogFieldNumber:
+ parser_.ParseAndroidLogPacket(decoder.android_log());
+ return;
+ case TracePacket::kPackagesListFieldNumber:
+ parser_.ParseAndroidPackagesList(decoder.packages_list());
+ return;
+ }
+}
+
+void AndroidProbesModule::ParseTraceConfig(
+ const protos::pbzero::TraceConfig::Decoder& decoder) {
+ if (decoder.has_statsd_metadata()) {
+ parser_.ParseStatsdMetadata(decoder.statsd_metadata());
+ }
+}
+
+} // namespace trace_processor
+} // namespace perfetto
diff --git a/src/trace_processor/importers/proto/android_probes_module.h b/src/trace_processor/importers/proto/android_probes_module.h
index 94d90a5..4a8c8d8 100644
--- a/src/trace_processor/importers/proto/android_probes_module.h
+++ b/src/trace_processor/importers/proto/android_probes_module.h
@@ -28,45 +28,16 @@
namespace perfetto {
namespace trace_processor {
-class AndroidProbesModule : public ProtoImporterModuleBase<PERFETTO_BUILDFLAG(
- PERFETTO_TP_ANDROID_PROBES)> {
+class AndroidProbesModule : public NewProtoImporterModule {
public:
- explicit AndroidProbesModule(TraceProcessorContext* context)
- : ProtoImporterModuleBase(context), parser_(context) {}
+ explicit AndroidProbesModule(TraceProcessorContext* context);
- ModuleResult ParsePacket(const protos::pbzero::TracePacket::Decoder& decoder,
- const TimestampedTracePiece& ttp) {
- if (decoder.has_battery()) {
- parser_.ParseBatteryCounters(ttp.timestamp, decoder.battery());
- return ModuleResult::Handled();
- }
+ void ParsePacket(const protos::pbzero::TracePacket::Decoder& decoder,
+ const TimestampedTracePiece& ttp,
+ uint32_t field_id) override;
- if (decoder.has_power_rails()) {
- parser_.ParsePowerRails(ttp.timestamp, decoder.power_rails());
- return ModuleResult::Handled();
- }
-
- if (decoder.has_android_log()) {
- parser_.ParseAndroidLogPacket(decoder.android_log());
- return ModuleResult::Handled();
- }
-
- if (decoder.has_packages_list()) {
- parser_.ParseAndroidPackagesList(decoder.packages_list());
- return ModuleResult::Handled();
- }
-
- return ModuleResult::Ignored();
- }
-
- ModuleResult ParseTraceConfig(
- const protos::pbzero::TraceConfig::Decoder& decoder) {
- if (decoder.has_statsd_metadata()) {
- parser_.ParseStatsdMetadata(decoder.statsd_metadata());
- return ModuleResult::Handled();
- }
- return ModuleResult::Ignored();
- }
+ void ParseTraceConfig(
+ const protos::pbzero::TraceConfig::Decoder& decoder) override;
private:
AndroidProbesParser parser_;
diff --git a/src/trace_processor/importers/proto/proto_trace_parser.cc b/src/trace_processor/importers/proto/proto_trace_parser.cc
index 634d857..2533e1c 100644
--- a/src/trace_processor/importers/proto/proto_trace_parser.cc
+++ b/src/trace_processor/importers/proto/proto_trace_parser.cc
@@ -33,7 +33,6 @@
#include "src/trace_processor/event_tracker.h"
#include "src/trace_processor/heap_profile_tracker.h"
#include "src/trace_processor/importers/ftrace/ftrace_module.h"
-#include "src/trace_processor/importers/proto/android_probes_module.h"
#include "src/trace_processor/importers/proto/heap_graph_module.h"
#include "src/trace_processor/importers/proto/packet_sequence_state.h"
#include "src/trace_processor/metadata.h"
@@ -204,9 +203,6 @@
if (!context_->ftrace_module->ParsePacket(packet, ttp).ignored())
return;
- if (!context_->android_probes_module->ParsePacket(packet, ttp).ignored())
- return;
-
if (!context_->heap_graph_module->ParsePacket(packet, ttp).ignored())
return;
@@ -597,8 +593,6 @@
protos::pbzero::TraceConfig::Decoder trace_config(blob.data, blob.size);
// TODO(eseckler): Propagate statuses from modules.
- context_->android_probes_module->ParseTraceConfig(trace_config);
-
for (auto& module : context_->modules) {
module->ParseTraceConfig(trace_config);
}
diff --git a/src/trace_processor/importers/proto/proto_trace_parser_unittest.cc b/src/trace_processor/importers/proto/proto_trace_parser_unittest.cc
index eaa9b60..f321f5f 100644
--- a/src/trace_processor/importers/proto/proto_trace_parser_unittest.cc
+++ b/src/trace_processor/importers/proto/proto_trace_parser_unittest.cc
@@ -263,11 +263,10 @@
#endif // PERFETTO_BUILDFLAG(PERFETTO_TP_GRAPHICS)
context_.ftrace_module.reset(
new ProtoImporterModule<FtraceModule>(&context_));
- context_.android_probes_module.reset(
- new ProtoImporterModule<AndroidProbesModule>(&context_));
context_.heap_graph_module.reset(
new ProtoImporterModule<HeapGraphModule>(&context_));
+ context_.modules.emplace_back(new AndroidProbesModule(&context_));
context_.modules.emplace_back(new SystemProbesModule(&context_));
context_.modules.emplace_back(new TrackEventModule(&context_));
#if PERFETTO_BUILDFLAG(PERFETTO_TP_GRAPHICS)
diff --git a/src/trace_processor/trace_processor_context.h b/src/trace_processor/trace_processor_context.h
index 7aa4bd4..a6e99a4 100644
--- a/src/trace_processor/trace_processor_context.h
+++ b/src/trace_processor/trace_processor_context.h
@@ -26,7 +26,6 @@
namespace perfetto {
namespace trace_processor {
-class AndroidProbesModule;
class ArgsTracker;
class BinderTracker;
class ChunkedTraceReader;
@@ -73,8 +72,6 @@
std::unique_ptr<BinderTracker> binder_tracker;
std::unique_ptr<ProtoImporterModule<FtraceModule>> ftrace_module;
- std::unique_ptr<ProtoImporterModule<AndroidProbesModule>>
- android_probes_module;
std::unique_ptr<ProtoImporterModule<HeapGraphModule>> heap_graph_module;
// The module at the index N is registered to handle field id N in
diff --git a/src/trace_processor/trace_processor_storage_impl.cc b/src/trace_processor/trace_processor_storage_impl.cc
index 57e3805..f3529fe 100644
--- a/src/trace_processor/trace_processor_storage_impl.cc
+++ b/src/trace_processor/trace_processor_storage_impl.cc
@@ -70,11 +70,12 @@
#endif // PERFETTO_BUILDFLAG(PERFETTO_TP_GRAPHICS)
context_.ftrace_module.reset(
new ProtoImporterModule<FtraceModule>(&context_));
- context_.android_probes_module.reset(
- new ProtoImporterModule<AndroidProbesModule>(&context_));
context_.heap_graph_module.reset(
new ProtoImporterModule<HeapGraphModule>(&context_));
+#if PERFETTO_BUILDFLAG(PERFETTO_TP_ANDROID_PROBES)
+ context_.modules.emplace_back(new AndroidProbesModule(&context_));
+#endif // PERFETTO_BUILDFLAG(PERFETTO_TP_ANDROID_PROBES)
#if PERFETTO_BUILDFLAG(PERFETTO_TP_SYSTEM_PROBES)
context_.modules.emplace_back(new SystemProbesModule(&context_));
#endif // PERFETTO_BUILDFLAG(PERFETTO_TP_SYSTEM_PROBES)