GstShark is a powerful profiling and debugging tool for GStreamer pipelines. It provides "tracers" that extract data from the pipeline in real-time, allowing you to monitor queue levels, latency, framerate, and CPU usage per element.
System Requirements:
- GStreamer 1.0 installed and working
- Build tools and development libraries
Install the required build tools and GStreamer development libraries.
On Ubuntu / Debian / Raspberry Pi OS:
sudo apt-get update
sudo apt-get install -y \
git \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
libgstreamer-plugins-bad1.0-dev \
autoconf \
automake \
libtool \
graphviz \
pkg-config \
gtk-doc-toolsWe will build gst-shark from source.
-
Clone the repository:
# Clone to a convenient location (e.g., your home directory) cd ~ git clone https://github.com/RidgeRun/gst-shark.git cd gst-shark
Note: The
gst-sharkdirectory is needed later for generating plots. A good default location is~/gst-shark(your home directory). -
Configure: You must specify the correct library directory.
-
For x86_64 PCs (Standard Ubuntu):
./autogen.sh --prefix=/usr/ --libdir=/usr/lib/x86_64-linux-gnu/gstreamer-1.0/
-
For Raspberry Pi 5 (aarch64 / Debian Trixie):
./autogen.sh --prefix=/usr/ --libdir=/usr/lib/aarch64-linux-gnu/gstreamer-1.0/
-
Tip: If you are unsure of your architecture, run
uname -m.x86_64uses the first command,aarch64uses the second.
-
-
Compile and Install:
make sudo make install
Check if GStreamer can see the new tracers:
gst-inspect-1.0 sharktracersYou should see a list of tracers including interlatency, proctime, framerate, queuelevel, etc.
You can print trace information directly to the console to debug bottlenecks live.
This is critical for diagnosing "stuck" pipelines or jitter.
Example with Hailo applications:
# Using a CLI command (e.g., simple detection)
GST_DEBUG="GST_TRACER:7" GST_TRACERS="queuelevel" hailo-detect-simple
# Or using Python script directly
GST_DEBUG="GST_TRACER:7" GST_TRACERS="queuelevel" python3 hailo_apps/python/pipeline_apps/detection_simple/detection_simple.py --input usbWhat to look for:
- Bottleneck: Queue level hits max (e.g.,
30/30) and stays there. The element reading from this queue is too slow. - Starvation: Queue level is always 0. The element feeding this queue is too slow.
You can use multiple tracers by separating them with semicolons:
# Single tracer examples:
GST_TRACERS="interlatency" hailo-detect-simple # Latency Spikes
GST_TRACERS="framerate" hailo-detect-simple # Throughput
GST_TRACERS="proctime" hailo-detect-simple # Processing Time
# Multiple tracers:
GST_DEBUG="GST_TRACER:7" GST_TRACERS="queuelevel;framerate;proctime" hailo-detect-simpleGstShark can record pipeline data to a folder and generate reports in two formats:
- PDF Reports: Static, printable charts suitable for documentation and sharing
- HTML/Interactive Reports: Dynamic, interactive visualizations viewable in web browsers
Both formats use the same trace data, so you can generate both from a single recording session.
PDF reports provide static, printable charts that are excellent for documentation and sharing.
The plotting scripts require Octave, Gnuplot, Ghostscript, and Babeltrace2 (for reading CTF trace data).
sudo apt-get install -y octave gnuplot ghostscript babeltrace2Note: babeltrace2 is required to convert the CTF (Common Trace Format) trace data into a readable format for plotting.
The trace data recording process is the same for both PDF and HTML reports:
Run your application with GST_SHARK_LOCATION set. This tells GstShark where to save the data.
Example with Hailo applications:
# Create a directory for the trace logs (default: /tmp/trace_data)
mkdir -p /tmp/trace_data
# Run the app with desired tracers (using CLI command)
GST_DEBUG="GST_TRACER:7" \
GST_TRACERS="proctime;interlatency;framerate;scheduletime;cpuusage;queuelevel" \
GST_SHARK_LOCATION=/tmp/trace_data \
hailo-detect-simple
# Or using Python script directly
GST_DEBUG="GST_TRACER:7" \
GST_TRACERS="proctime;interlatency;framerate;scheduletime;cpuusage;queuelevel" \
GST_SHARK_LOCATION=/tmp/trace_data \
python3 hailo_apps/python/pipeline_apps/detection_simple/detection_simple.py --input usbNotes:
- The default trace directory is
/tmp/trace_data(you can use any directory path). - Run the app for at least 10-20 seconds to gather meaningful data.
- Stop the app (Ctrl+C).
- You will see a folder
/tmp/trace_datacontaining a CTF (Common Trace Format) metadata file and binary logs. - Use an absolute path for
GST_SHARK_LOCATIONto avoid confusion about where the data is saved.
Use the gstshark-plot script located in the gst-shark source directory you cloned earlier.
# Navigate to the directory where you cloned gst-shark (default: ~/gst-shark)
cd ~/gst-shark
# Run the plotting script with the absolute path to your trace_data directory
# The script will generate PDF charts in the trace_data directory
# Default example using /tmp/trace_data:
./scripts/graphics/gstshark-plot /tmp/trace_data --savefig pdf
# Or if you used a different directory:
./scripts/graphics/gstshark-plot /absolute/path/to/trace_data --savefig pdfNotes:
- The script must be run from the
gst-sharkdirectory (e.g.,~/gst-shark). - Provide the absolute path to your
trace_datadirectory. - Use
--savefig pdfto save the charts as PDF files (default format). - The script generates a single
tracer.pdffile containing all plots appended together. - The PDF is initially created in the
gst-sharkdirectory, but you can copy it to your trace_data directory:cp ~/gst-shark/tracer.pdf /tmp/trace_data/ - The PDF contains multiple pages with charts for each tracer: queuelevel, framerate, cpuusage, proctime, interlatency, scheduling, bitrate, and buffer.
Open the generated PDF (tracer.pdf) which contains multiple pages with charts for each tracer:
- Queue Level: Shows the buffer count in every queue over time. Look for lines that plateau at the top (full) or bottom (empty).
- Frame Rate: Shows the FPS at various points. Look for drops.
- CPU Usage: Shows CPU load per element.
- Processing Time: Shows how long each element takes to process a buffer. This helps identify the slowest specific element (e.g., is it the inference engine, the post-process, or the display?).
- Interlatency: Shows latency between pipeline elements.
- Scheduling: Shows scheduling time for elements.
- Bitrate: Shows bitrate over time.
- Buffer: Shows buffer processing time.
HTML reports provide interactive, web-based visualizations that allow you to zoom, pan, filter, and explore the trace data dynamically. This is ideal for detailed analysis and presentations.
For interactive HTML reports, you only need babeltrace2 which supports conversion to Chrome tracing format:
sudo apt-get install -y babeltrace2Note: babeltrace2 provides format conversion capabilities for CTF traces to interactive formats.
Use the same trace data recording process as described in Section 3.1, Step 2. The trace data can be used for both PDF and HTML reports.
Convert the CTF trace data to Chrome tracing JSON format using babeltrace2:
# First, check available output formats (sink components)
babeltrace2 list-plugins
# Convert CTF trace to text format (babeltrace2 may not have Chrome tracing sink by default)
# Output as text which can then be converted to Chrome tracing format
babeltrace2 convert /tmp/trace_data -c sink.text.pretty > /tmp/trace_data/trace.txtNote: Standard babeltrace2 installations may not include a Chrome tracing sink. Available sinks typically include:
sink.text.pretty- Pretty-print text format (default)sink.text.details- Detailed text outputsink.ctf.fs- Write CTF traces to file system
Alternative approaches for Chrome tracing format:
-
Use Trace Compass (recommended): Trace Compass can directly open CTF traces and provides interactive visualization without conversion.
-
Convert text output: Use the text output from
babeltrace2and convert it to Chrome tracing JSON format using custom scripts or tools. -
Check for additional plugins: Some distributions or custom builds may include Chrome tracing sinks. Check
babeltrace2 list-pluginsfor available sinks in your installation.
Recommended: Using Trace Compass
Trace Compass is the recommended tool for interactive CTF trace visualization as it works directly with CTF traces without conversion:
- Install Trace Compass: Download from https://www.eclipse.org/tracecompass/
- Open Trace Compass
- File → Open Trace → Select
/tmp/trace_datadirectory - Explore the trace data with advanced filtering and analysis features
Interactive Features:
- Zoom: Use mouse wheel or trackpad to zoom in/out on specific time ranges
- Pan: Click and drag to navigate through the timeline
- Filter: Search for specific elements or events
- Details: Click on any event to see detailed information
- Measure: Select time ranges to measure durations between events
- Advanced Analysis: Multiple views and analysis tools for performance profiling
Alternative: Chrome Tracing (if conversion available)
If you have successfully converted the trace to Chrome tracing JSON format, you can view it in Chrome's built-in trace viewer:
- Open Google Chrome browser
- Navigate to
chrome://tracing - Click "Load" button
- Select the generated
trace.jsonfile - Explore the interactive timeline
Note: Chrome tracing format conversion may require additional plugins or custom conversion scripts, as standard babeltrace2 installations may not include Chrome tracing sinks. Trace Compass is recommended as it works directly with CTF traces.
| Feature | PDF Reports | HTML/Interactive Reports |
|---|---|---|
| Format | Static PDF document | Interactive JSON/HTML |
| Viewing | PDF viewer (any platform) | Chrome browser (chrome://tracing) or Trace Compass |
| Interactivity | None (static pages) | Full (zoom, pan, filter, search) |
| Sharing | Easy (single file) | Easy (single JSON file) |
| Printing | Excellent (formatted pages) | Limited (screenshots) |
| Documentation | Ideal for reports and presentations | Ideal for detailed analysis |
| File Size | Small (compressed PDF) | Medium (JSON format) |
| Best For | Documentation, sharing, offline analysis | Interactive exploration, debugging, presentations |
Recommendation:
- Use PDF reports when you need printable documentation, formal reports, or offline analysis
- Use HTML/Interactive reports when you need to explore data in detail, zoom into specific time ranges, or present findings interactively
Both formats can be generated from the same trace data, so you can create both for comprehensive analysis.
For deeper details on interpreting every metric, refer to the official documentation:
- GstShark Wiki: https://developer.ridgerun.com/wiki/index.php?title=GstShark
- GstShark GitHub: https://github.com/RidgeRun/gst-shark