Skip to content

Add Flamegraph HTML to Uploaded Profile Data#1022

Open
artursarlo wants to merge 1 commit intodynamic_profilingfrom
dynamic_profiling_ad_hoc
Open

Add Flamegraph HTML to Uploaded Profile Data#1022
artursarlo wants to merge 1 commit intodynamic_profilingfrom
dynamic_profiling_ad_hoc

Conversation

@artursarlo
Copy link

@artursarlo artursarlo commented Mar 11, 2026

Add Flamegraph HTML to Uploaded Profile Data

Summary

Includes the flamegraph HTML as a field (flamegraph_html) inside the profile metadata that is uploaded with each snapshot. This allows consumers of the uploaded data to render the flamegraph directly from the profile payload without regenerating it client-side.

Additionally, the flamegraph template has been updated to be fully responsive.


Changes

gprofiler/merge.py

  • Added flamegraph_html: Optional[str] as a parameter to _make_profile_metadata, concatenate_profiles, and merge_profiles.
  • The value is threaded through to the serialized profile metadata JSON comment (# {...}) under the key "flamegraph_html".
  • Defaults to None in the public-facing functions to preserve backward compatibility.

gprofiler/main.py

  • Extracted _generate_flamegraph_html() method: Splits flamegraph generation logic out of _generate_output_files() into a standalone method that accepts stripped collapsed stack data and start/end times, returning the rendered HTML string or None on failure (with a warning log).
  • Refactored _generate_output_files(): Now delegates to _generate_flamegraph_html() instead of inlining the generation logic.
  • Pre-generation in _snapshot(): Before producing the final merged result, a temporary merge is performed using the same NoopProfiler/perf branching logic to obtain the full collapsed stacks. The flamegraph HTML is generated from this temporary result and passed to the final concatenate_profiles / merge_profiles calls via the new flamegraph_html parameter.

gprofiler/resources/flamegraph/flamegraph_template.html

  • Made the flamegraph chart responsive: chart width is now computed dynamically as max(1400, window.innerWidth * 0.98) instead of a fixed 960px.
  • Added a resize event listener to reflow the chart on window resize.
  • Updated container layout: max-width/width set to 99%, reduced horizontal padding, added margin: 0 to body.

Motivation

The intel_dynamic_profiling ad-hoc flow uploads snapshots to a backend. Previously, the flamegraph was only written to disk when --flamegraph was enabled; the uploaded metadata had no HTML representation of the call stacks. This change embeds the pre-rendered HTML in the upload payload so the backend can surface the flamegraph without any additional processing.


Testing

  • When --flamegraph is enabled, the uploaded profile's metadata JSON will contain a flamegraph_html key with the full HTML string.
  • When --flamegraph is disabled or flamegraph generation fails, flamegraph_html is null in the metadata.
  • Existing output file behavior (.col and .html files written to --output-dir) is unchanged.

@artursarlo artursarlo changed the title Add ad hoc flamegraph report as part of the uploaded data Add Flamegraph HTML to Uploaded Profile Data Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant