Skip to content

Commit 508e64d

Browse files
committed
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
1 parent 260a091 commit 508e64d

1 file changed

Lines changed: 47 additions & 10 deletions

File tree

libs/tracing_perfetto/tracing_perfetto_internal.cpp

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,31 @@ void perfettoTraceEnd(const struct PerfettoTeCategory& category) {
253253
void perfettoTraceAsyncBeginForTrack(const struct PerfettoTeCategory& category, const char* name,
254254
const char* trackName, uint64_t cookie) {
255255
PERFETTO_TE(
256-
category, PERFETTO_TE_SLICE_BEGIN(name),
257-
PERFETTO_TE_NAMED_TRACK(trackName, cookie, PerfettoTeProcessTrackUuid()));
256+
category, PERFETTO_TE_SLICE_BEGIN(name),
257+
PERFETTO_TE_PROTO_TRACK(
258+
PerfettoTeNamedTrackUuid(trackName, cookie,
259+
PerfettoTeProcessTrackUuid()),
260+
PERFETTO_TE_PROTO_FIELD_CSTR(
261+
perfetto_protos_TrackDescriptor_atrace_name_field_number,
262+
trackName),
263+
PERFETTO_TE_PROTO_FIELD_VARINT(
264+
perfetto_protos_TrackDescriptor_parent_uuid_field_number,
265+
PerfettoTeProcessTrackUuid())));
258266
}
259267

260268
void perfettoTraceAsyncEndForTrack(const struct PerfettoTeCategory& category,
261269
const char* trackName, uint64_t cookie) {
262-
PERFETTO_TE(
263-
category, PERFETTO_TE_SLICE_END(),
264-
PERFETTO_TE_NAMED_TRACK(trackName, cookie, PerfettoTeProcessTrackUuid()));
270+
PERFETTO_TE(
271+
category, PERFETTO_TE_SLICE_END(),
272+
PERFETTO_TE_PROTO_TRACK(
273+
PerfettoTeNamedTrackUuid(trackName, cookie,
274+
PerfettoTeProcessTrackUuid()),
275+
PERFETTO_TE_PROTO_FIELD_CSTR(
276+
perfetto_protos_TrackDescriptor_atrace_name_field_number,
277+
trackName),
278+
PERFETTO_TE_PROTO_FIELD_VARINT(
279+
perfetto_protos_TrackDescriptor_parent_uuid_field_number,
280+
PerfettoTeProcessTrackUuid())));
265281
}
266282

267283
void perfettoTraceAsyncBegin(const struct PerfettoTeCategory& category, const char* name,
@@ -281,14 +297,35 @@ void perfettoTraceInstant(const struct PerfettoTeCategory& category, const char*
281297
void perfettoTraceInstantForTrack(const struct PerfettoTeCategory& category,
282298
const char* trackName, const char* name) {
283299
PERFETTO_TE(
284-
category, PERFETTO_TE_INSTANT(name),
285-
PERFETTO_TE_NAMED_TRACK(trackName, 1, PerfettoTeProcessTrackUuid()));
300+
category, PERFETTO_TE_INSTANT(name),
301+
PERFETTO_TE_PROTO_TRACK(
302+
PerfettoTeNamedTrackUuid(trackName, 1,
303+
PerfettoTeProcessTrackUuid()),
304+
PERFETTO_TE_PROTO_FIELD_CSTR(
305+
perfetto_protos_TrackDescriptor_atrace_name_field_number,
306+
trackName),
307+
PERFETTO_TE_PROTO_FIELD_VARINT(
308+
perfetto_protos_TrackDescriptor_parent_uuid_field_number,
309+
PerfettoTeProcessTrackUuid())));
286310
}
287311

288312
void perfettoTraceCounter(const struct PerfettoTeCategory& category,
289-
[[maybe_unused]] const char* name, int64_t value) {
290-
PERFETTO_TE(category, PERFETTO_TE_COUNTER(),
291-
PERFETTO_TE_INT_COUNTER(value));
313+
const char* name, int64_t value) {
314+
PERFETTO_TE(
315+
category, PERFETTO_TE_COUNTER(),
316+
PERFETTO_TE_PROTO_TRACK(
317+
PerfettoTeCounterTrackUuid(name,
318+
PerfettoTeProcessTrackUuid()),
319+
PERFETTO_TE_PROTO_FIELD_CSTR(
320+
perfetto_protos_TrackDescriptor_atrace_name_field_number,
321+
name),
322+
PERFETTO_TE_PROTO_FIELD_VARINT(
323+
perfetto_protos_TrackDescriptor_parent_uuid_field_number,
324+
PerfettoTeProcessTrackUuid()),
325+
PERFETTO_TE_PROTO_FIELD_BYTES(
326+
perfetto_protos_TrackDescriptor_counter_field_number,
327+
PERFETTO_NULL, 0)),
328+
PERFETTO_TE_INT_COUNTER(value));
292329
}
293330
} // namespace internal
294331

0 commit comments

Comments
 (0)