如何查看执行过程中Java程序中每个方法所花费的时间 [英] How to see time taken by each method in Java program during execution
问题描述
我正在尝试查找Java程序在执行时调用每种方法所花费的时间.我不想用System.currentTimeMillis()
乱扔我的代码.也许像探查器或IDE插件之类的东西,但是我不确定这是否叫它.有人可以通过指示我正确的方向来帮助我吗?
I am trying to find the time taken by each method that my Java program calls, while executing. I do not want to litter my code with System.currentTimeMillis()
. Maybe, something like a profiler or an IDE plugin, but I am not sure if that is what it is called. Can someone help me by pointing me in the right direction?
示例代码:
public static void main(String[] args){
Obj A = new Obj();
ObjDiff B = new ObjDiff();
A.callMe();
B.callMeToo();
}
工具/框架:
- Eclipse
- 支柱
我想要的:
- 实例化
Obj A
所需的时间, - 实例化
ObjDiff B
所需的时间, - 运行
A.callMe()
所需的时间, - 运行
B.callMeToo()
所需的时间
- Time taken to instantiate
Obj A
, - Time taken to instantiate
ObjDiff B
, - Time taken to run
A.callMe()
, - Time taken to run
B.callMeToo()
任何帮助将不胜感激.
干杯,
罗希特(Rohitesh)
Cheers,
Rohitesh
编辑:
我已经安装了VisualVM,并将其用作独立应用程序.这很有帮助.但是,我的主要关注仍未得到解决.我无法查看方法上的内存/CPU使用情况.有什么想法吗?
EDIT :
I have installed VisualVM and used it as a standalone app. It has been helpful. However, my primary concern is still not addressed. I cannot look at the memory/CPU usage, method wise. Any thoughts on this?
推荐答案
我也建议 VisualVM ,基本但非常有用.建议您在与应用顶部相同的Java 7 JVM上运行它,以避免兼容性问题.如果需要更高级的功能(例如跟踪与Web服务器的用户交互),则可以查看更详细的分析器,例如Introscope.
I would recommend VisualVM too, basic but quite useful. Recommended you run it on the same Java 7 JVM as your app top avoid compatibility issues. If you need more advanced features like tracing a user interaction with a web server, you can look at more elaborate profilers like Introscope.
这篇关于如何查看执行过程中Java程序中每个方法所花费的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!