You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/contributor/profiling.md
+8-51Lines changed: 8 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,65 +13,22 @@ the most useful information from the tools, assuming basic knowledge of their us
13
13
14
14
### Creating a Flame Graph
15
15
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:
35
17
```bash
36
-
jt profile -S gem list
18
+
ruby --cpusampler=flamegraph ...
37
19
```
38
20
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).
40
23
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:
49
24
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:
50
27
```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:
0 commit comments