Skip to content

Commit 149a704

Browse files
committed
Updated README instructions
1 parent d7d953f commit 149a704

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

allocations/README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
Sample to show allocations in Java Flight Recording
2-
=================================================
2+
===================================================
33

44
This program checks whether a number is prime.
55

6-
Run the program without any arguments and also make a profiling recording.
6+
Run the program and also make a profiling recording.
77

8-
For example:
9-
`java -Xms64m -Xmx64m -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,duration=30s,name=Allocations,filename=allocations.jfr -XX:FlightRecorderOptions=loglevel=info -jar target/allocations.jar`
8+
### How to run
9+
`java -Xms64m -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,duration=30s,name=Allocations,filename=allocations.jfr -XX:FlightRecorderOptions=loglevel=info -jar target/allocations.jar`
10+
11+
### Analyzing Java Flight Recording
1012

1113
In Memory -> Allocation tab, you should see a high allocation rate.
1214

13-
Also see Memory -> Garbage Collections tab and check the frequency of
15+
Also see Memory -> Garbage Collections tab and check the frequency of GC events.
1416

15-
Try the program again after changing `Long` types to primitive `long`
17+
### Improving Performance
1618

17-
Run the program without locks.
18-
`java -Xms64m -Xmx64m -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,duration=30s,name=Allocations,filename=allocations-fixed.jfr -XX:FlightRecorderOptions=loglevel=info -jar target/allocations.jar`
19+
Try the program again after changing `Long` types to primitive `long`

highcpu/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ Sample program consuming high CPU usage
33

44
A java program consuming high CPU usage. This program was inspired by a sample found in the article "[Identifying which Java Thread is consuming most CPU](http://code.nomad-labs.com/2010/11/18/identifying-which-java-thread-is-consuming-most-cpu/)"
55

6+
### How to run
7+
`java -Xms128m -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,duration=30s,name=HighCPU,filename=highcpu.jfr -XX:FlightRecorderOptions=loglevel=info -jar target/highcpu.jar`

hotmethods/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ Sample to show hot methods in Java Flight Recording
33

44
This program checks whether a given random number is primitive or not.
55

6-
Run the program without any arguments and also make a profiling recording.
6+
Run the program and also make a profiling recording.
77

8-
For example:
9-
`java -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,duration=60s,name=Hotmethods,filename=hotmethods.jfr -XX:FlightRecorderOptions=loglevel=info -jar target/hotmethods.jar`
8+
### How to run
9+
`java -Xms64m -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,duration=60s,name=Hotmethods,filename=hotmethods.jfr -XX:FlightRecorderOptions=loglevel=info -jar target/hotmethods.jar`
10+
11+
### Analyzing Java Flight Recording
1012

1113
In Code -> Hot Methods tab, you should see that the program has spent a lot of time in the LinkedList.indexOf(Object) method, which is called from contains method.
1214

15+
### Improving Performance
16+
1317
By changing LinkedList to a HashSet, you can make the program run a lot faster.
1418

1519
The contains methods in Linked List checks all the items. Algorithm run time is O(n). However the HashSet contains algorithm's run time is O(1).
1620

1721
In the program, change `Collection<Integer> primeNumbers = new LinkedList<>()` to `Collection<Integer> primeNumbers = new HashSet<>()` to use a HashSet for Prime Numbers
1822

1923
Check the runtime using HashSet.
20-
`java -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,duration=60s,name=Hotmethods,filename=hotmethods-fixed.jfr -XX:FlightRecorderOptions=loglevel=info -jar target/hotmethods.jar`
2124

22-
Use `time` command in Linux to measure the time.
25+
Use `time` command in Linux to measure the time.

latencies/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ Sample to show latencies in Java Flight Recording
33

44
This program has two threads: Even and Odd to print Even and Odd numbers.
55

6-
Run the program without any arguments and also make a profiling recording.
6+
Run the program and also make a profiling recording.
77

8-
For example:
9-
`java -jar -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,duration=30s,name=Latencies,filename=latencies.jfr -XX:FlightRecorderOptions=loglevel=info target/latencies.jar`
8+
### How to run
9+
`java -Xms64m -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,duration=30s,name=Latencies,filename=latencies.jfr -XX:FlightRecorderOptions=loglevel=info -jar target/latencies.jar`
10+
11+
### Analyzing Java Flight Recording
1012

1113
In Threads -> Latencies tab, you should see that the program has many blocked events.
1214

1315
You should also see red blocks in Events -> Graph tab. Red blocks are not good as the thread is just waiting to acquire a lock.
1416

1517
See Threads -> Contention tab to see the Locks and also see Threads -> Lock Instances to check whether both threads share the same lock instances.
1618

17-
Since there is no shared resource, you can avoid the lock and improve the performance.
19+
### Improving Performance
1820

19-
Remove the `synchronized` keyword in `isEven` method.
21+
Since there is no shared resource to protect, you can avoid the synchronized keyword and improve the performance.
2022

21-
Run the program without locks.
22-
`java -jar -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,duration=30s,name=Latencies,filename=latencies-fixed.jfr -XX:FlightRecorderOptions=loglevel=info target/latencies.jar`
23+
Try the program again after removing the `synchronized` keyword in `isEven` method.

0 commit comments

Comments
 (0)