CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-gprof2dot

Generate a dot graph from the output of several profilers.

Pending
Overview
Eval results
Files

cli.mddocs/

Command Line Interface

Complete command-line interface with extensive options for format selection, threshold configuration, theming, and output control. The CLI provides access to all gprof2dot functionality through a comprehensive set of command-line arguments.

Capabilities

Main Entry Point

Primary command-line interface function that orchestrates the entire profiling workflow from input parsing to DOT output generation.

def main(argv=sys.argv[1:]):
    """
    Main entry point for command-line interface.
    
    Args:
        argv (list): Command line arguments (defaults to sys.argv[1:])
        
    Returns:
        int: Exit code (0 for success, non-zero for failure)
    """

Command Line Options

The CLI supports the following command-line options:

Input/Output Options

# Specify input file(s)
gprof2dot [file1] [file2] ...

# Specify output file (default: stdout)
gprof2dot -o output.dot input_profile
gprof2dot --output=output.dot input_profile

Format Selection

# Specify input format (default: prof)
gprof2dot -f FORMAT input_profile
gprof2dot --format=FORMAT input_profile

# Supported formats:
# axe, callgrind, collapse, dtrace, hprof, json,
# oprofile, perf, prof, pstats, sleepy, sysprof, xperf

Threshold Configuration

# Set node threshold (eliminate nodes below percentage, default: 0.5)
gprof2dot -n PERCENTAGE input_profile
gprof2dot --node-thres=PERCENTAGE input_profile

# Set edge threshold (eliminate edges below percentage, default: 0.1)  
gprof2dot -e PERCENTAGE input_profile
gprof2dot --edge-thres=PERCENTAGE input_profile

Visualization Options

# Select color theme (default: color)
gprof2dot -c THEME input_profile
gprof2dot --colormap=THEME input_profile

# Available themes: color, pink, gray, bw, print

# Strip function parameters and template arguments from C++ names
gprof2dot -s input_profile
gprof2dot --strip input_profile

Advanced Options

# Set total time calculation method (for perf format)
gprof2dot --total=METHOD input_profile

# Methods: callratios (default), callstacks

# Control function name stripping
gprof2dot --strip input_profile

# Wrap long lines in labels
gprof2dot -w input_profile
gprof2dot --wrap input_profile

# Specify node labeling
gprof2dot -l LABELS input_profile  
gprof2dot --labels=LABELS input_profile

Help and Information

# Show help message
gprof2dot -h
gprof2dot --help

# Show version information
gprof2dot --version

Command Line Usage Examples

Basic Usage

# Parse Python pstats and output DOT to stdout
gprof2dot -f pstats profile.stats

# Parse Valgrind callgrind output
gprof2dot -f callgrind callgrind.out.1234

# Parse and save to file
gprof2dot -f perf -o profile.dot perf_output.txt

Complete Pipeline Examples

# Python profiling pipeline
python -m cProfile -o profile.stats my_script.py
gprof2dot -f pstats profile.stats | dot -Tpng -o profile.png

# Valgrind callgrind pipeline  
valgrind --tool=callgrind ./my_program
gprof2dot -f callgrind callgrind.out.* | dot -Tsvg -o profile.svg

# Linux perf pipeline
perf record -g ./my_program
perf script | gprof2dot -f perf | dot -Tpdf -o profile.pdf

Threshold and Filtering

# Show only significant nodes and edges
gprof2dot -f pstats -n 2.0 -e 1.0 profile.stats

# Very detailed view (low thresholds)
gprof2dot -f callgrind -n 0.1 -e 0.05 callgrind.out

# High-level overview (high thresholds)  
gprof2dot -f perf -n 5.0 -e 2.0 perf.out

Theme and Visualization Options

# Use different color themes
gprof2dot -f pstats -c pink profile.stats
gprof2dot -f pstats -c gray profile.stats  
gprof2dot -f pstats -c bw profile.stats
gprof2dot -f pstats -c print profile.stats

# Strip function name decorations
gprof2dot -f pstats -s profile.stats      # Strip C++ decorations

Advanced Processing

# Perf with callstacks method
gprof2dot -f perf --total=callstacks perf.out

# Custom labeling
gprof2dot -f pstats -l "name,total_time" profile.stats

# Wrap long function names  
gprof2dot -f callgrind -w callgrind.out

# Strip common prefixes from function names
gprof2dot -f hprof --strip java_profile.hprof

Multiple Input Files

# Process multiple profile files
gprof2dot -f pstats profile1.stats profile2.stats profile3.stats

# Combine different profiler outputs (if compatible)
gprof2dot -f json profile1.json profile2.json

Output Format Integration

# Generate PNG with custom DPI
gprof2dot -f pstats profile.stats | dot -Tpng -Gdpi=300 -o profile.png

# Generate interactive SVG
gprof2dot -f callgrind callgrind.out | dot -Tsvg -o profile.svg

# Generate PostScript for printing
gprof2dot -f perf -c print perf.out | dot -Tps -o profile.ps

# Generate PDF with specific page size
gprof2dot -f pstats profile.stats | dot -Tpdf -Gsize="11,8.5" -o profile.pdf

Integration Examples

Shell Script Integration

#!/bin/bash
# Profile analysis script

PROFILE_FILE="$1"
FORMAT="$2"
OUTPUT_DIR="${3:-./profiles}"

mkdir -p "$OUTPUT_DIR"

# Generate multiple formats
gprof2dot -f "$FORMAT" "$PROFILE_FILE" | dot -Tpng -o "$OUTPUT_DIR/profile.png"
gprof2dot -f "$FORMAT" "$PROFILE_FILE" | dot -Tsvg -o "$OUTPUT_DIR/profile.svg"  
gprof2dot -f "$FORMAT" -c print "$PROFILE_FILE" | dot -Tpdf -o "$OUTPUT_DIR/profile.pdf"

echo "Profiles generated in $OUTPUT_DIR"

Python Script Integration

#!/usr/bin/env python3
import subprocess
import sys
import os

def generate_profile_visualization(input_file, format_type, output_base):
    """Generate profile visualization using gprof2dot."""
    
    # Generate DOT
    cmd = ['gprof2dot', '-f', format_type, input_file]
    dot_output = subprocess.check_output(cmd, text=True)
    
    # Save DOT file
    with open(f"{output_base}.dot", 'w') as f:
        f.write(dot_output)
    
    # Generate PNG
    subprocess.run([
        'dot', '-Tpng', '-o', f"{output_base}.png", f"{output_base}.dot"
    ])
    
    print(f"Generated {output_base}.png and {output_base}.dot")

if __name__ == "__main__":
    if len(sys.argv) != 4:
        print("Usage: script.py <input_file> <format> <output_base>")
        sys.exit(1)
    
    generate_profile_visualization(sys.argv[1], sys.argv[2], sys.argv[3])

Makefile Integration

# Profile visualization targets
PROFILE_FORMATS = png svg pdf
GPROF2DOT_OPTS = -n 1.0 -e 0.5

profile.dot: profile.stats  
	gprof2dot -f pstats $(GPROF2DOT_OPTS) $< > $@

%.png: %.dot
	dot -Tpng -o $@ $<

%.svg: %.dot  
	dot -Tsvg -o $@ $<

%.pdf: %.dot
	dot -Tpdf -o $@ $<

profile-all: $(addprefix profile., $(PROFILE_FORMATS))

clean-profiles:
	rm -f profile.dot profile.png profile.svg profile.pdf

.PHONY: profile-all clean-profiles

Install with Tessl CLI

npx tessl i tessl/pypi-gprof2dot

docs

cli.md

index.md

parsers.md

profile-model.md

visualization.md

tile.json