Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 1.23 KB

PROFILING.md

File metadata and controls

24 lines (20 loc) · 1.23 KB

Profiling Java Code

For Java, we will be using VisualVM to profile the code. VisualVM is a lightweight profiling tool that used to be packaged with JDK until JDK 9. Therefore, it would be better to download the latest version to benefit from the new features.

To profile your code, follow the below steps:

  1. Make sure to enable the benchmark test case in BenchmarkTest.java

  2. Download VisualVM

  3. Start VisualVM by running the following command:

    visualvm\bin\visualvm.exe --jdkhome "<path to JDK>"

  4. Run your benchmark test:

    1. Gradle: ./gradlew clean test --tests BenchmarkTest
    2. Maven: ./mvnw clean test -Dtest=BenchmarkTest
  5. From VisualVM:

    1. Expand the Local group under the Applications window
    2. Right click on org.openjdk.jmh.runner.ForkedMain
    3. Select Sample , this should open a dedicated tab dedicated to this process
    4. Click on CPU button
    5. Under the CPU Samples tab, you should see a thread associated to the test or main class you are running.
    6. Expand that thread and play analyze where most of the time is consumed
  6. Improve your code and redo steps 4 & 5