Skip to content

Commit 02835dd

Browse files
committed
[GR-19691] Update documentation about flamegraphs
1 parent c37d6ae commit 02835dd

File tree

1 file changed

+8
-51
lines changed

1 file changed

+8
-51
lines changed

doc/contributor/profiling.md

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,22 @@ the most useful information from the tools, assuming basic knowledge of their us
1313

1414
### Creating a Flame Graph
1515

16-
#### The Easy Way
17-
18-
The easiest way to generate a flame graph from a profile is to accept the default profiling
19-
options configured in _jt_. In this case, simply run `jt profile` like you would `jt ruby`
20-
and your application or inline script will be profiled and an SVG written to your
21-
TruffleRuby source directory, named _profiles/flamegraph\_\<timestamp\>.svg_.
22-
23-
To make things even easier, `jt profile` will automatically open up the flame graph for
24-
you in whatever application you have configured as your default for SVG files. This is
25-
handled by the `open` command on macOS and the `xdg-open` command on Linux.
26-
27-
To illustrate, here's a command for profiling and inline script.
28-
29-
```bash
30-
jt profile -e "x = 'abc'; 100_000.times { x.upcase }"
31-
```
32-
33-
Here's a command for profiling the `gem list` command:
34-
16+
Use the [CPUSampler](https://www.graalvm.org/dev/tools/profiling/) ([blog post](https://medium.com/graalvm/where-has-all-my-run-time-gone-245f0ccde853)) in flamegraph mode, like this:
3517
```bash
36-
jt profile -S gem list
18+
ruby --cpusampler=flamegraph ...
3719
```
3820

39-
#### The Less Easy Way
21+
This will create a `flamegraph.svg`, which you can open in a web browser
22+
(Chromium-based browsers seem faster for rendering the flamegraph).
4023

41-
The histogram output from the Truffle profiler can be quite large, making it difficult to
42-
analyze. Additionally, as a flat format it isn't possible to analyze a call graph as that
43-
information simply isn't encoded in the output. A flame graph shows the entire call graph
44-
and its structure makes it considerably simpler to see where the application time is being
45-
spent.
46-
47-
Creating the flame graph is a multi-stage process. First, we need to profile the application
48-
with the JSON formatter:
4924

25+
There is also `jt profile` which does the same but uses a unique filename, prints the wall-clock time and open the SVG for you:
26+
Here are some examples:
5027
```bash
51-
jt ruby --cpusampler --cpusampler.Output=json -e 'p :hello' > simple-app.json
52-
```
53-
54-
The JSON profiler formatter encodes call graph information that isn't available in the
55-
histogram format. To make a flame graph out of this output, however, we need to transform
56-
it into a format that folds the call stack samples into single lines. This can be done
57-
using [stackcollapse-graalvm.rb](https://github.com/eregon/FlameGraph/blob/graalvm/stackcollapse-graalvm.rb)
58-
from Benoit's fork of FlameGraph.
59-
60-
If you haven't yet, you should clone Benoit's [fork of FlameGraph](https://github.com/eregon/FlameGraph/tree/graalvm)
61-
into TruffleRuby's parent directory. Now you can run the script to transform the output and
62-
pipe it into the script that will generate the SVG data:
63-
64-
```bash
65-
../FlameGraph/stackcollapse-graalvm.rb simple-app.json | ../FlameGraph/flamegraph.pl > simple-app.svg
28+
jt profile -e "x = 'abc'; 100_000.times { x.upcase }"
29+
jt profile -S gem list
6630
```
6731

68-
At this point, you should open the SVG file in a Chromium-based web browser. Your system
69-
might have a different image manipulation application configured as the default application
70-
for SVG files. While loading the file in such an application make render a graph, it likely
71-
will not handle the interactive components of the flame graph. Firefox may work as well,
72-
but Chromium-based browsers seem to have better support and performance for the flame graph
73-
files as of this writing (Dec. 2018).
74-
7532
### Require Profiling
7633
The `--metrics-profile-require` option can be used to profile the time used for searching, parsing, translating and loading files during require.
7734

0 commit comments

Comments
 (0)