Skip to content

Commit f46eadc

Browse files
authored
Update 3_agent.md
1 parent ded180c commit f46eadc

File tree

1 file changed

+19
-9
lines changed
  • content/learning-paths/servers-and-cloud-computing/java-perf-flamegraph

1 file changed

+19
-9
lines changed

content/learning-paths/servers-and-cloud-computing/java-perf-flamegraph/3_agent.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,41 @@ layout: learningpathall
88
---
99

1010
## Java Flame Graph Generation via Java agent and perf
11-
To profile a Java application with perf and ensure proper symbol resolution, you must include libperf-jvmti.so when launching the Java application.
12-
- libperf-jvmti.so is a JVM TI agent library enabling perf to resolve Java symbols, facilitating accurate profiling of Java applications.
13-
- A specialized shared library, libperf-jvmti.so bridges perf and the JVM, enabling proper translation of memory addresses to Java method names during profiling.
11+
To profile a Java application with perf and ensure proper symbol resolution, you must include `libperf-jvmti.so` when launching the Java application.
12+
- `libperf-jvmti.so` is a JVM TI agent library enabling perf to resolve Java symbols, facilitating accurate profiling of Java applications.
13+
- A specialized shared library, `libperf-jvmti.so` bridges perf and the JVM, enabling proper translation of memory addresses to Java method names during profiling.
1414

15-
1. Find and add libperf-jvmti.so to Java option
15+
1. Find where `libperf-jvmti.so` is installed on your Arm-based Linux server:
16+
```bash
17+
pushd /usr/lib
18+
find . -name libperf-jvmti.so`
19+
```
20+
The output will show the path of the library that you will then include in your Tomcat setup file:
1621
```bash
1722
vi apache-tomcat-11.0.9/bin/catalina.sh
18-
# add JAVA_OPTS="$JAVA_OPTS -agentpath:/usr/lib/linux-tools-6.8.0-63/libperf-jvmti.so -XX:+PreserveFramePointer"
23+
```
24+
Add JAVA_OPTS="$JAVA_OPTS -agentpath:/usr/lib/linux-tools-6.8.0-63/libperf-jvmti.so -XX:+PreserveFramePointer" to `catalina.sh`. Make sure the path matches the location on your machine from the previous step.
25+
26+
Now shutdown and restart Tomcat:
27+
```bash
1928
cd apache-tomcat-11.0.9/bin
2029
./shutdown.sh
2130
./startup.sh
2231
```
2332

24-
2. Use perf to profile Tomcat, and restart wrk if necessary
33+
2. Use perf to profile Tomcat, and restart wrk that running on your x86 instance if necessary:
2534
```bash
2635
sudo perf record -g -k1 -p $(jps | awk /Bootstrap/'{print $1}') -- sleep 10
2736
```
37+
This command will record the collected data in a file named `perf.data`
2838

29-
3. Convert the collected perf.data file into a Java flame graph using FlameGraph
39+
3. Convert the collected `perf.data` into a Java flame graph using FlameGraph
3040
```bash
3141
git clone https://github.com/brendangregg/FlameGraph.git
32-
export PATH=$PATH:/root/FlameGraph
42+
export PATH=$PATH:`pwd`/FlameGraph
3343
sudo perf inject -j -i perf.data | perf script | stackcollapse-perf.pl | flamegraph.pl &> profile.svg
3444
```
3545

36-
4. Launch profile.svg in a browser to analyse the profiling result
46+
4. You can now successfully launch `profile.svg` in a browser to analyse the profiling result
3747

3848
![example image alt-text#center](_images/lp-flamegraph-agent.png "Java Flame Graph via Java agent and perf")

0 commit comments

Comments
 (0)