1

I try to use wall clock time in intellij profiler instead of cpu time, and I change the config to wall according the post here. How to enable wall-clock profiling for Intellij Async Profiler? But it looks like doesnt' work. The following code is what I tested.

  private static void f1(long mills) {
    Random random = new Random();
    long start = System.currentTimeMillis();
    while ((System.currentTimeMillis() - start) < mills) {
      Math.pow(random.nextDouble(), random.nextDouble());
    }
  }

  private static void f2(long mills) {
    long start = System.currentTimeMillis();
    while ((System.currentTimeMillis() - start) < mills) {
      try {
        Thread.sleep(10);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }
  }

  public static void main(String[] args) throws IOException, InterruptedException {
      f1(10000);
      f2(10000);
  }

And the following is the screenshot of frame graph of intellij async profiler. You can see that f1 take the majority of cpu time, but in wall clock time perspective, f1 and f2 should be close. Anyone know what is the right way? Thanks

enter image description here

enter image description here

enter image description here

zjffdu
  • 25,496
  • 45
  • 109
  • 159

1 Answers1

0

From the answer you mention, you would still need to add the wall=event option on the "CPU profiler" section of "Java Profiler", while running your application with the 'Async Profiler':

https://blog.jetbrains.com/wp-content/uploads/2022/01/run-with-profiler.png

The article "Profiling Tutorial: Fixing the Parrot Party" shows CPU profiling, but I suspect the CPU-specific settings are still set on "CPU Profiler".

You can test that, when you start your application using the "Run with 'Async Profiler'" option, IntelliJ IDEA will use the agent options specified in the "CPU Profiler" section to configure the Async Profiler.

Or: CPU profiling is activated by default when using Async Profiler:

https://blog.jetbrains.com/wp-content/uploads/2022/01/open-report.png

And, right-clicking the necessary process in the Profiler tool window and select CPU and Memory Live Charts (from "CPU and memory live charts"):

https://resources.jetbrains.com/help/img/idea/2023.1/cpu-memory-live-charts.png


If it is still not working, check if the expected results are there outside IntelliJ, using async-profiler/async-profiler directly:

./profiler.sh -e wall -d <duration> -f <output_file> -i <interval> --title <title> <pid>

With:

  • <duration>: Duration of the profiling session in seconds.
  • <output_file>: The path and filename for the output file (e.g., output.html).
  • <interval>: Sampling interval in nanoseconds (e.g., 1000000 for 1ms).
  • <title>: Title for the output report. `: Process ID of the running Java application.

For example:

./profiler.sh -e wall -d 20 -f output.html -i 1000000 --title "Wall Clock Profiling" 12345

This command will profile the Java application with process ID 12345 for 20 seconds, using wall-clock time and a 1ms sampling interval, and generate an HTML report with the title "Wall Clock Profiling" in the file output.html.

Once the profiling session is complete, open the generated output file (output.html in this example) in a web browser to view the profiling results.
See if f1 and f2 are close then.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I make the configuration in java profiler as well, but it doesn't work. And I added more context in the post – zjffdu May 12 '23 at 03:07
  • @zjffdu I have edited the answer with a test to validate your approach. – VonC May 12 '23 at 13:46