How to improve compression rate and modify information by modifying the content of trace files?
Hello I am currently using two formats of trace files, namely Linux system trace files and custom trace files: (1)Linux system trace files
-
I found that the Linux system trace file is a compressed format, where a packet can contain multiple switch and wake-up events, as well as information about multiple processes and threads.
-
There is an example file
linux_System.exe. jsonin the attachment, which is the Linux system trace file I obtained. It contains partially serialized packet information. linux_system_example.json
(2)custom trace files
-
I used these properties of the packet, including
track_descriptor,interned_data,track_event(TYPE_SLICE.BEGIN, TYPE-INSTANT, and TYPE_SLICE.END types, flow_ids property). -
This is an example custom trace file that contains partially serialized packet information. custom_trace_example.json
I have a few questions now and would like to ask them for advice:
(1)I use the custom trace file mentioned above to record the start and end of custom events, custom track hierarchy, and construct event chains (by track_event. flow_ids). But the compression rate of this file format is not high enough, and each packet can only carry one piece of information. Can we further compress files in this format? How to improve compression ratio and benchmark it with Linux system trace files?
(2)Is it feasible to merge the above custom trace file with the Linux system trace file into the one trace file?
(3)The track hierarchy of Linux system trace files is two-tier (i.e. the first level is processes and the second level is threads). Can their hierarchical structure be modified by changing the file content? For example, create a new track named "Linux" and place all processes one level below it.
(4)In a custom trace file packet, event chains can be constructed by setting the flow_ids of track_event. Can event chains be constructed in a Linux system trace file?
Thank you.
I would like to add the style of the trace file displayed in perfetto UI:
(1)Linux system trace files
(2)custom trace files
(1)I use the custom trace file mentioned above to record the start and end of custom events, custom track hierarchy, and construct event chains (by track_event. flow_ids). But the compression rate of this file format is not high enough, and each packet can only carry one piece of information. Can we further compress files in this format? How to improve compression ratio and benchmark it with Linux system trace files?
You can turn on gzip compression at the trace file level which will compress all the contents of the trace using a general puprpose gzip compression pass.
Beyond using interning, there are no options at the Perfetto level to compress any further using track_event. You'd need to invent a custom format but that's a big undertaking: you need to add the protos, support for parsing it TP, visualizing in the UI etc. It's difficult to support a compact format while keeping it also general purpose and usable by lots of people.
(2)Is it feasible to merge the above custom trace file with the Linux system trace file into the one trace file?
Tracked by https://github.com/google/perfetto/issues/1018. I belive fixing this issue is the real solution to most of your problems as it would allow visualizing both traces at the same time without worrying about where the data came from (it would just be an implementation detail).
(3)The track hierarchy of Linux system trace files is two-tier (i.e. the first level is processes and the second level is threads). Can their hierarchical structure be modified by changing the file content? For example, create a new track named "Linux" and place all processes one level below it.
No this is not possible.
(4)In a custom trace file packet, event chains can be constructed by setting the flow_ids of track_event. Can event chains be constructed in a Linux system trace file?
No this is not possible.
Actually I looked a bit more into this and there are couple of other knobs you have available to reduce the track_event data rate:
- TrackEventDefaults: https://cs.android.com/android/platform/superproject/main/+/main:external/perfetto/protos/perfetto/trace/track_event/track_event.proto;drc=c5d26342cdc18c3d7971f66c5d77972037c0fce5;l=414. This allows you to omit specifying the track_uuid if you only have a single track per sequence. This can save up to 10 bytes per event
- TracePacketDefaults: https://cs.android.com/android/platform/superproject/main/+/main:external/perfetto/protos/perfetto/trace/trace_packet_defaults.proto;drc=856a7092569df8e5bbb958317a36f61ec7bbf133;l=33. Specifically you can set a custom clock id which is an incremental clock. This means instead of emitting the raw timestamps, you can emit deltas from the previous value which should shave off 7 bytes or so per event.
Both of these should have a non trivial impact on your trace size so I'd start here.