nlsq.profiler_visualization module

Performance Profiling Visualization

Visualization and dashboard tools for NLSQ performance profiling data.

class nlsq.utils.profiler_visualization.ProfilerVisualization(profiler)[source]

Bases: object

Visualization tools for performance profiling data.

Examples

>>> from nlsq.utils.profiler import get_global_profiler
>>> from nlsq.utils.profiler_visualization import ProfilerVisualization
>>> profiler = get_global_profiler()
>>> viz = ProfilerVisualization(profiler)
>>> fig = viz.plot_timing_comparison(["test1", "test2"])
>>> viz.save_html_report("report.html")
__init__(profiler)[source]

Initialize visualization tools.

Parameters:

profiler (PerformanceProfiler) – Profiler instance to visualize

plot_timing_series(name='default', figsize=(10, 6))[source]

Plot timing metrics across runs.

Parameters:
  • name (str) – Profile name to visualize

  • figsize (tuple) – Figure size (width, height)

Returns:

fig – Matplotlib figure or None if matplotlib not available

Return type:

Figure or None

plot_timing_comparison(names, figsize=(10, 6))[source]

Compare timing metrics across multiple profiles.

Parameters:
  • names (list of str) – Profile names to compare

  • figsize (tuple) – Figure size (width, height)

Returns:

fig – Matplotlib figure or None if matplotlib not available

Return type:

Figure or None

plot_timing_distribution(name='default', figsize=(10, 6))[source]

Plot distribution of timing metrics.

Parameters:
  • name (str) – Profile name to visualize

  • figsize (tuple) – Figure size (width, height)

Returns:

fig – Matplotlib figure or None if matplotlib not available

Return type:

Figure or None

generate_html_report(output_path=None)[source]

Generate HTML report with all profiling data.

Parameters:

output_path (str or Path, optional) – Path to save HTML file. If None, returns HTML string.

Returns:

html – HTML report content

Return type:

str

export_json(output_path)[source]

Export profiling data to JSON.

Parameters:

output_path (str or Path) – Path to save JSON file

export_csv(name, output_path)[source]

Export profile data to CSV.

Parameters:
  • name (str) – Profile name to export

  • output_path (str or Path) – Path to save CSV file

class nlsq.utils.profiler_visualization.ProfilingDashboard(profiler)[source]

Bases: object

Interactive dashboard for profiling data.

Examples

>>> from nlsq.utils.profiler import get_global_profiler
>>> from nlsq.utils.profiler_visualization import ProfilingDashboard
>>> profiler = get_global_profiler()
>>> dashboard = ProfilingDashboard(profiler)
>>> dashboard.add_profile("test1")
>>> dashboard.add_profile("test2")
>>> dashboard.generate_comparison_report()
__init__(profiler)[source]

Initialize dashboard.

Parameters:

profiler (PerformanceProfiler) – Profiler instance to visualize

add_profile(name)[source]

Add a profile to track in the dashboard.

Parameters:

name (str) – Profile name to track

remove_profile(name)[source]

Remove a profile from tracking.

Parameters:

name (str) – Profile name to remove

generate_comparison_report()[source]

Generate comparison report for tracked profiles.

Returns:

report – Formatted comparison report

Return type:

str

plot_all_comparisons(figsize=(15, 10))[source]

Generate comprehensive comparison plots.

Parameters:

figsize (tuple) – Figure size (width, height)

Returns:

fig – Matplotlib figure or None if matplotlib not available

Return type:

Figure or None

save_dashboard(output_dir)[source]

Save complete dashboard to directory.

Parameters:

output_dir (str or Path) – Directory to save dashboard files

Overview

The profiler_visualization module provides visualization tools for profiling data.

Key Features

  • Flame graphs for call stack visualization

  • Timeline plots for execution traces

  • Memory usage plots over time

  • Interactive HTML reports

Functions

Example Usage

from nlsq.utils.profiler import Profiler
from nlsq.utils.profiler_visualization import plot_timeline, create_html_report

# Profile operations
profiler = Profiler(enable=True)
# ... run profiled code ...

# Visualize results
plot_timeline(profiler.get_results())

# Generate HTML report
create_html_report(profiler.get_results(), output_file="profile_report.html")

See Also