Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write TrackEvent protos to generate visual tracks like ftrace CPU tasks #880

Open
wangjiyang opened this issue Sep 9, 2024 · 6 comments

Comments

@wangjiyang
Copy link

Hi,
I successfully write TrackEvent protos as described https://perfetto.dev/docs/reference/synthetic-track-event. However, I can't find any descriptions to describe how to generate visual tracks like cpu-level tasks in ftrace, as shown below in attachment. Is it possible to write these trackevent protos directly to show such visual effects?

image

@LalitMaganti
Copy link
Collaborator

This is not possible at the moment unless you want to try and reverse engineer how the ftrace protos work (which I really wouldn't recommend they are quite complicated).

However in general we plan on adding a bunch of easy to synthesise protos for all the sorts of data Perfetto can generate in the coming months (including an easier to generate format than track event for slices/counters). Protos for generating scheduling data will be one of the things we add as part of this.

@wangjiyang
Copy link
Author

Thanks. There is always something new. Waiting for you update.

@wangjiyang
Copy link
Author

wangjiyang commented Sep 9, 2024

Does process-scoped (async) slices support show thread time, by extra_counter_track_uuids stuff? I tried to add thread information to track_descriptor, seems not working. You can third child show in a seperate track visually.

image

if __name__ == '__main__':
    trace = Trace()

    packet = trace.packet.add()
    packet.track_descriptor.uuid = 48948
    packet.track_descriptor.name = "My special track"
    packet.track_descriptor.process.pid = 1234
    packet.track_descriptor.process.process_name = "My process name"

    packet = trace.packet.add()
    packet.timestamp = 200
    packet.track_event.type = TrackEvent.TYPE_SLICE_BEGIN
    packet.track_event.track_uuid = 48948
    packet.track_event.name = "My special parent A"
    packet.trusted_packet_sequence_id = 3903809

    packet = trace.packet.add()
    packet.timestamp = 250
    packet.track_event.type = TrackEvent.TYPE_SLICE_BEGIN
    packet.track_event.track_uuid = 48948
    packet.track_event.name = "My special child"
    packet.trusted_packet_sequence_id = 3903809

    packet = trace.packet.add()
    packet.timestamp = 290
    packet.track_event.type = TrackEvent.TYPE_SLICE_END
    packet.track_event.track_uuid = 48948
    packet.trusted_packet_sequence_id = 3903809

    packet = trace.packet.add()
    packet.timestamp = 300
    packet.track_event.type = TrackEvent.TYPE_SLICE_END
    packet.track_event.track_uuid = 48948
    packet.trusted_packet_sequence_id = 3903809

    packet = trace.packet.add()
    packet.track_descriptor.uuid = 2390190934
    packet.track_descriptor.name = "My special track"
    # add tid
    packet.track_descriptor.thread.pid = 1234
    packet.track_descriptor.thread.tid = 5678
    packet.track_descriptor.thread.thread_name = 'aaaaa'
    packet.trusted_packet_sequence_id = 3903809

    packet.track_descriptor.parent_uuid = 48948

    packet = trace.packet.add()
    packet.timestamp = 230
    packet.track_event.type = TrackEvent.TYPE_SLICE_BEGIN
    packet.track_event.track_uuid = 2390190934
    packet.track_event.name = "My special parent A"
    packet.trusted_packet_sequence_id = 3903809

    packet = trace.packet.add()
    packet.timestamp = 260
    packet.track_event.type = TrackEvent.TYPE_SLICE_BEGIN
    packet.track_event.track_uuid = 2390190934
    packet.track_event.name = "My special child"
    packet.trusted_packet_sequence_id = 3903809

    # third one
    packet = trace.packet.add()
    packet.track_descriptor.uuid = 2390190935
    packet.track_descriptor.name = "My special track"
    # add tid
    packet.track_descriptor.thread.pid = 1234
    packet.track_descriptor.thread.tid = 5678
    packet.track_descriptor.thread.thread_name = 'aaaaa'
    packet.trusted_packet_sequence_id = 3903810
    packet.track_descriptor.parent_uuid = 48948

    packet = trace.packet.add()
    packet.timestamp = 265
    packet.track_event.type = TrackEvent.TYPE_SLICE_BEGIN
    packet.track_event.track_uuid = 2390190935
    packet.track_event.name = "My special 3 child"
    packet.trusted_packet_sequence_id = 3903809

    packet = trace.packet.add()
    packet.timestamp = 270
    packet.track_event.type = TrackEvent.TYPE_SLICE_END
    packet.track_event.track_uuid = 2390190935
    packet.trusted_packet_sequence_id = 3903809



    packet = trace.packet.add()
    packet.timestamp = 270
    packet.track_event.type = TrackEvent.TYPE_SLICE_END
    packet.track_event.track_uuid = 2390190934
    packet.trusted_packet_sequence_id = 3903809

    packet = trace.packet.add()
    packet.timestamp = 295
    packet.track_event.type = TrackEvent.TYPE_SLICE_END
    packet.track_event.track_uuid = 2390190934
    packet.trusted_packet_sequence_id = 3903809

    with open("trace_output.pb", "wb") as f:
        f.write(trace.SerializeToString())

@LalitMaganti
Copy link
Collaborator

LalitMaganti commented Sep 9, 2024

No process scoped slices do not support CPU time: that's a feature of thread scoped slices only (since CPU time does not really make sense for anything process related in the first place).

@wangjiyang
Copy link
Author

I am looking for some visual feature of mouse selecting and draging and make use of perfetto ui's aggragation feature, which can show associated internal values with these slices. Is this feature in your roadmap?

Thanks.

@LalitMaganti
Copy link
Collaborator

In general making aggregation work flexibly and consistently is very much on our roadmap yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants