简体   繁体   English

如何找出哪种方法需要花费很多时间?

[英]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 . 查看这篇文章最后一段

Here's more on how it works. 这里有更多关于它是如何工作的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用“timed()”来找出 Reactor 操作员花费了多少时间 - Using "timed()" to find out how much time a Reactor operator is taking BufferedReader readLine()方法花费了很多时间 - BufferedReader readLine() method taking so much time 如何找出调用方法的接口? - How to find out which interface a method was called on? 如何找出线程中断后还剩下多少睡眠时间? - How can I find out how much time was left to sleep after thread was interrupted? 找出Thread使用了多少RAM - Find out how much RAM is used by Thread 如果占用太多时间,如何取消AsyncRestTemplate HTTP请求? - How to cancel AsyncRestTemplate HTTP request if they are taking too much time? 如何找出在编译时加载了哪个类? - How to find out which class is loaded at compile time? 在执行 Hibernate 查询时,如何找到哪个 Join 占用了大部分时间? - How do i find which Join is taking most of the time while executing a Hibernate query? 如何在 SpringBoot 上构建的 Java REST APIs 中查找源代码的哪一部分执行时间更长? - How to find which part of the source code is taking more time to execute in Java REST APIs built on SpringBoot? Eclipse插件可以检查代码的哪一部分需要花费太多时间? - Eclipse plugin that can check which part of code is taking too much time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM