Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 508e64d9 authored by Zimuzo Ezeozue's avatar Zimuzo Ezeozue
Browse files

Fix track event names with atrace via Perfetto

The perfettoTraceCounter method was broken because there was no
way to emit the equivalent of NamedTracks (non registered tracks)
for counters. This was fixed in aosp/3284918 with the introduction
of a more general API to create TrackDescriptors. Fixed the counter
track with this new method.

Additionally, a new atrace_name was added to the track descriptor
that doesn't guarantee the strings are fixed (for privacy reason).
Utilized the atrace_name for both slice and counter tracks instead
of the existing static_name.

Bug: 303199244
Test: Manual
Flag: android.os.perfetto_sdk_tracing
Change-Id: I376dc2f661bf1df4968a2983a1bb0f7dbb018f5c
parent 260a091b
Loading
Loading
Loading
Loading
+47 −10
Original line number Diff line number Diff line
@@ -254,14 +254,30 @@ void perfettoTraceAsyncBeginForTrack(const struct PerfettoTeCategory& category,
                                       const char* trackName, uint64_t cookie) {
  PERFETTO_TE(
        category, PERFETTO_TE_SLICE_BEGIN(name),
      PERFETTO_TE_NAMED_TRACK(trackName, cookie, PerfettoTeProcessTrackUuid()));
        PERFETTO_TE_PROTO_TRACK(
            PerfettoTeNamedTrackUuid(trackName, cookie,
                                     PerfettoTeProcessTrackUuid()),
            PERFETTO_TE_PROTO_FIELD_CSTR(
                perfetto_protos_TrackDescriptor_atrace_name_field_number,
                trackName),
            PERFETTO_TE_PROTO_FIELD_VARINT(
                perfetto_protos_TrackDescriptor_parent_uuid_field_number,
                PerfettoTeProcessTrackUuid())));
}

void perfettoTraceAsyncEndForTrack(const struct PerfettoTeCategory& category,
                                     const char* trackName, uint64_t cookie) {
    PERFETTO_TE(
        category, PERFETTO_TE_SLICE_END(),
      PERFETTO_TE_NAMED_TRACK(trackName, cookie, PerfettoTeProcessTrackUuid()));
        PERFETTO_TE_PROTO_TRACK(
            PerfettoTeNamedTrackUuid(trackName, cookie,
                                     PerfettoTeProcessTrackUuid()),
            PERFETTO_TE_PROTO_FIELD_CSTR(
                perfetto_protos_TrackDescriptor_atrace_name_field_number,
                trackName),
            PERFETTO_TE_PROTO_FIELD_VARINT(
                perfetto_protos_TrackDescriptor_parent_uuid_field_number,
                PerfettoTeProcessTrackUuid())));
}

void perfettoTraceAsyncBegin(const struct PerfettoTeCategory& category, const char* name,
@@ -282,12 +298,33 @@ void perfettoTraceInstantForTrack(const struct PerfettoTeCategory& category,
                                    const char* trackName, const char* name) {
  PERFETTO_TE(
        category, PERFETTO_TE_INSTANT(name),
      PERFETTO_TE_NAMED_TRACK(trackName, 1, PerfettoTeProcessTrackUuid()));
        PERFETTO_TE_PROTO_TRACK(
            PerfettoTeNamedTrackUuid(trackName, 1,
                                     PerfettoTeProcessTrackUuid()),
            PERFETTO_TE_PROTO_FIELD_CSTR(
                perfetto_protos_TrackDescriptor_atrace_name_field_number,
                trackName),
            PERFETTO_TE_PROTO_FIELD_VARINT(
                perfetto_protos_TrackDescriptor_parent_uuid_field_number,
                PerfettoTeProcessTrackUuid())));
}

void perfettoTraceCounter(const struct PerfettoTeCategory& category,
                            [[maybe_unused]] const char* name, int64_t value) {
  PERFETTO_TE(category, PERFETTO_TE_COUNTER(),
                          const char* name, int64_t value) {
  PERFETTO_TE(
        category, PERFETTO_TE_COUNTER(),
        PERFETTO_TE_PROTO_TRACK(
            PerfettoTeCounterTrackUuid(name,
                                       PerfettoTeProcessTrackUuid()),
            PERFETTO_TE_PROTO_FIELD_CSTR(
                perfetto_protos_TrackDescriptor_atrace_name_field_number,
                name),
            PERFETTO_TE_PROTO_FIELD_VARINT(
                perfetto_protos_TrackDescriptor_parent_uuid_field_number,
                PerfettoTeProcessTrackUuid()),
            PERFETTO_TE_PROTO_FIELD_BYTES(
                perfetto_protos_TrackDescriptor_counter_field_number,
                PERFETTO_NULL, 0)),
        PERFETTO_TE_INT_COUNTER(value));
}
}  // namespace internal