perfetto
perfetto copied to clipboard
write TrackEvent protos to generate visual tracks like ftrace CPU tasks
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?
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.
Thanks. There is always something new. Waiting for you update.
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.
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())
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).
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.
In general making aggregation work flexibly and consistently is very much on our roadmap yes.
We now have support for emitting scheduling data using stable protos. See https://github.com/google/perfetto/blob/cca1748cb16b9dc0cac21515813c3855a983917d/protos/perfetto/trace/generic_kernel/generic_task_state.proto#L20
Closing this out.