Getting Started with Percepio Tracealyzer
Snapshot Tracing (Ring Buffer)
Overview
Snapshot tracing stores trace data in a RAM buffer on the target device. When recording stops, the buffer can be retrieved and opened in Tracealyzer for analysis.
The buffer has a fixed capacity, so a snapshot contains only a portion of the execution history. Snapshot tracing is often the easiest way to get started and is useful for debugging deployed devices where continuous streaming is unavailable or impractical.
Since Tracealyzer 4.6, snapshot tracing is supported using the default TraceRecorder mode with the RingBuffer stream port. This is the recommended approach for new projects.
1. Configure Target-Side Snapshot Recording
Select the RingBuffer stream port
Use the RingBuffer stream port to store trace data in target RAM instead of continuously transferring it to the host.
Locate the RingBuffer implementation in the TraceRecorderSource repository.
Integrate the port using your platform’s normal configuration method. Depending on the RTOS, this may involve enabling a configuration option or adding source files and headers manually.
Configure the snapshot buffer
The main settings are defined in trcStreamPortConfig_RingBuffer.h.
| Setting | Default | Description |
|---|---|---|
TRC_CFG_STREAM_PORT_
|
10240 bytes |
RAM allocated for trace data. Increase this value to retain more events, subject to available memory. |
TRC_CFG_STREAM_PORT_
|
TRC_CFG_STREAM_PORT_
|
Determines what happens when the buffer fills up. |
Two buffer modes are available:
- Overwrite when full: New events overwrite the oldest events, preserving the most recent execution history.
- Stop when full: Recording stops when the buffer reaches capacity, preserving the earliest recorded events.
Choose the mode based on whether you need to investigate what happened immediately before an issue or preserve the complete trace from the start of recording.
Start recording
Initialize TraceRecorder and start tracing using the mechanism supported by your integration. For a typical application:
xTraceEnable(TRC_START);
Recording can also be controlled by host commands where supported.
For programmatic snapshots, stop recording before retrieving or saving the trace data. This ensures that the buffer is not being modified while it is extracted.
2. Retrieve the Snapshot
Tracealyzer needs the raw trace data from the target buffer. The data can be retrieved using any method that preserves the buffer contents, such as:
- Debugger: Use GDB or a supported debug probe to read the buffer from target RAM.
- Serial or another interface: Transfer the buffer contents to the host using application-specific code.
- Target file system: Stop recording and save the trace data to local storage.
- Integrated IDE or debug probe: Use a supported Tracealyzer integration to automate retrieval.
The exact procedure depends on your RTOS, target platform, and debug environment.
Save the extracted data in the format expected by Tracealyzer, typically a .psf trace file.
3. Open and Analyze the Snapshot
- Retrieve the trace data from target RAM or the target’s file system.
- Save it as a
.psffile if your retrieval method does not already produce one. - Open the file in Tracealyzer.
- Inspect the timeline, task execution, event history, and other trace views to investigate system behavior.
If your IDE or debug probe has a supported Tracealyzer integration, use it to simplify the retrieval process.
4. Programmatic Snapshot Capture
Snapshot capture can be managed directly from target code. This is useful for deployed devices and for capturing trace data when an error condition occurs.
A typical workflow is:
- Start trace recording.
- Detect the condition you want to investigate.
- Stop recording.
- Save or transfer the trace buffer.
- Open the resulting trace in Tracealyzer.
The method used to stop recording and extract the buffer depends on the TraceRecorder integration. Ensure that recording has stopped before saving the data.
5. Troubleshooting
- Trace is too short: Increase
TRC_CFG_STREAM_PORT_BUFFER_SIZEif target RAM permits. - Important events are missing: Check whether the buffer overwrites older data or stops when full. Select the mode that matches your debugging goal.
- Tracealyzer cannot open the file: Verify that the extracted data contains the complete trace buffer in the expected format.
- Snapshot retrieval produces inconsistent data: Stop recording before reading or saving the buffer.
- Insufficient target RAM: Reduce the buffer size or use streamed tracing if continuous transfer to the host is more suitable.
References
- TraceRecorderSource on GitHub — RingBuffer implementation and configuration headers.
- Tracealyzer Application Notes — platform-specific examples and retrieval workflows.
Recommended approach: Use the RingBuffer stream port with the default TraceRecorder mode for new snapshot-tracing implementations. The legacy snapshot recorder mode, selected through TRC_CFG_RECORDER_MODE in trcKernelPortConfig.h, is retained for older integrations and should generally be avoided for new projects.
Our Products
Percepio® is the leading provider of visual trace diagnostics for embedded and IoT software systems in development and in the field.
TRACEALYZER
Percepio® Tracealyzer combines software tracing with powerful visualizations, allowing users to spot and analyze issues in software recordings during development and testing.
DEVALERT
Percepio® DevAlert is a cloud-connected monitoring framework for OEMs developing RTOS device software, providing instant insight on bugs and anomalies.
