如何衡量Java应用程序的性能?

时间:2022-09-08 21:03:54

I have a CPU intensive multi-threaded Java application and I'm looking for ways to measure its performance at run time (useful for automation). I tried a few options

我有一个CPU密集型多线程Java应用程序,我正在寻找在运行时测量其性能的方法(对自动化很有用)。我试了几个选择

System.currentTimeMillis();
System.nanoTime();
ThreadMXBean.getThreadCPUTime();

The first two measure real time. The last measures CPU time for only one thread. I want to measure the CPU-time for all threads spawned by the process.

前两个测量实时。最后一个测量只有一个线程的CPU时间。我想测量进程生成的所有线程的CPU时间。

Before resurrecting an old machine and dedicate it for this task, I would like to see what options I have now.

在复活旧机器并将其专门用于此任务之前,我想看看我现在有哪些选择。

I run Linux and a platform dependent solution is acceptable, but least desirable.

我运行Linux并且平台相关的解决方案是可以接受的,但最不可取。

2 个解决方案

#1


11  

Try perf4j: http://perf4j.codehaus.org/ I recommend using it along with AOP, but it's not a must. See http://perf4j.codehaus.org/devguide.html#Using_Spring_AOP_to_Integrate_Timing_Aspects for more details on AOP.

试试perf4j:http://perf4j.codehaus.org/我建议将它与AOP一起使用,但这不是必须的。有关AOP的更多详细信息,请参见http://perf4j.codehaus.org/devguide.html#Using_Spring_AOP_to_Integrate_Timing_Aspects。

#2


2  

Try to enable the JVM with Dtrace. It has a lot of performance probes which help you get what ever you want.

尝试使用Dtrace启用JVM。它有许多性能探测器,可以帮助您获得所需的任何内容。

#1


11  

Try perf4j: http://perf4j.codehaus.org/ I recommend using it along with AOP, but it's not a must. See http://perf4j.codehaus.org/devguide.html#Using_Spring_AOP_to_Integrate_Timing_Aspects for more details on AOP.

试试perf4j:http://perf4j.codehaus.org/我建议将它与AOP一起使用,但这不是必须的。有关AOP的更多详细信息,请参见http://perf4j.codehaus.org/devguide.html#Using_Spring_AOP_to_Integrate_Timing_Aspects。

#2


2  

Try to enable the JVM with Dtrace. It has a lot of performance probes which help you get what ever you want.

尝试使用Dtrace启用JVM。它有许多性能探测器,可以帮助您获得所需的任何内容。