Back to Canvas Lms

Flamegraphs

doc/flamegraphs.md

2026-05-20.1432.1 KB
Original Source

Flamegraphs

TL;DR

Add the flamegraph=true&flamename=my-custom-name query params to any request, and view/download flamegraphs in your Canvas Files.

Why Flamegraphs?

Flamegraphs can help to identify performance bottlenecks in our Canvas Ruby code (it can help identify problems rooted in inefficient database queries AND problems rooted in too-much-processing-time-spent-in-ruby).

If you're not familiar with flamegraphs and don't know how to analyze them, I encourage you to take an hour or two researching the topic; it's not difficult to analyze a flamegraph file, and it can be immensely helpful in tracking down performance issues!

Generating an HTML Flamegraph File

Users with Site Admin access can have an interactive HTML flamegraph generated for them, for any request, and have it delivered to their Canvas Files. Site Admin users can also masquerade as any non-site-admin user and generate a flamegraph report (the resulting report will be in the Site Admin user's Canvas Files).

In order to generate a flamegraph for a given request, simply add the

text
flamegraph=true

query parameter to the request. That's it! It works for both HTML and JSON requests.

Viewing the Generated HTML Flamegraph File

Next, go to your Canvas files (/files) and notice there's a flamegraphs folder with your newly-generated flamegraph file is in there!

The format of the filename is: flamegraph-<controller>#<action>-<iso8601 timestamp>, but you can also pass the

text
flamename=my-kewl-stuff

query parameter, which will make the filename flamegraph-my-kewl-stuff-<controller>#<action>-<iso8601 timestamp>.

You can preview the file within Canvas and interact with it (try clicking things and using the search bar, it's interactive!). You can also download the HTML file and view it locally in your browser.

More Info

Flamegraphs are generated by the awesome ruby stackprof library. See app/services/flamegraphs/flamegraph_service.rb for implementation details.

See git show b860ae73 for the commit that added this functionality.

If you have any questions, feel free to reach out to @solson in Slack.