perfetto icon indicating copy to clipboard operation
perfetto copied to clipboard

Add support for splitting Perfetto traces

Open tingfengwanxiao opened this issue 2 years ago • 25 comments

When I use as ./traceconv.exe systrace 1.pftrace 2.ftrace,I get a empty 2.ftrace, it seems because my 1.pftrace is too large as 8G,so How can I change so large perfetto trace to ftrace, or how can I directly capture a ftrace by som command as large as 8G?

tingfengwanxiao avatar Nov 27 '24 10:11 tingfengwanxiao

Are you sure it's actually because the file is large? Have you tried with a smaller file and things work correctly?

I would be a bit surprised if the file being large was an issue albeit it's not impossible I guess.

Just to be clear, if you have an 8GB Perfetto file, that will turn into a 20GB or more systrace file. What are you planning on doing with that in the end?

LalitMaganti avatar Nov 27 '24 10:11 LalitMaganti

I want to capture a long-term trace and then divide it into smaller ones at certain time points, but perfetto trace seems unable to be directly divided, so I want to convert it into ftrace and use text processing to divide it. Do you have any good suggestions

tingfengwanxiao avatar Nov 27 '24 11:11 tingfengwanxiao

Why not just collect many small traces in the first place? Would be a lot easier than capturing a big trace and then trying to split it.

LalitMaganti avatar Nov 27 '24 11:11 LalitMaganti

Why not just collect many small traces in the first place? Would be a lot easier than capturing a big trace and then trying to split it.

I don't know when I need the trace,so I need to collect it all

tingfengwanxiao avatar Nov 27 '24 11:11 tingfengwanxiao

Fine I don't think it's worth discussing more in that direction.

Back to the actual topic at hand: would still be useful to know if this is only an issue on big traces or also happening on smaller traces. Especially interesting is if the cut-off is 4GB.

LalitMaganti avatar Nov 27 '24 11:11 LalitMaganti

The small ones won't happen, the large ones will happen multiple times, and the converted files will be empty

tingfengwanxiao avatar Nov 27 '24 11:11 tingfengwanxiao

Do you have enough memory on your system to have the full trace in memory i.e. at least 20GB of free memory? Because systrace conversion works by first parsing the full trace into trace processor tables before then doing the conversion.

LalitMaganti avatar Nov 27 '24 11:11 LalitMaganti

Specifically, what happens if you just try and just parse the trace with trace_processor_shell? Does it work?

LalitMaganti avatar Nov 27 '24 11:11 LalitMaganti

Do you have enough memory on your system to have the full trace in memory i.e. at least 20GB of free memory? Because systrace conversion works by first parsing the full trace into trace processor tables before then doing the conversion.

I only have 16G,maybe its reason

tingfengwanxiao avatar Nov 27 '24 11:11 tingfengwanxiao

Then how can I do for this large trace? split it by time for some small trace

tingfengwanxiao avatar Nov 27 '24 11:11 tingfengwanxiao

There's not really a good solution for this today unfortunately. Everyone who needs this sort of thing today just collects smaller traces in the first place.

LalitMaganti avatar Nov 27 '24 11:11 LalitMaganti

ok ,thank you !

tingfengwanxiao avatar Nov 27 '24 11:11 tingfengwanxiao

I've changed this bug to track a better implementation of trace splitting: we might implement it at some point but for us it's not a super high priority.

LalitMaganti avatar Nov 27 '24 11:11 LalitMaganti

Can I use trace_processor_shell query the trace such as "select * from slice where slice > start.ts and slice.ts<end.ts" to get the trace between them and save the new trace?

tingfengwanxiao avatar Dec 24 '24 08:12 tingfengwanxiao

Or whether it is possible to read in batches instead of all at once

Do you have enough memory on your system to have the full trace in memory i.e. at least 20GB of free memory? Because systrace conversion works by first parsing the full trace into trace processor tables before then doing the conversion.

tingfengwanxiao avatar Dec 24 '24 08:12 tingfengwanxiao

No neither is possible.

LalitMaganti avatar Dec 24 '24 09:12 LalitMaganti

Also to use trace processor with such a large trace in the first place still requires you to have enough memory to hold the full trace in memory.

LalitMaganti avatar Dec 24 '24 10:12 LalitMaganti

Why not just collect many small traces in the first place? Would be a lot easier than capturing a big trace and then trying to split it.

Hi,I want to obtain a bunch of trace files with long time spans, and there is no time gap between them. But the trace config will stop the trace when the limit was reached. When I restart a new trace, the time gap will occur.

Image

Image

Do we have the function of automatic slicing during collection or any plan in the future?

fengzikuaipao avatar May 29 '25 02:05 fengzikuaipao

Do we have the function of automatic slicing during collection or any plan in the future?

If you change your approach slightly you can get something close to what you are looking for but not exactly. You want something like this:

  • Remove write_into_file and all related options from your trace config completely
  • Add a CLONE_SNAPSHOT trigger [1] [2] to your config with name like "snapshot-10s" or similar
  • Start the trace
  • Write a bash script which every 10s runs /system/bin/trigger_perfetto "snapshot-10s"

This will produce as many trace files every 10s with a "snapshot" of the buffers. While this does do the "slicing" you are looking for, there will be overlaps between your traces, it will not be a perfect slicing (i.e. the traces will overlap for some period of time). But it might solve whatever problem you are having.

If you are looking for perfect slicing, it's not possible today nor are there any plans to support it. Honestly, I'm not sure it's even technically possible during collection, it's more likely we will be able to support it as a post-processing step really.

[1] https://perfetto.dev/docs/reference/trace-config-proto#TraceConfig.TriggerConfig [2] https://perfetto.dev/docs/concepts/config#triggers

LalitMaganti avatar May 29 '25 08:05 LalitMaganti

Copying from https://github.com/google/perfetto/pull/2020 for future readers who want to know about why we don't support trace splitting:

It's a very hard problem to do in a general way, you're going to run in all sorts of subtle issue with "ambient state" (things like which processes are running on the system) if you split traces naively.

Concretely: at the start of traces, we snapshot the full state of all the processes on the system. If you do a naive splitting tool where you just split the trace based on packet boundaries, you'll drop this packet and then be confused why there in your split trace all the processes are missing.

Now there are probably 20-25 different similar instances of "we snapshot this at the start of the trace and we want to preserve it" and many more of "we want to preserve some data (e.g. the value of a counter) from before the start of the split trace".

So TLDR it's a very hard problem. It'll be something we get to at some point but to do it properly, it's a multi-month project and it's never been a priority so not something we will get to soon.

LalitMaganti avatar Jul 03 '25 13:07 LalitMaganti