Ad hoc profiling mode with Pyroscope
This post was originally published on pyroscope.io. Grafana Labs acquired Pyroscope in 2023.
While most profilers are built for more static or ad hoc analysis (i.e., profiling a script), Pyroscope’s continuous profiling gives you the opportunity to jump around to any point in time. This fluid profiling is beneficial for understanding performance issues in your application. However, as we continued to improve on Pyroscope UI/UX, we identified ideal situations to use static profiling instead of running a profiler continuously, including profiling scripts and attaching a running process.
Our goal is to make Pyroscope a one-stop-shop for all profiling needs. That means supporting all languages, all flame graph formats, continuously profiling servers, and, of course, quickly profiling an ad hoc script.
What is ad hoc profiling?
That being said, we are excited to officially release ad hoc profiling mode for Pyroscope! With ad hoc mode, you get all the convenience and simplicity of profiling a script, as well as Pyroscope’s stellar visualization and UI functionality.
How to export interactive Flame graph HTML from Pyroscope ad hoc mode
You can use the pyroscope adhoc
command to profile a script and export the HTML file for an interactive profile that you can view, play with, and share with your team.
For example, to profile a Golang script you simply run:
pyroscope adhoc go run adhoc-push.go
which will produce a folder containing an .html
file with an interactive flame graph for each of the pprof profiles.
This command will profile the file passed in and then export an HTML file that looks like the Pyroscope UI, but it is exported as a simple standalone HTML file:
Note: This HTML export can also be achieved through the file exported dropdown available in the flame graph toolbar of your continuous profiling flame graphs:
This is the simplest way to use Pyroscope adhoc mode. The new feature is great for quickly viewing and sharing profiles in a format with more functionality than a simple screenshot.
Analyzing ad hoc flame graphs with Pyroscope
HTML file export allows you to easily share profiles with other people. Pyroscope also permanently stores all of your profiles in the ~/.pyroscope/
directory so you can revisit or compare profiles. In order to do that, run: Pyroscope stores data in the ~/.pyroscope/
directory. If you run:
pyroscope server
And go to port :4040
to access the flame graphs you have created via the pyroscope adhoc
command.
Viewing flame graph diffs between two ad hoc profiles
Similar to how we have the diff view for continuous profiling, ad hoc also supports calculating the diff between two flamegraphs. This functionality requires server-side code, so it is only available for files saved in the ~/.pyroscope
directory. We plan to improve this over time, or potentially even compile these functions to WASM.
Coming soon!
As of January 26, 2022, ad hoc mode is meant for three main use cases:
- Profiling scripts using Pyroscope: Running
pyroscope adhoc
command and being able to view/share the resulting flame graphs. - Viewing profiles exported from Pyroscope: Dragging and dropping files that have been exported to
json
format and then analyzing those flamegraphs. - Getting a shareable standalone HTML flame graph that has the same UI and analysis features as Pyroscope web interface.
We plan to expand functionality and support more languages, formats and use cases:
- Supporting drag-and-drop for pprof files
- Adding ability to comment on stored files
- Adding descriptions / annotations to flame graphs
- Getting a shareable link to flame graphs
- UI improvements
- And much more!
Let us know if you have any recommendations for how to improve ad hoc mode!
Follow us on Github for updates!