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.81k stars 350 forks source link

How to get system begin time of a trace slice #729

Closed dionysus1016 closed 7 months ago

dionysus1016 commented 7 months ago

I have a trace file which contains only scheduling events. How can I check the system time of a slice? for not, it shows tickets offsets

aMayzner commented 7 months ago

If you click on a slice in the UI you will see "Duration" with breakdown into "Running", "Runnable" or "Sleeping". Yesterday we also introduced table thread_slice_cpu_time with duration of CPU time for a slice. It will be able to be included using INCLUDE PERFETTO MODULE slices.cpu_time, but is not yet available on autopush.

dionysus1016 commented 7 months ago

@aMayzner, Thanks for your reply, Is it possible to know the system time when schedule event happens? E.g time in UTC, I checked metric and stats in perfecto UI, it seems beginning time is not recorded, otherwise I can calculate slice begin time by adding an offset on recording begin time.

aMayzner commented 7 months ago

You might want to query the sched table (https://perfetto.dev/docs/analysis/sql-tables#sched_slice) directly to find all scheduling events. You can also query trace beginning time by TRACE_START().

LalitMaganti commented 7 months ago

If you are looking for the "realtime" (i.e. wall time or UTC time) of a scheduling event, you can use the TO_REALTIME or ABS_TIME_STR functions and combine it with querying the sched table that Anna linked about. Something like:

SELECT ABS_TIME_STR(ts) from sched

or

SELECT TO_REALTIME(ts) from sched

Note that requires the trace to contain clock snapshots containing the mapping from realtime to trace time: this should have been automatically generated at the start of the trace by traced if you collected the trace using Perfetto.