1# Panda Tracing 2 3This document describes **Panda trace** subsystem. The subsystem provides API for creating *tracepoints* to track key points in the runtime. The subsystem uses the `ftrace` ring buffer to record the trace. 4 5## API 6Trace API is described in libpandabase/trace/trace.h file. It supports tracing a scope execution time and tracking a parameter value. 7### Usage examples: 8```cpp 9... 10#include "trace/trace.h" 11... 12 13void FunctionA() { 14 trace::ScopedTrace scoped_trace("Loading file"); 15 ... 16} 17 18void FunctionB() { 19 trace::ScopedTrace scoped_trace(__func__); 20 ... 21} 22 23void FunctionC() { 24 SCOPED_TRACE_STREAM << "Trace: " << __func__; 25 ... 26} 27 28void FunctionD() { 29 trace::BeginTracePoint(__func__); 30 ... 31 trace::EndTracePoint(); 32} 33 34void FunctionE(int allocated_bytes) { 35 trace::IntTracePoint("Heap Size", allocated_bytes); 36 ... 37} 38``` 39 40## Recording trace 41 42To record and view a trace, do the following steps: 43 441. Enable tracing by the command: 45```bash 46sudo scripts/trace_enable.sh <output_file> <trace_time_in_seconds> 47``` 482. Launch the runtime with extra environment variable: 49```bash 50PANDA_TRACE=1 panda <args> 51``` 523. Stop tracing by ^C if the trace time is still running out. 534. Load <output_file> in Chrome at `chrome://tracing` address. 54