google / perfetto

Performance instrumentation and tracing for Android, Linux and Chrome (read-only mirror of https://android.googlesource.com/platform/external/perfetto/)
https://www.perfetto.dev
Apache License 2.0
2.73k stars 341 forks source link

TrackEvents proto binary recorded by CustomDataSource not successfully displayed by Perfetto UI #812

Closed wangjiyang closed 3 months ago

wangjiyang commented 3 months ago

Hi, I am writting a custom perfetto datasource according to https://perfetto.dev/docs/instrumentation/tracing-sdk#custom-data-sources. Payload data I wrote to this custom data source is actually track events according to https://perfetto.dev/docs/reference/synthetic-track-event.

Everything seems ok and it seems perfetto can successfully generate trace, with my following perfetto cmdline. Howevere, perfetto UI shows empty track counters. I also tried AutoPush release channel, which turns out to be displaying a empty clock_snapshot line.

image

Trace file attached, please unzip it and have a try. trace.zip

adb shell perfetto \
  -c - --txt \
  -o /data/misc/perfetto-traces/trace \
<<EOF

buffers: {
    size_kb: 63488
    fill_policy: DISCARD
}
buffers: {
    size_kb: 2048
    fill_policy: DISCARD
}

data_sources: {
    config {
        name: "logd.socket_data_source"
        target_buffer: 1
        track_event_config {
            enabled_categories: "logd"
        }
    }
}

duration_ms: 10000

EOF

Could you help me to have a check?

Thanks

LalitMaganti commented 3 months ago

Combining custom data sources with https://perfetto.dev/docs/reference/synthetic-track-event is very much, not a recommended way to use Perfetto. A lot of the fields in those protos are set automatically if you use the SDK and so what you're writing on your side is almost certainly being ignored or changed by the tracing service and the SDK

You can confirm this by changing your trace to proto text (https://perfetto.dev/docs/quickstart/traceconv) and seeing what the final protos look like.

Any reason why you cannot just use the track_event macros instead in the custom data source?

wangjiyang commented 3 months ago

Thanks. Issue resolved by correcting child track_descriptor.

            // auto thread = track_descriptor->set_thread(); // not working.
            ...
            auto counter = track_descriptor->set_counter(); // use this one