tp: Store trace time clock id to enable recovery of all data
Bug:273263113
Change-Id: Ie7e9c0b7306777c3bc323fee782b90366b185b17
diff --git a/Android.bp b/Android.bp
index f3598be..8a41156 100644
--- a/Android.bp
+++ b/Android.bp
@@ -9297,6 +9297,7 @@
"src/trace_processor/importers/common/event_tracker.cc",
"src/trace_processor/importers/common/flow_tracker.cc",
"src/trace_processor/importers/common/global_args_tracker.cc",
+ "src/trace_processor/importers/common/metadata_tracker.cc",
"src/trace_processor/importers/common/process_tracker.cc",
"src/trace_processor/importers/common/slice_tracker.cc",
"src/trace_processor/importers/common/slice_translation_table.cc",
@@ -9587,7 +9588,6 @@
"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_minimal_module.cc",
- "src/trace_processor/importers/proto/metadata_tracker.cc",
"src/trace_processor/importers/proto/network_trace_module.cc",
"src/trace_processor/importers/proto/packet_analyzer.cc",
"src/trace_processor/importers/proto/packet_sequence_state_generation.cc",
diff --git a/BUILD b/BUILD
index 080ae05..a79e0f2 100644
--- a/BUILD
+++ b/BUILD
@@ -1121,6 +1121,8 @@
"src/trace_processor/importers/common/flow_tracker.h",
"src/trace_processor/importers/common/global_args_tracker.cc",
"src/trace_processor/importers/common/global_args_tracker.h",
+ "src/trace_processor/importers/common/metadata_tracker.cc",
+ "src/trace_processor/importers/common/metadata_tracker.h",
"src/trace_processor/importers/common/process_tracker.cc",
"src/trace_processor/importers/common/process_tracker.h",
"src/trace_processor/importers/common/slice_tracker.cc",
@@ -1412,8 +1414,6 @@
"src/trace_processor/importers/proto/memory_tracker_snapshot_parser.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/network_trace_module.cc",
"src/trace_processor/importers/proto/network_trace_module.h",
"src/trace_processor/importers/proto/packet_analyzer.cc",
diff --git a/src/trace_processor/export_json_unittest.cc b/src/trace_processor/export_json_unittest.cc
index 07722a0..823bc17 100644
--- a/src/trace_processor/export_json_unittest.cc
+++ b/src/trace_processor/export_json_unittest.cc
@@ -28,9 +28,9 @@
#include "perfetto/ext/base/temp_file.h"
#include "src/trace_processor/importers/common/args_tracker.h"
#include "src/trace_processor/importers/common/event_tracker.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#include "src/trace_processor/importers/common/process_tracker.h"
#include "src/trace_processor/importers/common/track_tracker.h"
-#include "src/trace_processor/importers/proto/metadata_tracker.h"
#include "src/trace_processor/importers/proto/track_event_tracker.h"
#include "src/trace_processor/storage/trace_storage.h"
#include "src/trace_processor/types/trace_processor_context.h"
diff --git a/src/trace_processor/importers/common/BUILD.gn b/src/trace_processor/importers/common/BUILD.gn
index 22a1154..7795398 100644
--- a/src/trace_processor/importers/common/BUILD.gn
+++ b/src/trace_processor/importers/common/BUILD.gn
@@ -33,6 +33,8 @@
"flow_tracker.h",
"global_args_tracker.cc",
"global_args_tracker.h",
+ "metadata_tracker.cc",
+ "metadata_tracker.h",
"process_tracker.cc",
"process_tracker.h",
"slice_tracker.cc",
diff --git a/src/trace_processor/importers/common/clock_tracker.cc b/src/trace_processor/importers/common/clock_tracker.cc
index a2feea9..987739c 100644
--- a/src/trace_processor/importers/common/clock_tracker.cc
+++ b/src/trace_processor/importers/common/clock_tracker.cc
@@ -36,8 +36,8 @@
using Clock = protos::pbzero::ClockSnapshot::Clock;
-ClockTracker::ClockTracker(TraceStorage* storage)
- : storage_(storage),
+ClockTracker::ClockTracker(TraceProcessorContext* context)
+ : context_(context),
trace_time_clock_id_(protos::pbzero::BUILTIN_CLOCK_BOOTTIME) {}
ClockTracker::~ClockTracker() = default;
@@ -67,7 +67,7 @@
" cannot use incremental encoding; this is only "
"supported for sequence-scoped clocks.",
clock_id);
- storage_->IncrementStats(stats::invalid_clock_snapshots);
+ context_->storage->IncrementStats(stats::invalid_clock_snapshots);
return snapshot_id;
}
domain.unit_multiplier_ns = clock_ts.clock.unit_multiplier_ns;
@@ -83,7 +83,7 @@
clock_id, clock_ts.clock.unit_multiplier_ns,
clock_ts.clock.is_incremental, domain.unit_multiplier_ns,
domain.is_incremental);
- storage_->IncrementStats(stats::invalid_clock_snapshots);
+ context_->storage->IncrementStats(stats::invalid_clock_snapshots);
return snapshot_id;
}
const int64_t timestamp_ns = clock_ts.timestamp * domain.unit_multiplier_ns;
@@ -95,7 +95,7 @@
PERFETTO_ELOG("Clock sync error: duplicate clock domain with id=%" PRIu64
" at snapshot %" PRIu32 ".",
clock_id, snapshot_id);
- storage_->IncrementStats(stats::invalid_clock_snapshots);
+ context_->storage->IncrementStats(stats::invalid_clock_snapshots);
return snapshot_id;
}
@@ -119,7 +119,7 @@
" not >= %" PRId64 ".",
clock_id, snapshot_id, timestamp_ns,
vect.timestamps_ns.back());
- storage_->IncrementStats(stats::invalid_clock_snapshots);
+ context_->storage->IncrementStats(stats::invalid_clock_snapshots);
return snapshot_id;
}
@@ -220,12 +220,12 @@
PERFETTO_DCHECK(!IsSequenceClock(src_clock_id));
PERFETTO_DCHECK(!IsSequenceClock(target_clock_id));
- storage_->IncrementStats(stats::clock_sync_cache_miss);
+ context_->storage->IncrementStats(stats::clock_sync_cache_miss);
ClockPath path = FindPath(src_clock_id, target_clock_id);
if (!path.valid()) {
// Too many logs maybe emitted when path is invalid.
- storage_->IncrementStats(stats::clock_sync_failure);
+ context_->storage->IncrementStats(stats::clock_sync_failure);
return base::ErrStatus("No path from clock %" PRIu64 " to %" PRIu64
" at timestamp %" PRId64,
src_clock_id, target_clock_id, src_timestamp);
diff --git a/src/trace_processor/importers/common/clock_tracker.h b/src/trace_processor/importers/common/clock_tracker.h
index 2e4a3b1..81588e6 100644
--- a/src/trace_processor/importers/common/clock_tracker.h
+++ b/src/trace_processor/importers/common/clock_tracker.h
@@ -30,7 +30,9 @@
#include "perfetto/ext/base/optional.h"
#include "perfetto/ext/base/status_or.h"
#include "perfetto/ext/base/string_utils.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#include "src/trace_processor/storage/trace_storage.h"
+#include "src/trace_processor/types/trace_processor_context.h"
namespace perfetto {
namespace trace_processor {
@@ -116,9 +118,9 @@
class ClockTracker {
public:
- using ClockId = uint64_t;
+ using ClockId = int64_t;
- explicit ClockTracker(TraceStorage*);
+ explicit ClockTracker(TraceProcessorContext*);
virtual ~ClockTracker();
// Clock description.
@@ -153,7 +155,7 @@
// passed as argument to ClockTracker functions.
static ClockId SeqenceToGlobalClock(uint32_t seq_id, uint32_t clock_id) {
PERFETTO_DCHECK(IsSequenceClock(clock_id));
- return (static_cast<uint64_t>(seq_id) << 32) | clock_id;
+ return (static_cast<int64_t>(seq_id) << 32) | clock_id;
}
// Appends a new snapshot for the given clock domains.
@@ -162,6 +164,12 @@
uint32_t AddSnapshot(const std::vector<ClockTimestamp>&);
base::StatusOr<int64_t> ToTraceTime(ClockId clock_id, int64_t timestamp) {
+ if (PERFETTO_UNLIKELY(!trace_time_clock_id_used_for_conversion_)) {
+ context_->metadata_tracker->SetMetadata(
+ metadata::trace_time_clock_id,
+ Variadic::Integer(trace_time_clock_id_));
+ trace_time_clock_id_used_for_conversion_ = true;
+ }
trace_time_clock_id_used_for_conversion_ = true;
if (clock_id == trace_time_clock_id_)
return timestamp;
@@ -189,6 +197,8 @@
return;
}
trace_time_clock_id_ = clock_id;
+ context_->metadata_tracker->SetMetadata(
+ metadata::trace_time_clock_id, Variadic::Integer(trace_time_clock_id_));
}
void set_cache_lookups_disabled_for_testing(bool v) {
@@ -328,7 +338,7 @@
return &it->second;
}
- TraceStorage* const storage_;
+ TraceProcessorContext* const context_;
ClockId trace_time_clock_id_ = 0;
std::map<ClockId, ClockDomain> clocks_;
std::set<ClockGraphEdge> graph_;
diff --git a/src/trace_processor/importers/common/clock_tracker_unittest.cc b/src/trace_processor/importers/common/clock_tracker_unittest.cc
index 0614372..e625111 100644
--- a/src/trace_processor/importers/common/clock_tracker_unittest.cc
+++ b/src/trace_processor/importers/common/clock_tracker_unittest.cc
@@ -19,6 +19,7 @@
#include <random>
#include "perfetto/ext/base/optional.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#include "src/trace_processor/storage/trace_storage.h"
#include "src/trace_processor/types/trace_processor_context.h"
#include "test/gtest_and_gmock.h"
@@ -31,9 +32,15 @@
class ClockTrackerTest : public ::testing::Test {
public:
+ ClockTrackerTest() {
+ context_.storage.reset(new TraceStorage());
+ context_.metadata_tracker.reset(
+ new MetadataTracker(context_.storage.get()));
+ }
+
// using ClockId = uint64_t;
- TraceStorage storage_;
- ClockTracker ct_{&storage_};
+ TraceProcessorContext context_;
+ ClockTracker ct_{&context_};
base::StatusOr<int64_t> Convert(ClockTracker::ClockId src_clock_id,
int64_t src_timestamp,
ClockTracker::ClockId target_clock_id) {
diff --git a/src/trace_processor/importers/proto/metadata_tracker.cc b/src/trace_processor/importers/common/metadata_tracker.cc
similarity index 98%
rename from src/trace_processor/importers/proto/metadata_tracker.cc
rename to src/trace_processor/importers/common/metadata_tracker.cc
index a5e6928..010b1b7 100644
--- a/src/trace_processor/importers/proto/metadata_tracker.cc
+++ b/src/trace_processor/importers/common/metadata_tracker.cc
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "src/trace_processor/importers/proto/metadata_tracker.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#include "perfetto/ext/base/crash_keys.h"
#include "src/trace_processor/importers/common/process_tracker.h"
diff --git a/src/trace_processor/importers/proto/metadata_tracker.h b/src/trace_processor/importers/common/metadata_tracker.h
similarity index 91%
rename from src/trace_processor/importers/proto/metadata_tracker.h
rename to src/trace_processor/importers/common/metadata_tracker.h
index c3e587e..80cace9 100644
--- a/src/trace_processor/importers/proto/metadata_tracker.h
+++ b/src/trace_processor/importers/common/metadata_tracker.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_METADATA_TRACKER_H_
-#define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_METADATA_TRACKER_H_
+#ifndef SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_METADATA_TRACKER_H_
+#define SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_METADATA_TRACKER_H_
#include "src/trace_processor/storage/trace_storage.h"
@@ -70,4 +70,4 @@
} // namespace trace_processor
} // namespace perfetto
-#endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_METADATA_TRACKER_H_
+#endif // SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_METADATA_TRACKER_H_
diff --git a/src/trace_processor/importers/ftrace/ftrace_parser.cc b/src/trace_processor/importers/ftrace/ftrace_parser.cc
index 7033130..78157d1 100644
--- a/src/trace_processor/importers/ftrace/ftrace_parser.cc
+++ b/src/trace_processor/importers/ftrace/ftrace_parser.cc
@@ -22,6 +22,7 @@
#include "perfetto/protozero/proto_decoder.h"
#include "src/trace_processor/importers/common/args_tracker.h"
#include "src/trace_processor/importers/common/async_track_set_tracker.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#include "src/trace_processor/importers/common/parser_types.h"
#include "src/trace_processor/importers/common/process_tracker.h"
#include "src/trace_processor/importers/ftrace/binder_tracker.h"
@@ -29,7 +30,6 @@
#include "src/trace_processor/importers/ftrace/v4l2_tracker.h"
#include "src/trace_processor/importers/ftrace/virtio_video_tracker.h"
#include "src/trace_processor/importers/i2c/i2c_tracker.h"
-#include "src/trace_processor/importers/proto/metadata_tracker.h"
#include "src/trace_processor/importers/proto/packet_sequence_state.h"
#include "src/trace_processor/importers/syscalls/syscall_tracker.h"
#include "src/trace_processor/importers/systrace/systrace_parser.h"
@@ -1403,7 +1403,6 @@
evt.func_name(), tgid, evt.value());
}
-
/** Parses ion heap events present in Pixel kernels. */
void FtraceParser::ParseIonHeapGrowOrShrink(int64_t timestamp,
uint32_t pid,
@@ -1717,7 +1716,8 @@
ThreadNamePriority::kFtrace);
proc_tracker->AssociateThreads(source_utid, new_utid);
- ThreadStateTracker::GetOrCreate(context_)->PushNewTaskEvent(timestamp, new_utid, source_utid);
+ ThreadStateTracker::GetOrCreate(context_)->PushNewTaskEvent(
+ timestamp, new_utid, source_utid);
}
void FtraceParser::ParseTaskRename(ConstBytes blob) {
diff --git a/src/trace_processor/importers/fuchsia/fuchsia_parser_unittest.cc b/src/trace_processor/importers/fuchsia/fuchsia_parser_unittest.cc
index 92ccb20..349e9d0 100644
--- a/src/trace_processor/importers/fuchsia/fuchsia_parser_unittest.cc
+++ b/src/trace_processor/importers/fuchsia/fuchsia_parser_unittest.cc
@@ -26,13 +26,13 @@
#include "src/trace_processor/importers/common/clock_tracker.h"
#include "src/trace_processor/importers/common/event_tracker.h"
#include "src/trace_processor/importers/common/flow_tracker.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#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/ftrace/sched_event_tracker.h"
#include "src/trace_processor/importers/proto/additional_modules.h"
#include "src/trace_processor/importers/proto/default_modules.h"
-#include "src/trace_processor/importers/proto/metadata_tracker.h"
#include "src/trace_processor/importers/proto/proto_trace_parser.h"
#include "src/trace_processor/importers/proto/stack_profile_tracker.h"
#include "src/trace_processor/sorter/trace_sorter.h"
@@ -228,7 +228,7 @@
slice_ = new NiceMock<MockSliceTracker>(&context_);
context_.slice_tracker.reset(slice_);
context_.slice_translation_table.reset(new SliceTranslationTable(storage_));
- context_.clock_tracker.reset(new ClockTracker(context_.storage.get()));
+ context_.clock_tracker.reset(new ClockTracker(&context_));
clock_ = context_.clock_tracker.get();
context_.flow_tracker.reset(new FlowTracker(&context_));
context_.sorter.reset(new TraceSorter(&context_, CreateParser(),
diff --git a/src/trace_processor/importers/proto/BUILD.gn b/src/trace_processor/importers/proto/BUILD.gn
index 07bdd19..47bf6c7 100644
--- a/src/trace_processor/importers/proto/BUILD.gn
+++ b/src/trace_processor/importers/proto/BUILD.gn
@@ -34,8 +34,6 @@
"memory_tracker_snapshot_parser.h",
"metadata_minimal_module.cc",
"metadata_minimal_module.h",
- "metadata_tracker.cc",
- "metadata_tracker.h",
"network_trace_module.cc",
"network_trace_module.h",
"packet_analyzer.cc",
diff --git a/src/trace_processor/importers/proto/android_probes_parser.cc b/src/trace_processor/importers/proto/android_probes_parser.cc
index 6d37b9c..7827d50 100644
--- a/src/trace_processor/importers/proto/android_probes_parser.cc
+++ b/src/trace_processor/importers/proto/android_probes_parser.cc
@@ -23,8 +23,8 @@
#include "src/trace_processor/importers/common/async_track_set_tracker.h"
#include "src/trace_processor/importers/common/clock_tracker.h"
#include "src/trace_processor/importers/common/event_tracker.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#include "src/trace_processor/importers/common/process_tracker.h"
-#include "src/trace_processor/importers/proto/metadata_tracker.h"
#include "src/trace_processor/importers/syscalls/syscall_tracker.h"
#include "src/trace_processor/types/tcp_state.h"
#include "src/trace_processor/types/trace_processor_context.h"
diff --git a/src/trace_processor/importers/proto/metadata_minimal_module.cc b/src/trace_processor/importers/proto/metadata_minimal_module.cc
index d29b3d3..099cdac 100644
--- a/src/trace_processor/importers/proto/metadata_minimal_module.cc
+++ b/src/trace_processor/importers/proto/metadata_minimal_module.cc
@@ -17,7 +17,7 @@
#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/importers/common/metadata_tracker.h"
#include "src/trace_processor/types/trace_processor_context.h"
#include "protos/perfetto/trace/chrome/chrome_benchmark_metadata.pbzero.h"
diff --git a/src/trace_processor/importers/proto/metadata_module.cc b/src/trace_processor/importers/proto/metadata_module.cc
index 81a4ce6..3374043 100644
--- a/src/trace_processor/importers/proto/metadata_module.cc
+++ b/src/trace_processor/importers/proto/metadata_module.cc
@@ -18,10 +18,10 @@
#include "perfetto/ext/base/base64.h"
#include "perfetto/ext/base/uuid.h"
+#include "src/trace_processor/importers/common/metadata_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/proto/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"
diff --git a/src/trace_processor/importers/proto/proto_trace_parser.cc b/src/trace_processor/importers/proto/proto_trace_parser.cc
index 600b886..fa1ffd6 100644
--- a/src/trace_processor/importers/proto/proto_trace_parser.cc
+++ b/src/trace_processor/importers/proto/proto_trace_parser.cc
@@ -30,12 +30,12 @@
#include "src/trace_processor/importers/common/args_tracker.h"
#include "src/trace_processor/importers/common/event_tracker.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#include "src/trace_processor/importers/common/parser_types.h"
#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/ftrace/ftrace_module.h"
-#include "src/trace_processor/importers/proto/metadata_tracker.h"
#include "src/trace_processor/importers/proto/packet_sequence_state.h"
#include "src/trace_processor/importers/proto/track_event_module.h"
#include "src/trace_processor/storage/metadata.h"
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 5b907a3..ff841aa 100644
--- a/src/trace_processor/importers/proto/proto_trace_parser_unittest.cc
+++ b/src/trace_processor/importers/proto/proto_trace_parser_unittest.cc
@@ -25,13 +25,13 @@
#include "src/trace_processor/importers/common/clock_tracker.h"
#include "src/trace_processor/importers/common/event_tracker.h"
#include "src/trace_processor/importers/common/flow_tracker.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#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/ftrace/sched_event_tracker.h"
#include "src/trace_processor/importers/proto/additional_modules.h"
#include "src/trace_processor/importers/proto/default_modules.h"
-#include "src/trace_processor/importers/proto/metadata_tracker.h"
#include "src/trace_processor/importers/proto/proto_trace_parser.h"
#include "src/trace_processor/importers/proto/stack_profile_tracker.h"
#include "src/trace_processor/sorter/trace_sorter.h"
@@ -243,7 +243,7 @@
slice_ = new NiceMock<MockSliceTracker>(&context_);
context_.slice_tracker.reset(slice_);
context_.slice_translation_table.reset(new SliceTranslationTable(storage_));
- clock_ = new ClockTracker(context_.storage.get());
+ clock_ = new ClockTracker(&context_);
context_.clock_tracker.reset(clock_);
context_.flow_tracker.reset(new FlowTracker(&context_));
context_.sorter.reset(new TraceSorter(&context_, CreateParser(),
diff --git a/src/trace_processor/importers/proto/proto_trace_reader.cc b/src/trace_processor/importers/proto/proto_trace_reader.cc
index cb0567b..f3b06fb 100644
--- a/src/trace_processor/importers/proto/proto_trace_reader.cc
+++ b/src/trace_processor/importers/proto/proto_trace_reader.cc
@@ -28,9 +28,9 @@
#include "perfetto/trace_processor/status.h"
#include "src/trace_processor/importers/common/clock_tracker.h"
#include "src/trace_processor/importers/common/event_tracker.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#include "src/trace_processor/importers/common/track_tracker.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_analyzer.h"
#include "src/trace_processor/importers/proto/packet_sequence_state.h"
#include "src/trace_processor/importers/proto/proto_incremental_state.h"
@@ -399,7 +399,7 @@
}
base::Optional<StringId> ProtoTraceReader::GetBuiltinClockNameOrNull(
- uint64_t clock_id) {
+ int64_t clock_id) {
switch (clock_id) {
case protos::pbzero::ClockSnapshot::Clock::REALTIME:
return context_->storage->InternString("REALTIME");
diff --git a/src/trace_processor/importers/proto/proto_trace_reader.h b/src/trace_processor/importers/proto/proto_trace_reader.h
index 471503a..3776358 100644
--- a/src/trace_processor/importers/proto/proto_trace_reader.h
+++ b/src/trace_processor/importers/proto/proto_trace_reader.h
@@ -75,7 +75,7 @@
TraceBlobView interned_data);
void ParseTraceConfig(ConstBytes);
- base::Optional<StringId> GetBuiltinClockNameOrNull(uint64_t clock_id);
+ base::Optional<StringId> GetBuiltinClockNameOrNull(int64_t clock_id);
PacketSequenceState* GetIncrementalStateForPacketSequence(
uint32_t sequence_id) {
diff --git a/src/trace_processor/importers/proto/system_probes_parser.cc b/src/trace_processor/importers/proto/system_probes_parser.cc
index a16ca4a..3a3c438 100644
--- a/src/trace_processor/importers/proto/system_probes_parser.cc
+++ b/src/trace_processor/importers/proto/system_probes_parser.cc
@@ -23,9 +23,9 @@
#include "perfetto/ext/traced/sys_stats_counters.h"
#include "perfetto/protozero/proto_decoder.h"
#include "src/trace_processor/importers/common/event_tracker.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#include "src/trace_processor/importers/common/process_tracker.h"
#include "src/trace_processor/importers/common/system_info_tracker.h"
-#include "src/trace_processor/importers/proto/metadata_tracker.h"
#include "src/trace_processor/importers/syscalls/syscall_tracker.h"
#include "src/trace_processor/storage/metadata.h"
#include "src/trace_processor/types/trace_processor_context.h"
diff --git a/src/trace_processor/importers/proto/track_event_tokenizer.cc b/src/trace_processor/importers/proto/track_event_tokenizer.cc
index 314d205..35c76a3 100644
--- a/src/trace_processor/importers/proto/track_event_tokenizer.cc
+++ b/src/trace_processor/importers/proto/track_event_tokenizer.cc
@@ -19,9 +19,9 @@
#include "perfetto/base/logging.h"
#include "perfetto/trace_processor/trace_blob_view.h"
#include "src/trace_processor/importers/common/clock_tracker.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#include "src/trace_processor/importers/common/process_tracker.h"
#include "src/trace_processor/importers/common/track_tracker.h"
-#include "src/trace_processor/importers/proto/metadata_tracker.h"
#include "src/trace_processor/importers/proto/packet_sequence_state.h"
#include "src/trace_processor/importers/proto/proto_trace_reader.h"
#include "src/trace_processor/importers/proto/track_event_tracker.h"
diff --git a/src/trace_processor/storage/metadata.h b/src/trace_processor/storage/metadata.h
index de2e651..88eac06 100644
--- a/src/trace_processor/storage/metadata.h
+++ b/src/trace_processor/storage/metadata.h
@@ -50,6 +50,7 @@
F(system_version, KeyType::kSingle, Variadic::kString), \
F(trace_config_pbtxt, KeyType::kSingle, Variadic::kString), \
F(trace_size_bytes, KeyType::kSingle, Variadic::kInt), \
+ F(trace_time_clock_id, KeyType::kSingle, Variadic::kInt), \
F(trace_type, KeyType::kSingle, Variadic::kString), \
F(trace_uuid, KeyType::kSingle, Variadic::kString), \
F(tracing_disabled_ns, KeyType::kSingle, Variadic::kInt), \
diff --git a/src/trace_processor/trace_processor_context.cc b/src/trace_processor/trace_processor_context.cc
index 29fa474..b407e19 100644
--- a/src/trace_processor/trace_processor_context.cc
+++ b/src/trace_processor/trace_processor_context.cc
@@ -26,13 +26,13 @@
#include "src/trace_processor/importers/common/event_tracker.h"
#include "src/trace_processor/importers/common/flow_tracker.h"
#include "src/trace_processor/importers/common/global_args_tracker.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#include "src/trace_processor/importers/common/process_tracker.h"
#include "src/trace_processor/importers/common/slice_tracker.h"
#include "src/trace_processor/importers/common/slice_translation_table.h"
#include "src/trace_processor/importers/common/track_tracker.h"
#include "src/trace_processor/importers/ftrace/ftrace_module.h"
#include "src/trace_processor/importers/proto/heap_profile_tracker.h"
-#include "src/trace_processor/importers/proto/metadata_tracker.h"
#include "src/trace_processor/importers/proto/perf_sample_tracker.h"
#include "src/trace_processor/importers/proto/proto_importer_module.h"
#include "src/trace_processor/importers/proto/proto_trace_parser.h"
diff --git a/src/trace_processor/trace_processor_impl.cc b/src/trace_processor/trace_processor_impl.cc
index 24bb87e..7c38b98 100644
--- a/src/trace_processor/trace_processor_impl.cc
+++ b/src/trace_processor/trace_processor_impl.cc
@@ -33,6 +33,7 @@
#include "perfetto/trace_processor/basic_types.h"
#include "src/trace_processor/importers/android_bugreport/android_bugreport_parser.h"
#include "src/trace_processor/importers/common/clock_tracker.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#include "src/trace_processor/importers/ftrace/sched_event_tracker.h"
#include "src/trace_processor/importers/fuchsia/fuchsia_trace_parser.h"
#include "src/trace_processor/importers/fuchsia/fuchsia_trace_tokenizer.h"
@@ -43,7 +44,6 @@
#include "src/trace_processor/importers/ninja/ninja_log_parser.h"
#include "src/trace_processor/importers/proto/additional_modules.h"
#include "src/trace_processor/importers/proto/content_analyzer.h"
-#include "src/trace_processor/importers/proto/metadata_tracker.h"
#include "src/trace_processor/importers/systrace/systrace_trace_parser.h"
#include "src/trace_processor/iterator_impl.h"
#include "src/trace_processor/prelude/functions/create_function.h"
diff --git a/src/trace_processor/trace_processor_storage_impl.cc b/src/trace_processor/trace_processor_storage_impl.cc
index 3bea7eb..75031f8 100644
--- a/src/trace_processor/trace_processor_storage_impl.cc
+++ b/src/trace_processor/trace_processor_storage_impl.cc
@@ -25,6 +25,7 @@
#include "src/trace_processor/importers/common/clock_tracker.h"
#include "src/trace_processor/importers/common/event_tracker.h"
#include "src/trace_processor/importers/common/flow_tracker.h"
+#include "src/trace_processor/importers/common/metadata_tracker.h"
#include "src/trace_processor/importers/common/process_tracker.h"
#include "src/trace_processor/importers/common/slice_tracker.h"
#include "src/trace_processor/importers/common/slice_translation_table.h"
@@ -32,7 +33,6 @@
#include "src/trace_processor/importers/proto/chrome_track_event.descriptor.h"
#include "src/trace_processor/importers/proto/default_modules.h"
#include "src/trace_processor/importers/proto/heap_profile_tracker.h"
-#include "src/trace_processor/importers/proto/metadata_tracker.h"
#include "src/trace_processor/importers/proto/packet_analyzer.h"
#include "src/trace_processor/importers/proto/perf_sample_tracker.h"
#include "src/trace_processor/importers/proto/proto_importer_module.h"
@@ -60,7 +60,7 @@
context_.flow_tracker.reset(new FlowTracker(&context_));
context_.event_tracker.reset(new EventTracker(&context_));
context_.process_tracker.reset(new ProcessTracker(&context_));
- context_.clock_tracker.reset(new ClockTracker(context_.storage.get()));
+ context_.clock_tracker.reset(new ClockTracker(&context_));
context_.heap_profile_tracker.reset(new HeapProfileTracker(&context_));
context_.perf_sample_tracker.reset(new PerfSampleTracker(&context_));
context_.global_stack_profile_tracker.reset(new GlobalStackProfileTracker());
diff --git a/test/trace_processor/diff_tests/parsing/chrome_metadata.out b/test/trace_processor/diff_tests/parsing/chrome_metadata.out
index 7346e41..873e349 100644
--- a/test/trace_processor/diff_tests/parsing/chrome_metadata.out
+++ b/test/trace_processor/diff_tests/parsing/chrome_metadata.out
@@ -1,9 +1,10 @@
"id","type","name","key_type","int_value","str_value"
-0,"metadata","trace_uuid","single","[NULL]","00000000-0000-0000-dcce-849205cfb03e"
-1,"metadata","cr-playstore_version_code","single",101,"[NULL]"
-2,"metadata","cr-enabled_categories","single","[NULL]","cat1,cat2,cat3"
-3,"metadata","cr-background_tracing_metadata","single","[NULL]","CgUlDsAbXx2RziSz"
-4,"metadata","cr-scenario_name_hash","single",3005533841,"[NULL]"
-5,"metadata","cr-triggered_rule_name_hash","single",1595654158,"[NULL]"
-6,"metadata","trace_size_bytes","single",64,"[NULL]"
-7,"metadata","trace_type","single","[NULL]","proto"
+0,"metadata","trace_uuid","single","[NULL]","00000000-0000-0000-dcce-849205cfb03e"
+1,"metadata","trace_time_clock_id","single",6,"[NULL]"
+2,"metadata","cr-playstore_version_code","single",101,"[NULL]"
+3,"metadata","cr-enabled_categories","single","[NULL]","cat1,cat2,cat3"
+4,"metadata","cr-background_tracing_metadata","single","[NULL]","CgUlDsAbXx2RziSz"
+5,"metadata","cr-scenario_name_hash","single",3005533841,"[NULL]"
+6,"metadata","cr-triggered_rule_name_hash","single",1595654158,"[NULL]"
+7,"metadata","trace_size_bytes","single",64,"[NULL]"
+8,"metadata","trace_type","single","[NULL]","proto"