perfetto icon indicating copy to clipboard operation
perfetto copied to clipboard

Improve UX for combined in-application and system event trace on Linux

Open planetmarshall opened this issue 1 year ago • 3 comments

Hi - I'm having some problems trying to get a combined trace on Linux - I suspect I'm missing a configuration step or something from the docs.

This example from the documentation shows how to combine in-application and system tracing using the SDK.

Here's what I've tried:

Steps to reproduce

  1. Compile the following example with the Perfetto SDK -
#include <perfetto.h>

PERFETTO_DEFINE_CATEGORIES(
    perfetto::Category("rendering")
        .SetDescription("Events from the graphics subsystem"),


PERFETTO_TRACK_EVENT_STATIC_STORAGE();

int main(int argc, char** argv) {
  perfetto::TracingInitArgs args;
  args.backends |= perfetto::kSystemBackend;
  perfetto::Tracing::Initialize(args);

  perfetto::TrackEvent::Register();

 {
   TRACE_EVENT("rendering", "work");
    std::this_thread::sleep_for(std::chrono::milliseconds(500));
 }
TRACE_EVENT("rendering", "more_work");
return 0;
}
  1. Run tracebox as specified in Capturing a Trace with the following config:

buffers {
    size_kb: 100024
    fill_policy: RING_BUFFER
}

data_sources: {
  config {
    name: "linux.sys_stats"
    sys_stats_config {
      stat_period_ms: 1000
      stat_counters: STAT_CPU_TIMES
      stat_counters: STAT_FORK_COUNT
    }
  }
}
data_sources: {
    config {
        name: "track_event"
    }
}

duration_ms: 30000
$ ./tracebox -o trace_file.perfetto-trace --txt -c config.cfg
  1. Run the application to be traced.

  2. When the tracebox command exits, load the trace file into the Perfetto UI

Expected result

The track events and system events are visible in the timeline

Actual result

Only the system events are visible

Alternative steps

I also tried to run the tracebox commands separately as in example_system_wide.cc

  1. Run tracebox traced
  2. Launch the application to be traced
  3. Run tracebox perfetto -o flutter.perfetto.trace --txt -c config.cfg
  4. When the tracebox command exits, load the trace file into the Perfetto UI

This time the application events were visible, but no system events were present.

How can I collect a combined trace?

Many thanks.

planetmarshall avatar Oct 28 '25 18:10 planetmarshall

pls try running with --system-sockets flag (only the below command is needed no need to start traced/traced_probes separately)

./tracebox --system-sockets -o flutter.perfetto.trace --txt -c config.cfg

This is a known pitfall :( and we have it in our pipeline to improve.

The problem you are facing is due to a mismatch in the communication sockets used by tracebox and the Perfetto SDK in your application. The --system-sockets flag forces tracebox to use the same system-wide sockets as the SDK, allowing them to communicate.

sashwinbalaji avatar Oct 28 '25 20:10 sashwinbalaji

Reusing this bug to track the improvements Ashwin mentioned.

LalitMaganti avatar Oct 28 '25 20:10 LalitMaganti

We're fixing this with https://github.com/google/perfetto/discussions/3540 and https://github.com/google/perfetto/pull/3726

LalitMaganti avatar Nov 20 '25 20:11 LalitMaganti