tp: split metadata_module into two and move trace_config parsing to full

Bug: crbug/1373719
Change-Id: I8ea258800dd6cf4b719b0566fc92306cdeacc017
diff --git a/Android.bp b/Android.bp
index 771b599..14c0e12 100644
--- a/Android.bp
+++ b/Android.bp
@@ -9326,8 +9326,6 @@
         "src/trace_processor/importers/proto/chrome_system_probes_parser.cc",
         "src/trace_processor/importers/proto/memory_tracker_snapshot_module.cc",
         "src/trace_processor/importers/proto/memory_tracker_snapshot_parser.cc",
-        "src/trace_processor/importers/proto/metadata_module.cc",
-        "src/trace_processor/importers/proto/metadata_tracker.cc",
         "src/trace_processor/importers/proto/perf_sample_tracker.cc",
         "src/trace_processor/importers/proto/profile_module.cc",
         "src/trace_processor/importers/proto/profile_packet_utils.cc",
@@ -9354,6 +9352,7 @@
     name: "perfetto_src_trace_processor_importers_proto_full",
     srcs: [
         "src/trace_processor/importers/proto/heap_graph_tracker.cc",
+        "src/trace_processor/importers/proto/metadata_module.cc",
         "src/trace_processor/importers/proto/statsd_module.cc",
     ],
 }
@@ -9381,6 +9380,8 @@
         "src/trace_processor/importers/proto/async_track_set_tracker.cc",
         "src/trace_processor/importers/proto/chrome_string_lookup.cc",
         "src/trace_processor/importers/proto/heap_profile_tracker.cc",
+        "src/trace_processor/importers/proto/metadata_minimal_module.cc",
+        "src/trace_processor/importers/proto/metadata_tracker.cc",
         "src/trace_processor/importers/proto/packet_sequence_state_generation.cc",
         "src/trace_processor/importers/proto/profiler_util.cc",
         "src/trace_processor/importers/proto/proto_importer_module.cc",
diff --git a/BUILD b/BUILD
index b44ab50..ad4a35b 100644
--- a/BUILD
+++ b/BUILD
@@ -1175,6 +1175,8 @@
     srcs = [
         "src/trace_processor/importers/proto/heap_graph_tracker.cc",
         "src/trace_processor/importers/proto/heap_graph_tracker.h",
+        "src/trace_processor/importers/proto/metadata_module.cc",
+        "src/trace_processor/importers/proto/metadata_module.h",
         "src/trace_processor/importers/proto/statsd_module.cc",
         "src/trace_processor/importers/proto/statsd_module.h",
     ],
@@ -1203,6 +1205,10 @@
         "src/trace_processor/importers/proto/chrome_string_lookup.h",
         "src/trace_processor/importers/proto/heap_profile_tracker.cc",
         "src/trace_processor/importers/proto/heap_profile_tracker.h",
+        "src/trace_processor/importers/proto/metadata_minimal_module.cc",
+        "src/trace_processor/importers/proto/metadata_minimal_module.h",
+        "src/trace_processor/importers/proto/metadata_tracker.cc",
+        "src/trace_processor/importers/proto/metadata_tracker.h",
         "src/trace_processor/importers/proto/packet_sequence_state.h",
         "src/trace_processor/importers/proto/packet_sequence_state_generation.cc",
         "src/trace_processor/importers/proto/profiler_util.cc",
@@ -1384,10 +1390,6 @@
         "src/trace_processor/importers/proto/memory_tracker_snapshot_module.h",
         "src/trace_processor/importers/proto/memory_tracker_snapshot_parser.cc",
         "src/trace_processor/importers/proto/memory_tracker_snapshot_parser.h",
-        "src/trace_processor/importers/proto/metadata_module.cc",
-        "src/trace_processor/importers/proto/metadata_module.h",
-        "src/trace_processor/importers/proto/metadata_tracker.cc",
-        "src/trace_processor/importers/proto/metadata_tracker.h",
         "src/trace_processor/importers/proto/perf_sample_tracker.cc",
         "src/trace_processor/importers/proto/perf_sample_tracker.h",
         "src/trace_processor/importers/proto/profile_module.cc",
diff --git a/src/trace_processor/BUILD.gn b/src/trace_processor/BUILD.gn
index c605029..c15fa79 100644
--- a/src/trace_processor/BUILD.gn
+++ b/src/trace_processor/BUILD.gn
@@ -173,6 +173,7 @@
       "importers/android_bugreport",
       "importers/common",
       "importers/ninja",
+      "importers/proto:minimal",
       "metrics",
       "sqlite",
       "sqlite/functions",
@@ -256,6 +257,7 @@
       "containers",
       "importers:minimal",
       "importers/common",
+      "importers/proto:minimal",
       "storage",
       "types",
     ]
diff --git a/src/trace_processor/importers/BUILD.gn b/src/trace_processor/importers/BUILD.gn
index 1374bf1..db6fa4e 100644
--- a/src/trace_processor/importers/BUILD.gn
+++ b/src/trace_processor/importers/BUILD.gn
@@ -32,10 +32,6 @@
     "proto/memory_tracker_snapshot_module.h",
     "proto/memory_tracker_snapshot_parser.cc",
     "proto/memory_tracker_snapshot_parser.h",
-    "proto/metadata_module.cc",
-    "proto/metadata_module.h",
-    "proto/metadata_tracker.cc",
-    "proto/metadata_tracker.h",
     "proto/perf_sample_tracker.cc",
     "proto/perf_sample_tracker.h",
     "proto/profile_module.cc",
diff --git a/src/trace_processor/importers/additional_modules.cc b/src/trace_processor/importers/additional_modules.cc
index 825cf21..55191b4 100644
--- a/src/trace_processor/importers/additional_modules.cc
+++ b/src/trace_processor/importers/additional_modules.cc
@@ -21,6 +21,7 @@
 #include "src/trace_processor/importers/proto/content_analyzer.h"
 #include "src/trace_processor/importers/proto/graphics_event_module.h"
 #include "src/trace_processor/importers/proto/heap_graph_module.h"
+#include "src/trace_processor/importers/proto/metadata_module.h"
 #include "src/trace_processor/importers/proto/statsd_module.h"
 #include "src/trace_processor/importers/proto/system_probes_module.h"
 #include "src/trace_processor/importers/proto/translation_table_module.h"
@@ -36,6 +37,7 @@
   context->modules.emplace_back(new TranslationTableModule(context));
   context->modules.emplace_back(new StatsdModule(context));
   context->modules.emplace_back(new AndroidCameraEventModule(context));
+  context->modules.emplace_back(new MetadataModule(context));
 
   if (context->config.analyze_trace_proto_content) {
     context->modules.emplace_back(new ContentAnalyzerModule(context));
diff --git a/src/trace_processor/importers/default_modules.cc b/src/trace_processor/importers/default_modules.cc
index 5fbc40c..4779949 100644
--- a/src/trace_processor/importers/default_modules.cc
+++ b/src/trace_processor/importers/default_modules.cc
@@ -18,7 +18,7 @@
 #include "src/trace_processor/importers/ftrace/ftrace_module.h"
 #include "src/trace_processor/importers/proto/chrome_system_probes_module.h"
 #include "src/trace_processor/importers/proto/memory_tracker_snapshot_module.h"
-#include "src/trace_processor/importers/proto/metadata_module.h"
+#include "src/trace_processor/importers/proto/metadata_minimal_module.h"
 #include "src/trace_processor/importers/proto/profile_module.h"
 #include "src/trace_processor/importers/proto/proto_importer_module.h"
 #include "src/trace_processor/importers/proto/track_event_module.h"
@@ -39,7 +39,7 @@
   context->modules.emplace_back(new MemoryTrackerSnapshotModule(context));
   context->modules.emplace_back(new ChromeSystemProbesModule(context));
   context->modules.emplace_back(new ProfileModule(context));
-  context->modules.emplace_back(new MetadataModule(context));
+  context->modules.emplace_back(new MetadataMinimalModule(context));
 }
 
 }  // namespace trace_processor
diff --git a/src/trace_processor/importers/proto/BUILD.gn b/src/trace_processor/importers/proto/BUILD.gn
index 83769f9..008ccbb 100644
--- a/src/trace_processor/importers/proto/BUILD.gn
+++ b/src/trace_processor/importers/proto/BUILD.gn
@@ -24,6 +24,10 @@
     "chrome_string_lookup.h",
     "heap_profile_tracker.cc",
     "heap_profile_tracker.h",
+    "metadata_minimal_module.cc",
+    "metadata_minimal_module.h",
+    "metadata_tracker.cc",
+    "metadata_tracker.h",
     "packet_sequence_state.h",
     "packet_sequence_state_generation.cc",
     "profiler_util.cc",
@@ -36,6 +40,7 @@
   deps = [
     ":packet_sequence_state_generation_hdr",
     "../../../../gn:default_deps",
+    "../../../../protos/perfetto/trace:zero",
     "../../../../protos/perfetto/trace/chrome:zero",
     "../../../../protos/perfetto/trace/profiling:zero",
     "../../../../protos/perfetto/trace/track_event:zero",
@@ -52,6 +57,8 @@
   sources = [
     "heap_graph_tracker.cc",
     "heap_graph_tracker.h",
+    "metadata_module.cc",
+    "metadata_module.h",
     "statsd_module.cc",
     "statsd_module.h",
   ]
@@ -59,6 +66,7 @@
     ":gen_cc_statsd_atoms_descriptor",
     ":minimal",
     "../../../../gn:default_deps",
+    "../../../../protos/perfetto/config:zero",
     "../../../../protos/perfetto/trace:zero",
     "../../../../protos/perfetto/trace/profiling:zero",
     "../../../../protos/perfetto/trace/statsd:zero",
diff --git a/src/trace_processor/importers/proto/metadata_minimal_module.cc b/src/trace_processor/importers/proto/metadata_minimal_module.cc
new file mode 100644
index 0000000..08ee096
--- /dev/null
+++ b/src/trace_processor/importers/proto/metadata_minimal_module.cc
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2021 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/metadata_minimal_module.h"
+
+#include "perfetto/ext/base/base64.h"
+#include "src/trace_processor/importers/proto/metadata_tracker.h"
+#include "src/trace_processor/types/trace_processor_context.h"
+
+#include "protos/perfetto/trace/chrome/chrome_benchmark_metadata.pbzero.h"
+#include "protos/perfetto/trace/chrome/chrome_metadata.pbzero.h"
+
+namespace perfetto {
+namespace trace_processor {
+
+using perfetto::protos::pbzero::TracePacket;
+
+MetadataMinimalModule::MetadataMinimalModule(TraceProcessorContext* context)
+    : context_(context) {
+  RegisterForField(TracePacket::kChromeMetadataFieldNumber, context);
+  RegisterForField(TracePacket::kChromeBenchmarkMetadataFieldNumber, context);
+}
+
+ModuleResult MetadataMinimalModule::TokenizePacket(
+    const protos::pbzero::TracePacket::Decoder& decoder,
+    TraceBlobView*,
+    int64_t,
+    PacketSequenceState*,
+    uint32_t field_id) {
+  switch (field_id) {
+    case TracePacket::kChromeMetadataFieldNumber: {
+      ParseChromeMetadataPacket(decoder.chrome_metadata());
+      return ModuleResult::Handled();
+    }
+    case TracePacket::kChromeBenchmarkMetadataFieldNumber: {
+      ParseChromeBenchmarkMetadata(decoder.chrome_benchmark_metadata());
+      return ModuleResult::Handled();
+    }
+  }
+  return ModuleResult::Ignored();
+}
+
+void MetadataMinimalModule::ParseChromeBenchmarkMetadata(ConstBytes blob) {
+  TraceStorage* storage = context_->storage.get();
+  MetadataTracker* metadata = context_->metadata_tracker.get();
+
+  protos::pbzero::ChromeBenchmarkMetadata::Decoder packet(blob.data, blob.size);
+  if (packet.has_benchmark_name()) {
+    auto benchmark_name_id = storage->InternString(packet.benchmark_name());
+    metadata->SetMetadata(metadata::benchmark_name,
+                          Variadic::String(benchmark_name_id));
+  }
+  if (packet.has_benchmark_description()) {
+    auto benchmark_description_id =
+        storage->InternString(packet.benchmark_description());
+    metadata->SetMetadata(metadata::benchmark_description,
+                          Variadic::String(benchmark_description_id));
+  }
+  if (packet.has_label()) {
+    auto label_id = storage->InternString(packet.label());
+    metadata->SetMetadata(metadata::benchmark_label,
+                          Variadic::String(label_id));
+  }
+  if (packet.has_story_name()) {
+    auto story_name_id = storage->InternString(packet.story_name());
+    metadata->SetMetadata(metadata::benchmark_story_name,
+                          Variadic::String(story_name_id));
+  }
+  for (auto it = packet.story_tags(); it; ++it) {
+    auto story_tag_id = storage->InternString(*it);
+    metadata->AppendMetadata(metadata::benchmark_story_tags,
+                             Variadic::String(story_tag_id));
+  }
+  if (packet.has_benchmark_start_time_us()) {
+    metadata->SetMetadata(metadata::benchmark_start_time_us,
+                          Variadic::Integer(packet.benchmark_start_time_us()));
+  }
+  if (packet.has_story_run_time_us()) {
+    metadata->SetMetadata(metadata::benchmark_story_run_time_us,
+                          Variadic::Integer(packet.story_run_time_us()));
+  }
+  if (packet.has_story_run_index()) {
+    metadata->SetMetadata(metadata::benchmark_story_run_index,
+                          Variadic::Integer(packet.story_run_index()));
+  }
+  if (packet.has_had_failures()) {
+    metadata->SetMetadata(metadata::benchmark_had_failures,
+                          Variadic::Integer(packet.had_failures()));
+  }
+}
+
+void MetadataMinimalModule::ParseChromeMetadataPacket(ConstBytes blob) {
+  TraceStorage* storage = context_->storage.get();
+  MetadataTracker* metadata = context_->metadata_tracker.get();
+
+  // Typed chrome metadata proto. The untyped metadata is parsed below in
+  // ParseChromeEvents().
+  protos::pbzero::ChromeMetadataPacket::Decoder packet(blob.data, blob.size);
+
+  if (packet.has_background_tracing_metadata()) {
+    auto background_tracing_metadata = packet.background_tracing_metadata();
+    std::string base64 = base::Base64Encode(background_tracing_metadata.data,
+                                            background_tracing_metadata.size);
+    metadata->SetDynamicMetadata(
+        storage->InternString("cr-background_tracing_metadata"),
+        Variadic::String(storage->InternString(base::StringView(base64))));
+  }
+
+  if (packet.has_chrome_version_code()) {
+    metadata->SetDynamicMetadata(
+        storage->InternString("cr-playstore_version_code"),
+        Variadic::Integer(packet.chrome_version_code()));
+  }
+  if (packet.has_enabled_categories()) {
+    auto categories_id = storage->InternString(packet.enabled_categories());
+    metadata->SetDynamicMetadata(storage->InternString("cr-enabled_categories"),
+                                 Variadic::String(categories_id));
+  }
+}
+
+}  // namespace trace_processor
+}  // namespace perfetto
diff --git a/src/trace_processor/importers/proto/metadata_minimal_module.h b/src/trace_processor/importers/proto/metadata_minimal_module.h
new file mode 100644
index 0000000..b12eed9
--- /dev/null
+++ b/src/trace_processor/importers/proto/metadata_minimal_module.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#ifndef SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_METADATA_MINIMAL_MODULE_H_
+#define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_METADATA_MINIMAL_MODULE_H_
+
+#include "src/trace_processor/importers/common/trace_parser.h"
+#include "src/trace_processor/importers/proto/proto_importer_module.h"
+
+#include "src/trace_processor/storage/trace_storage.h"
+
+#include "protos/perfetto/trace/trace_packet.pbzero.h"
+
+namespace perfetto {
+namespace trace_processor {
+
+class MetadataMinimalModule : public ProtoImporterModule {
+ public:
+  using ConstBytes = protozero::ConstBytes;
+  explicit MetadataMinimalModule(TraceProcessorContext* context);
+
+  ModuleResult TokenizePacket(
+      const protos::pbzero::TracePacket::Decoder& decoder,
+      TraceBlobView* packet,
+      int64_t packet_timestamp,
+      PacketSequenceState* state,
+      uint32_t field_id) override;
+
+ private:
+  void ParseChromeBenchmarkMetadata(ConstBytes);
+  void ParseChromeMetadataPacket(ConstBytes);
+
+  TraceProcessorContext* context_;
+};
+
+}  // namespace trace_processor
+}  // namespace perfetto
+
+#endif  // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_METADATA_MINIMAL_MODULE_H_
diff --git a/src/trace_processor/importers/proto/metadata_module.cc b/src/trace_processor/importers/proto/metadata_module.cc
index 6468757..b22663b 100644
--- a/src/trace_processor/importers/proto/metadata_module.cc
+++ b/src/trace_processor/importers/proto/metadata_module.cc
@@ -17,15 +17,18 @@
 #include "src/trace_processor/importers/proto/metadata_module.h"
 
 #include "perfetto/ext/base/base64.h"
-#include "protos/perfetto/trace/trace_packet.pbzero.h"
+#include "perfetto/ext/base/uuid.h"
 #include "src/trace_processor/importers/common/slice_tracker.h"
 #include "src/trace_processor/importers/common/track_tracker.h"
+#include "src/trace_processor/importers/config.descriptor.h"
 #include "src/trace_processor/importers/proto/metadata_tracker.h"
+#include "src/trace_processor/util/descriptors.h"
+#include "src/trace_processor/util/protozero_to_text.h"
 
-#include "protos/perfetto/trace/chrome/chrome_benchmark_metadata.pbzero.h"
-#include "protos/perfetto/trace/chrome/chrome_metadata.pbzero.h"
+#include "protos/perfetto/config/trace_config.pbzero.h"
+#include "protos/perfetto/trace/trace_packet.pbzero.h"
+#include "protos/perfetto/trace/trace_uuid.pbzero.h"
 #include "protos/perfetto/trace/trigger.pbzero.h"
-#include "src/trace_processor/importers/common/parser_types.h"
 
 namespace perfetto {
 namespace trace_processor {
@@ -38,9 +41,8 @@
       trusted_producer_uid_key_id_(
           context_->storage->InternString("trusted_producer_uid")) {
   RegisterForField(TracePacket::kUiStateFieldNumber, context);
-  RegisterForField(TracePacket::kChromeMetadataFieldNumber, context);
-  RegisterForField(TracePacket::kChromeBenchmarkMetadataFieldNumber, context);
   RegisterForField(TracePacket::kTriggerFieldNumber, context);
+  RegisterForField(TracePacket::kTraceUuidFieldNumber, context);
 }
 
 ModuleResult MetadataModule::TokenizePacket(
@@ -58,12 +60,22 @@
                                               Variadic::String(id));
       return ModuleResult::Handled();
     }
-    case TracePacket::kChromeMetadataFieldNumber: {
-      ParseChromeMetadataPacket(decoder.chrome_metadata());
-      return ModuleResult::Handled();
-    }
-    case TracePacket::kChromeBenchmarkMetadataFieldNumber: {
-      ParseChromeBenchmarkMetadata(decoder.chrome_benchmark_metadata());
+    case TracePacket::kTraceUuidFieldNumber: {
+      // If both the TraceUuid packet and TraceConfig.trace_uuid_msb/lsb are
+      // set, the former (which is emitted first) takes precedence. This is
+      // because the UUID can change throughout the lifecycle of a tracing
+      // session if gap-less snapshots are used. Each trace file has at most one
+      // TraceUuid packet (i has if it comes from an older version of the
+      // tracing service < v32)
+      protos::pbzero::TraceUuid::Decoder uuid_packet(decoder.trace_uuid());
+      if (uuid_packet.msb() != 0 || uuid_packet.lsb() != 0) {
+        base::Uuid uuid(uuid_packet.lsb(), uuid_packet.msb());
+        std::string str = uuid.ToPrettyString();
+        StringId id = context_->storage->InternString(base::StringView(str));
+        context_->metadata_tracker->SetMetadata(metadata::trace_uuid,
+                                                Variadic::String(id));
+        context_->uuid_found_in_trace = true;
+      }
       return ModuleResult::Handled();
     }
   }
@@ -82,84 +94,6 @@
   }
 }
 
-void MetadataModule::ParseChromeBenchmarkMetadata(ConstBytes blob) {
-  TraceStorage* storage = context_->storage.get();
-  MetadataTracker* metadata = context_->metadata_tracker.get();
-
-  protos::pbzero::ChromeBenchmarkMetadata::Decoder packet(blob.data, blob.size);
-  if (packet.has_benchmark_name()) {
-    auto benchmark_name_id = storage->InternString(packet.benchmark_name());
-    metadata->SetMetadata(metadata::benchmark_name,
-                          Variadic::String(benchmark_name_id));
-  }
-  if (packet.has_benchmark_description()) {
-    auto benchmark_description_id =
-        storage->InternString(packet.benchmark_description());
-    metadata->SetMetadata(metadata::benchmark_description,
-                          Variadic::String(benchmark_description_id));
-  }
-  if (packet.has_label()) {
-    auto label_id = storage->InternString(packet.label());
-    metadata->SetMetadata(metadata::benchmark_label,
-                          Variadic::String(label_id));
-  }
-  if (packet.has_story_name()) {
-    auto story_name_id = storage->InternString(packet.story_name());
-    metadata->SetMetadata(metadata::benchmark_story_name,
-                          Variadic::String(story_name_id));
-  }
-  for (auto it = packet.story_tags(); it; ++it) {
-    auto story_tag_id = storage->InternString(*it);
-    metadata->AppendMetadata(metadata::benchmark_story_tags,
-                             Variadic::String(story_tag_id));
-  }
-  if (packet.has_benchmark_start_time_us()) {
-    metadata->SetMetadata(metadata::benchmark_start_time_us,
-                          Variadic::Integer(packet.benchmark_start_time_us()));
-  }
-  if (packet.has_story_run_time_us()) {
-    metadata->SetMetadata(metadata::benchmark_story_run_time_us,
-                          Variadic::Integer(packet.story_run_time_us()));
-  }
-  if (packet.has_story_run_index()) {
-    metadata->SetMetadata(metadata::benchmark_story_run_index,
-                          Variadic::Integer(packet.story_run_index()));
-  }
-  if (packet.has_had_failures()) {
-    metadata->SetMetadata(metadata::benchmark_had_failures,
-                          Variadic::Integer(packet.had_failures()));
-  }
-}
-
-void MetadataModule::ParseChromeMetadataPacket(ConstBytes blob) {
-  TraceStorage* storage = context_->storage.get();
-  MetadataTracker* metadata = context_->metadata_tracker.get();
-
-  // Typed chrome metadata proto. The untyped metadata is parsed below in
-  // ParseChromeEvents().
-  protos::pbzero::ChromeMetadataPacket::Decoder packet(blob.data, blob.size);
-
-  if (packet.has_background_tracing_metadata()) {
-    auto background_tracing_metadata = packet.background_tracing_metadata();
-    std::string base64 = base::Base64Encode(background_tracing_metadata.data,
-                                            background_tracing_metadata.size);
-    metadata->SetDynamicMetadata(
-        storage->InternString("cr-background_tracing_metadata"),
-        Variadic::String(storage->InternString(base::StringView(base64))));
-  }
-
-  if (packet.has_chrome_version_code()) {
-    metadata->SetDynamicMetadata(
-        storage->InternString("cr-playstore_version_code"),
-        Variadic::Integer(packet.chrome_version_code()));
-  }
-  if (packet.has_enabled_categories()) {
-    auto categories_id = storage->InternString(packet.enabled_categories());
-    metadata->SetDynamicMetadata(storage->InternString("cr-enabled_categories"),
-                                 Variadic::String(categories_id));
-  }
-}
-
 void MetadataModule::ParseTrigger(int64_t ts, ConstBytes blob) {
   protos::pbzero::Trigger::Decoder trigger(blob.data, blob.size);
   StringId cat_id = kNullStringId;
@@ -182,5 +116,57 @@
       });
 }
 
+void MetadataModule::ParseTraceUuid(ConstBytes blob) {
+  // If both the TraceUuid packet and TraceConfig.trace_uuid_msb/lsb are set,
+  // the former (which is emitted first) takes precedence. This is because the
+  // UUID can change throughout the lifecycle of a tracing session if gap-less
+  // snapshots are used. Each trace file has at most one TraceUuid packet (i
+  // has if it comes from an older version of the tracing service < v32)
+  protos::pbzero::TraceUuid::Decoder uuid_packet(blob.data, blob.size);
+  if (uuid_packet.msb() != 0 || uuid_packet.lsb() != 0) {
+    base::Uuid uuid(uuid_packet.lsb(), uuid_packet.msb());
+    std::string str = uuid.ToPrettyString();
+    StringId id = context_->storage->InternString(base::StringView(str));
+    context_->metadata_tracker->SetMetadata(metadata::trace_uuid,
+                                            Variadic::String(id));
+    context_->uuid_found_in_trace = true;
+  }
+}
+
+void MetadataModule::ParseTraceConfig(
+    const protos::pbzero::TraceConfig_Decoder& trace_config) {
+  int64_t uuid_msb = trace_config.trace_uuid_msb();
+  int64_t uuid_lsb = trace_config.trace_uuid_lsb();
+  if (!context_->uuid_found_in_trace && (uuid_msb != 0 || uuid_lsb != 0)) {
+    base::Uuid uuid(uuid_lsb, uuid_msb);
+    std::string str = uuid.ToPrettyString();
+    StringId id = context_->storage->InternString(base::StringView(str));
+    context_->metadata_tracker->SetMetadata(metadata::trace_uuid,
+                                            Variadic::String(id));
+    context_->uuid_found_in_trace = true;
+  }
+
+  if (trace_config.has_unique_session_name()) {
+    StringId id = context_->storage->InternString(
+        base::StringView(trace_config.unique_session_name()));
+    context_->metadata_tracker->SetMetadata(metadata::unique_session_name,
+                                            Variadic::String(id));
+  }
+
+  DescriptorPool pool;
+  pool.AddFromFileDescriptorSet(kConfigDescriptor.data(),
+                                kConfigDescriptor.size());
+
+  std::string text = protozero_to_text::ProtozeroToText(
+      pool, ".perfetto.protos.TraceConfig",
+      protozero::ConstBytes{
+          trace_config.begin(),
+          static_cast<uint32_t>(trace_config.end() - trace_config.begin())},
+      protozero_to_text::kIncludeNewLines);
+  StringId id = context_->storage->InternString(base::StringView(text));
+  context_->metadata_tracker->SetMetadata(metadata::trace_config_pbtxt,
+                                          Variadic::String(id));
+}
+
 }  // namespace trace_processor
 }  // namespace perfetto
diff --git a/src/trace_processor/importers/proto/metadata_module.h b/src/trace_processor/importers/proto/metadata_module.h
index 6242db8..49e0384 100644
--- a/src/trace_processor/importers/proto/metadata_module.h
+++ b/src/trace_processor/importers/proto/metadata_module.h
@@ -43,10 +43,11 @@
                             const TracePacketData&,
                             uint32_t field_id) override;
 
+  void ParseTraceConfig(const protos::pbzero::TraceConfig_Decoder&) override;
+
  private:
-  void ParseChromeBenchmarkMetadata(ConstBytes);
-  void ParseChromeMetadataPacket(ConstBytes);
   void ParseTrigger(int64_t ts, ConstBytes);
+  void ParseTraceUuid(ConstBytes);
 
   TraceProcessorContext* context_;
   StringId producer_name_key_id_ = kNullStringId;
diff --git a/src/trace_processor/importers/proto/proto_trace_parser.cc b/src/trace_processor/importers/proto/proto_trace_parser.cc
index 0503cfa..600b886 100644
--- a/src/trace_processor/importers/proto/proto_trace_parser.cc
+++ b/src/trace_processor/importers/proto/proto_trace_parser.cc
@@ -34,7 +34,6 @@
 #include "src/trace_processor/importers/common/process_tracker.h"
 #include "src/trace_processor/importers/common/slice_tracker.h"
 #include "src/trace_processor/importers/common/track_tracker.h"
-#include "src/trace_processor/importers/config.descriptor.h"
 #include "src/trace_processor/importers/ftrace/ftrace_module.h"
 #include "src/trace_processor/importers/proto/metadata_tracker.h"
 #include "src/trace_processor/importers/proto/packet_sequence_state.h"
@@ -43,15 +42,12 @@
 #include "src/trace_processor/storage/stats.h"
 #include "src/trace_processor/types/trace_processor_context.h"
 #include "src/trace_processor/types/variadic.h"
-#include "src/trace_processor/util/descriptors.h"
-#include "src/trace_processor/util/protozero_to_text.h"
 
 #include "protos/perfetto/common/trace_stats.pbzero.h"
 #include "protos/perfetto/config/trace_config.pbzero.h"
 #include "protos/perfetto/trace/chrome/chrome_trace_event.pbzero.h"
 #include "protos/perfetto/trace/perfetto/perfetto_metatrace.pbzero.h"
 #include "protos/perfetto/trace/trace_packet.pbzero.h"
-#include "protos/perfetto/trace/trace_uuid.pbzero.h"
 
 namespace perfetto {
 namespace trace_processor {
@@ -99,12 +95,12 @@
     ParseMetatraceEvent(ts, packet.perfetto_metatrace());
   }
 
-  if (packet.has_trace_uuid()) {
-    ParseTraceUuid(packet.trace_uuid());
-  }
-
   if (packet.has_trace_config()) {
-    ParseTraceConfig(packet.trace_config());
+    // TODO(eseckler): Propagate statuses from modules.
+    protos::pbzero::TraceConfig::Decoder config(packet.trace_config());
+    for (auto& module : context_->modules) {
+      module->ParseTraceConfig(config);
+    }
   }
 }
 
@@ -444,61 +440,6 @@
     context_->storage->IncrementStats(stats::metatrace_overruns);
 }
 
-void ProtoTraceParser::ParseTraceUuid(ConstBytes blob) {
-  // If both the TraceUuid packet and TraceConfig.trace_uuid_msb/lsb are set,
-  // the former (which is emitted first) takes precedence. This is because the
-  // UUID can change throughout the lifecycle of a tracing session if gap-less
-  // snapshots are used. Each trace file has at most one TraceUuid packet (i
-  // has if it comes from an older version of the tracing service < v32)
-  protos::pbzero::TraceUuid::Decoder uuid_packet(blob.data, blob.size);
-  if (uuid_packet.msb() != 0 || uuid_packet.lsb() != 0) {
-    base::Uuid uuid(uuid_packet.lsb(), uuid_packet.msb());
-    std::string str = uuid.ToPrettyString();
-    StringId id = context_->storage->InternString(base::StringView(str));
-    context_->metadata_tracker->SetMetadata(metadata::trace_uuid,
-                                            Variadic::String(id));
-    context_->uuid_found_in_trace = true;
-  }
-}
-
-void ProtoTraceParser::ParseTraceConfig(ConstBytes blob) {
-  protos::pbzero::TraceConfig::Decoder trace_config(blob.data, blob.size);
-
-  // TODO(eseckler): Propagate statuses from modules.
-  for (auto& module : context_->modules) {
-    module->ParseTraceConfig(trace_config);
-  }
-
-  int64_t uuid_msb = trace_config.trace_uuid_msb();
-  int64_t uuid_lsb = trace_config.trace_uuid_lsb();
-  if (!context_->uuid_found_in_trace && (uuid_msb != 0 || uuid_lsb != 0)) {
-    base::Uuid uuid(uuid_lsb, uuid_msb);
-    std::string str = uuid.ToPrettyString();
-    StringId id = context_->storage->InternString(base::StringView(str));
-    context_->metadata_tracker->SetMetadata(metadata::trace_uuid,
-                                            Variadic::String(id));
-    context_->uuid_found_in_trace = true;
-  }
-
-  if (trace_config.has_unique_session_name()) {
-    StringId id = context_->storage->InternString(
-        base::StringView(trace_config.unique_session_name()));
-    context_->metadata_tracker->SetMetadata(metadata::unique_session_name,
-                                            Variadic::String(id));
-  }
-
-  DescriptorPool pool;
-  pool.AddFromFileDescriptorSet(kConfigDescriptor.data(),
-                                kConfigDescriptor.size());
-
-  std::string text = protozero_to_text::ProtozeroToText(
-      pool, ".perfetto.protos.TraceConfig", blob,
-      protozero_to_text::kIncludeNewLines);
-  StringId id = context_->storage->InternString(base::StringView(text));
-  context_->metadata_tracker->SetMetadata(metadata::trace_config_pbtxt,
-                                          Variadic::String(id));
-}
-
 StringId ProtoTraceParser::GetMetatraceInternedString(uint64_t iid) {
   StringId* maybe_id = metatrace_interned_strings_.Find(iid);
   if (!maybe_id)
diff --git a/src/trace_processor/importers/proto/proto_trace_parser.h b/src/trace_processor/importers/proto/proto_trace_parser.h
index f3c17ec..bfe5602 100644
--- a/src/trace_processor/importers/proto/proto_trace_parser.h
+++ b/src/trace_processor/importers/proto/proto_trace_parser.h
@@ -64,8 +64,6 @@
   void ParseTraceStats(ConstBytes);
   void ParseChromeEvents(int64_t ts, ConstBytes);
   void ParseMetatraceEvent(int64_t ts, ConstBytes);
-  void ParseTraceConfig(ConstBytes);
-  void ParseTraceUuid(ConstBytes);
 
  private:
   StringId GetMetatraceInternedString(uint64_t iid);