Set the clock id in FrameTracer for TracePacket
Perfetto uses BOOTTIME clock type by default, if it is not mentioned in
the TracePacket. For data sources that use different clock type,
they need to specify it in the TracePacket. SurfaceFlinger uses
MONOTONIC type but this wasn't specified previously, resulting in
misaligned events on the trace.
Test: Take a trace, disconnect the USB cable, turn off the screen,
connect the USB cable after 2 minutes and take a trace again
Bug: 145616132
Change-Id: I1579aba874ecfd6bb8fd1f6d04e6cad61453a62d
diff --git a/services/surfaceflinger/FrameTracer/FrameTracer.cpp b/services/surfaceflinger/FrameTracer/FrameTracer.cpp
index 6f91843..4418116 100644
--- a/services/surfaceflinger/FrameTracer/FrameTracer.cpp
+++ b/services/surfaceflinger/FrameTracer/FrameTracer.cpp
@@ -21,6 +21,7 @@
#include "FrameTracer.h"
#include <android-base/stringprintf.h>
+#include <perfetto/trace/clock_snapshot.pbzero.h>
#include <algorithm>
#include <mutex>
@@ -29,6 +30,7 @@
namespace android {
+using Clock = perfetto::protos::pbzero::ClockSnapshot::Clock;
void FrameTracer::initialize() {
std::call_once(mInitializationFlag, [this]() {
perfetto::TracingInitArgs args;
@@ -130,6 +132,7 @@
uint64_t bufferID, uint64_t frameNumber, nsecs_t timestamp,
FrameEvent::BufferEventType type, nsecs_t duration) {
auto packet = ctx.NewTracePacket();
+ packet->set_timestamp_clock_id(Clock::MONOTONIC);
packet->set_timestamp(timestamp);
auto* event = packet->set_graphics_frame_event()->set_buffer_event();
event->set_buffer_id(static_cast<uint32_t>(bufferID));