Comprehensive guide to all features developed in the CallFlow Tracer package.
π Table of Contents
- Core Features
- Visualization Features
- Profiling Features
- Flamegraph Features
- Jupyter Integration
- Export Features
- UI/UX Features
- Recent Fixes
Core Features
1. Function Call Tracing
Description: Automatically trace function calls and build a call graph.
Methods:
@tracedecoratortrace_scope()context manager
Features:
- β Automatic call detection
- β Hierarchical relationship tracking
- β Timing information
- β Call count tracking
- β Argument capture (truncated for privacy)
- β Module information
- β Thread-safe operation
Example:
from callflow_tracer import trace_scope
with trace_scope() as graph:
my_application()
print(f"Traced {len(graph.nodes)} functions")
print(f"Found {len(graph.edges)} call relationships")
Use Cases:
- Understanding code flow
- Debugging complex applications
- Documenting function relationships
- Finding unused code paths
2. Call Graph Analysis
Description: Programmatic access to call graph data.
Features:
- β Node iteration
- β Edge traversal
- β Metadata access
- β Performance metrics
- β Call hierarchy analysis
Example:
with trace_scope() as graph:
my_function()
# Analyze nodes
for node in graph.nodes.values():
print(f"{node.full_name}:")
print(f" Calls: {node.call_count}")
print(f" Total time: {node.total_time:.4f}s")
print(f" Avg time: {node.avg_time:.4f}s")
# Find bottlenecks
bottlenecks = [n for n in graph.nodes.values() if n.avg_time > 0.1]
print(f"Found {len(bottlenecks)} slow functions")
Use Cases:
- Performance analysis
- Automated testing
- Code quality metrics
- Dependency analysis
Visualization Features
1. Interactive Call Graph
Description: Beautiful HTML visualization of function calls.
Features:
- β Interactive network diagram
- β Zoom and pan
- β Node hover tooltips
- β Edge highlighting
- β Performance-based coloring
- β Responsive design
Color Coding:
- π΄ Red: Slow functions (>100ms)
- π’ Teal: Medium functions (10-100ms)
- π΅ Blue: Fast functions (<10ms)
Example:
from callflow_tracer import trace_scope, export_html
with trace_scope() as graph:
my_application()
export_html(graph, "callgraph.html", title="My App Call Graph")
Use Cases:
- Visual code exploration
- Presentation and documentation
- Team collaboration
- Code reviews
2. Multiple Layout Options
Description: Different ways to visualize the call graph.
Layouts:
Hierarchical
- Top-down tree structure
- Clear parent-child relationships
- Best for: Understanding call flow
Force-Directed
- Physics-based layout
- Natural clustering
- Best for: Exploring relationships
Circular
- Functions arranged in a circle
- Equal spacing
- Best for: Seeing all functions at once
Timeline
- Horizontal arrangement by execution time
- Fastest to slowest
- Best for: Performance comparison
Example:
export_html(graph, "hierarchical.html", layout="hierarchical")
export_html(graph, "force.html", layout="force")
export_html(graph, "circular.html", layout="circular")
export_html(graph, "timeline.html", layout="timeline")
Use Cases:
- Different analysis perspectives
- Finding patterns
- Presentation variety
3. Module Filtering
Description: Filter the graph by Python module.
Features:
- β Dropdown selection
- β Dynamic filtering
- β Edge filtering (only show connections between visible nodes)
- β Smooth zoom animation
- β βAll Modulesβ option
- β βMain Moduleβ grouping
How It Works:
- Open HTML file
- Use βFilter by Moduleβ dropdown
- Select a module
- Graph automatically filters and zooms
Use Cases:
- Focus on specific modules
- Isolate subsystems
- Reduce visual clutter
- Module-level analysis
Profiling Features
1. CPU Profiling (cProfile Integration)
Description: Detailed CPU performance profiling.
Features:
- β Execution time tracking
- β Function call counts
- β Cumulative time
- β Per-call time
- β Hot spot identification
- β FIXED: Now shows actual times (not 0.000s!)
Metrics Captured:
- Total execution time
- Number of function calls
- Time per call
- Cumulative time
- Hot spots (slowest functions)
Example:
from callflow_tracer import profile_section
with profile_section("My Code") as stats:
expensive_function()
# Access CPU stats
cpu_stats = stats._get_cpu_stats()
print(cpu_stats['profile_data'])
Use Cases:
- Finding CPU bottlenecks
- Optimization targets
- Performance regression testing
- Profiling production code
2. Memory Profiling
Description: Track memory usage during execution.
Features:
- β Current memory usage
- β Peak memory usage
- β Memory snapshots
- β Per-function tracking
- β tracemalloc integration
Metrics Captured:
- Current memory (MB)
- Peak memory (MB)
- Memory allocations
- Memory by function
Example:
from callflow_tracer import profile_function, get_memory_usage
@profile_function
def memory_intensive():
data = [i for i in range(1000000)]
return data
result = memory_intensive()
stats = memory_intensive.performance_stats
mem_stats = stats._get_memory_stats()
print(f"Current: {mem_stats['current_mb']:.2f}MB")
print(f"Peak: {mem_stats['peak_mb']:.2f}MB")
Use Cases:
- Memory leak detection
- Optimization
- Resource planning
- Memory profiling
3. I/O Wait Time Tracking
Description: Measure time spent waiting for I/O operations.
Features:
- β Automatic detection
- β Separate from CPU time
- β Per-section tracking
- β Accurate measurement
How It Works:
- Compares wall clock time vs CPU time
- Difference = I/O wait time
Example:
from callflow_tracer import profile_section
import time
with profile_section("I/O Operations") as stats:
time.sleep(0.1) # Simulates I/O
compute() # CPU work
stats_dict = stats.to_dict()
print(f"I/O wait: {stats_dict['io_wait']:.4f}s")
Use Cases:
- Identifying I/O bottlenecks
- Database query optimization
- Network call analysis
- File I/O optimization
4. Combined Profiling
Description: Combine all profiling metrics.
Features:
- β CPU + Memory + I/O in one
- β Integrated with call graph
- β Export to HTML
- β Visual indicators
Example:
from callflow_tracer import trace_scope, profile_section, export_html
with profile_section("Complete Analysis") as perf_stats:
with trace_scope() as graph:
my_application()
# Export with all profiling data
export_html(
graph,
"complete_analysis.html",
profiling_stats=perf_stats.to_dict()
)
Use Cases:
- Comprehensive performance analysis
- Before/after optimization comparison
- Production profiling
- Performance reports
Flamegraph Features
1. Basic Flamegraph
Description: Stacked bar chart showing call hierarchy and time.
Features:
- β Width = time spent
- β Height = call depth
- β Interactive zoom
- β Hover tooltips
- β D3.js powered
Example:
from callflow_tracer import trace_scope
from callflow_tracer.flamegraph import generate_flamegraph
with trace_scope() as graph:
my_application()
generate_flamegraph(graph, "flamegraph.html")
Use Cases:
- Finding bottlenecks
- Understanding call patterns
- Performance optimization
- Visual profiling
2. Enhanced Flamegraph (NEW!)
Description: Advanced flamegraph with statistics and search.
Features:
- β Statistics Panel: Key metrics at a glance
- β Search Functionality: Find functions quickly
- β 5 Color Schemes: Choose the best view
- β SVG Export: High-quality graphics
- β Modern UI: Responsive and beautiful
- β Optimization Tips: Built-in guidance
Statistics Panel Shows:
- Total functions
- Total calls
- Total execution time
- Average time per call
- Call depth
- π₯ Slowest function (bottleneck!)
- π Most called function
Example:
generate_flamegraph(
graph,
"enhanced.html",
title="Performance Analysis",
color_scheme="performance", # Green=fast, Red=slow
show_stats=True,
search_enabled=True,
min_width=0.1,
width=1600,
height=1000
)
Use Cases:
- Advanced performance analysis
- Finding specific functions
- Presentation-ready graphics
- Detailed optimization
3. Color Schemes
Description: 5 different color schemes for different needs.
Available Schemes:
Default
- Red-Yellow-Green gradient
- Balanced view
- Good for general analysis
Hot π₯
- Red-Orange colors
- Emphasizes hot spots
- Best for: Highlighting slow areas
Cool βοΈ
- Blue-Green colors
- Easy on eyes
- Best for: Long analysis sessions
Rainbow π
- Full spectrum
- Distinguishes many functions
- Best for: Visual appeal
Performance β‘ (RECOMMENDED!)
- Green = Fast functions
- Yellow = Medium functions
- Red = Slow functions (bottlenecks!)
- Best for: Finding optimization targets
Example:
# Try each scheme
for scheme in ['default', 'hot', 'cool', 'rainbow', 'performance']:
generate_flamegraph(
graph,
f"flamegraph_{scheme}.html",
color_scheme=scheme
)
Use Cases:
- Different analysis needs
- Presentation variety
- Personal preference
- Accessibility
4. Search Functionality
Description: Find specific functions in large flamegraphs.
Features:
- β Real-time search box
- β Highlights matching functions
- β Case-insensitive
- β Clear button
- β Enter key support
How to Use:
- Open flamegraph HTML
- Type function name in search box
- Press Enter or wait
- Matching functions highlighted
- Click βClearβ to reset
Example:
generate_flamegraph(
graph,
"searchable.html",
search_enabled=True
)
# Then search for: "database", "api", "process", etc.
Use Cases:
- Finding specific functions
- Locating bottlenecks
- Navigating large graphs
- Quick analysis
5. SVG Export
Description: Export flamegraph as high-quality vector graphics.
Features:
- β Scalable vector format
- β No quality loss
- β Perfect for presentations
- β Preserves all colors
- β One-click export
How to Use:
- Open flamegraph HTML
- Click βπΎ Export SVGβ button
- File downloads automatically
- Use in presentations/reports
Use Cases:
- Presentations
- Documentation
- Reports
- Publications
Jupyter Integration
1. Magic Commands
Description: IPython magic commands for quick tracing.
Commands:
%callflow_trace (Line Magic)
Trace a single line of code.
%callflow_trace my_function()
%%callflow_cell_trace (Cell Magic)
Trace an entire cell.
%%callflow_cell_trace
def my_function():
return 42
result = my_function()
print(result)
Use Cases:
- Quick experiments
- Interactive analysis
- Notebook workflows
- Teaching and demos
2. Inline Visualization
Description: Display interactive graphs directly in notebooks.
Features:
- β Renders inline
- β Full interactivity
- β Custom dimensions
- β Layout options
- β No external files needed
Example:
from callflow_tracer import trace_scope
from callflow_tracer.jupyter import display_callgraph
with trace_scope() as graph:
my_function()
# Display inline
display_callgraph(
graph.to_dict(),
width="100%",
height="800px",
layout="force"
)
Use Cases:
- Interactive analysis
- Jupyter workflows
- Teaching
- Presentations
3. Full Feature Support
Description: All features work in Jupyter.
Supported:
- β Tracing
- β Profiling
- β Flamegraphs
- β Call graphs
- β Export
- β All visualizations
Example:
# Complete workflow in Jupyter
with profile_section("Analysis") as stats:
with trace_scope() as graph:
ml_pipeline()
# Display graph
display_callgraph(graph.to_dict())
# Show stats
print(stats.to_dict())
# Export
export_html(graph, "analysis.html", profiling_stats=stats.to_dict())
generate_flamegraph(graph, "flamegraph.html", color_scheme="performance")
Use Cases:
- Data science workflows
- ML pipeline analysis
- Interactive development
- Research and education
Export Features
1. HTML Export
Description: Export to interactive HTML files.
Features:
- β Self-contained files
- β No dependencies
- β Works offline (with CDN fallback)
- β Custom titles
- β Layout options
- β Profiling data integration
Options:
export_html(
graph,
"output.html",
title="Custom Title",
layout="hierarchical", # or 'force', 'circular', 'timeline'
profiling_stats=stats_dict
)
Generated Files Include:
- Interactive network visualization
- Control panel
- Statistics
- CPU profile section
- Module filter
- Layout controls
- Export buttons
Use Cases:
- Sharing analysis
- Documentation
- Reports
- Presentations
2. JSON Export
Description: Export graph data as JSON.
Features:
- β Structured format
- β Complete metadata
- β Timestamp
- β Version info
- β Easy to parse
Format:
{
"metadata": {
"total_nodes": 10,
"total_edges": 15,
"duration": 1.234,
"export_timestamp": "2025-10-05T...",
"version": "callflow-tracer",
"title": "My Graph"
},
"nodes": [...],
"edges": [...]
}
Example:
from callflow_tracer import export_json
export_json(graph, "trace.json")
# Load and analyze
import json
with open("trace.json") as f:
data = json.load(f)
print(f"Nodes: {data['metadata']['total_nodes']}")
Use Cases:
- Programmatic analysis
- Data processing
- Integration with other tools
- Automated testing
3. SVG Export (Flamegraph)
Description: Export flamegraphs as vector graphics.
Features:
- β Scalable
- β High quality
- β Preserves colors
- β Perfect for print
- β One-click export
Use Cases:
- Presentations
- Publications
- Documentation
- High-quality reports
UI/UX Features
1. Modern Design
Features:
- β Gradient backgrounds
- β Smooth animations
- β Hover effects
- β Professional look
- β Responsive layout
Elements:
- Beautiful headers
- Card-based layouts
- Color-coded metrics
- Interactive buttons
- Smooth transitions
2. Responsive Design
Features:
- β Works on all screen sizes
- β Mobile-friendly
- β Tablet-optimized
- β Desktop-enhanced
- β Adaptive layouts
Breakpoints:
- Mobile: < 768px
- Tablet: 768px - 1024px
- Desktop: > 1024px
3. Interactive Controls
Features:
- β Zoom controls
- β Layout switcher
- β Module filter
- β Search box
- β Export buttons
- β Color scheme selector
All Controls:
- Zoom to Fit
- Reset Zoom
- Change Layout
- Filter Module
- Search Functions
- Export SVG/PNG/JSON
- Toggle Physics
- Change Colors
4. Rich Tooltips
Features:
- β Detailed information
- β Performance metrics
- β Percentage of total
- β Call counts
- β Timing data
Tooltip Shows:
- Function name
- Total time
- Average time
- Call count
- Percentage of total time
- Module information
Recent Fixes
1. CPU Profiling Fix
Problem: CPU profile always showed 0.000s execution time.
Solution:
- Created snapshot of pstats.Stats object
- Store before profiler stops
- Now shows actual execution times
Impact: β Working CPU profiling with accurate data
2. Module Filter Fix
Problem: Module filter dropdown had no functionality.
Solution:
- Added event listener
- Implemented node/edge filtering
- Added smooth zoom animation
Impact: β Working module filtering
3. Layout Fixes
Problem: Circular and Timeline layouts didnβt work.
Solution:
- Fixed node positioning
- Added proper physics settings
- Implemented auto-fit
Impact: β All 4 layouts working correctly
4. JSON Export Fix
Problem: βnetwork.getData is not a functionβ error.
Solution:
- Use original nodes/edges arrays
- Added better error handling
- Enhanced metadata
Impact: β Working JSON export
5. Tracer Stability Fix
Problem: Programs stopped executing after first few print statements.
Solution:
- Enhanced error handling in _trace_calls
- Fixed decorator/scope conflicts
- Improved global state management
Impact: β Stable tracing, programs run to completion
Feature Matrix
| Feature | Status | Version |
|---|---|---|
| Call Tracing | β | 0.1.0 |
| Call Graph Viz | β | 0.1.0 |
| JSON Export | β Fixed | 0.2.2 |
| HTML Export | β | 0.1.0 |
| CPU Profiling | β Fixed | Latest |
| Memory Profiling | β | 0.2.0 |
| I/O Tracking | β | 0.2.0 |
| Flamegraph | β | 0.2.0 |
| Enhanced Flamegraph | β New! | Latest |
| Statistics Panel | β New! | Latest |
| Search | β New! | Latest |
| 5 Color Schemes | β New! | Latest |
| SVG Export | β New! | Latest |
| Module Filter | β Fixed | Latest |
| All Layouts | β Fixed | Latest |
| Jupyter Integration | β New! | Latest |
| Magic Commands | β New! | Latest |
| Inline Display | β New! | Latest |
| Modern UI | β New! | Latest |
| Responsive Design | β New! | Latest |
Summary
CallFlow Tracer now includes:
β Core Features
- Function call tracing
- Call graph analysis
- Thread-safe operation
β Visualization
- Interactive call graphs
- 4 layout options
- Module filtering
- Rich tooltips
β Profiling
- CPU profiling (fixed!)
- Memory tracking
- I/O wait time
- Combined metrics
β Flamegraphs
- Basic flamegraphs
- Enhanced with statistics
- 5 color schemes
- Search functionality
- SVG export
β Jupyter
- Magic commands
- Inline display
- Full feature support
β Export
- HTML (interactive)
- JSON (structured)
- SVG (vector graphics)
β UI/UX
- Modern design
- Responsive layout
- Interactive controls
- Professional look
Features Documentation - Last Updated: 2025-10-05