[英]How to find out which method is taking much time?
One of my component is taking too much time to execute. 我的一个组件是花费太多时间来执行。 It calls lots of services which in turn calls many dao methods. 它调用了许多服务,而这些服务又调用了许多dao方法。 Now, is there any way to get the time taken by each method it is calling. 现在,有没有办法让它调用的每个方法花费时间。
I don't want to write System.currentmillis
before and after each method to calculate time taken as there are too many methods. 我不想在每个方法之前和之后编写System.currentmillis
来计算因为方法太多而花费的时间。
I think i may need to use interceptors or may be any profiler can do that. 我想我可能需要使用拦截器,或者可能是任何探查器都可以做到这一点。 I am not sure, please help. 我不确定,请帮忙。
Use jvisualvm
which should come with JDK (if I remember correctly). 使用JDK附带的jvisualvm
(如果我没记错的话)。 It's a GUI for your JVM, and has really nice functions. 它是您的JVM的GUI,并且具有非常好的功能。 Check out its features there are some screenshots as well... 查看其功能还有一些截图...
And you can follow these steps to integrate it as launcher in eclipse Steps to integrate in eclipse 并且您可以按照以下步骤将其作为启动器集成到eclipse 步骤中以集成到eclipse中
You can use the Java Profiler in the NetBeans IDE. 您可以在NetBeans IDE中使用Java Profiler。
Have a look here: http://netbeans.org/features/java/profiler.html 看看这里: http : //netbeans.org/features/java/profiler.html
The Java VisualVM is another alternative: http://java.net/projects/visualvm/content/ . Java VisualVM是另一种选择: http : //java.net/projects/visualvm/content/ 。 You can attach it to any running Java program, including ones you start through Eclipse. 您可以将它附加到任何正在运行的Java程序,包括您通过Eclipse启动的程序。
Don't look at it as measuring time to find the problem. 不要把它看作测量时间来找到问题。
Use its slowness to expose it. 使用它的缓慢来暴露它。 Just use the same method you would if it were an infinite loop. 只需使用与无限循环相同的方法。
That is, pause it a few times while it's being slow, and each time inspect the call stack of each thread. 也就是说,在它慢的时候暂停几次,每次检查每个线程的调用堆栈。 The guilty methods and lines of code will appear on multiple samples. 有罪的方法和代码行将出现在多个样本上。 Check the last paragraph of this post . 查看这篇文章的最后一段 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.