什么是剖析以及如何剖析我的Java程序?

时间:2021-03-28 20:48:56

I've heard a lot about profiling. What is this all about? As far as I understand this is some kind of performance measurement but can someone elaborate this on more clearly so that a newbie can grasp the idea. Also, I use Eclipse IDE for my Java program. Can I profile my program using Eclipse IDE? What are the factors to be considered while profiling (I mean the best practices)?

我听说过很多关于分析的内容。这是怎么回事?据我所知,这是某种性能测量,但有人可以更清楚地阐述这一点,以便新手可以掌握这个想法。另外,我将Eclipse IDE用于我的Java程序。我可以使用Eclipse IDE配置我的程序吗?分析时要考虑哪些因素(我的意思是最佳实践)?

4 个解决方案

#1


6  

Profiling basically shows you how often a given line of code is executed and how much time was spent in it (compared to other lines). This makes it easy to pinpoint the location where your code spends most of the time.

概要分析基本上显示了给定代码行执行的频率以及在其中花费了多少时间(与其他行相比)。这样可以轻松查明代码大部分时间所处的位置。

It also makes it possible to find places where your code spends much time without doing anything: this is the typical sign of a cache miss and this is where you should get active.

它还可以找到代码花费很多时间而不做任何事情的地方:这是缓存未命中的典型标志,这是你应该活跃的地方。

Usually, programs spend very much time (say, 90%) in one place. Unfortunately, finding this place without profiling isn't possible. Guesswork often goes awry. So if you optimize in the wrong place, this won't help at all: if the overall time spent in that line is only 10%, your code will only get 10% faster (at best!). If, however, you succeed in removing the call that takes 90% of the time, your programm will get ten times faster.

通常,程序在一个地方花费很多时间(比方说,90%)。不幸的是,找不到这个没有剖析的地方是不可能的。猜测经常出错。因此,如果您在错误的位置进行优化,这根本无济于事:如果在该行中花费的总时间仅为10%,那么您的代码只会快10%(充其量!)。但是,如果您成功删除了占用90%时间的呼叫,则您的程序将快十倍。

This, in a nutshell, is profiling.

简而言之,这就是剖析。

Eclipse offers builtin profiling capabilies and I've been told that they're pretty good but since I don't know them, let someone else answer that.

Eclipse提供内置的分析功能,我被告知它们非常好,但由于我不了解它们,让其他人回答这个问题。

#2


2  

Konrad is right, but profiling covers other aspects of your program as well, such as memory consumption.

Konrad是对的,但是分析也涵盖了程序的其他方面,例如内存消耗。

#3


0  

YourKit is an excellent profiler for Java and will integrate nicely with Eclipse. It is definitely worth the money and generally thought to be the best Java profiler available.

YourKit是一个优秀的Java分析器,可以很好地与Eclipse集成。它绝对物有所值,并且通常被认为是最好的Java分析器。

#4


-1  

From what little research I've done on Java profiling with Eclipse, you can use JProfiler. I never really got much further than installing it and having a quick nose around though.

从我用Eclipse进行Java分析的小研究开始,您可以使用JProfiler。我从来没有比安装它更快,而且快速的鼻子。

#1


6  

Profiling basically shows you how often a given line of code is executed and how much time was spent in it (compared to other lines). This makes it easy to pinpoint the location where your code spends most of the time.

概要分析基本上显示了给定代码行执行的频率以及在其中花费了多少时间(与其他行相比)。这样可以轻松查明代码大部分时间所处的位置。

It also makes it possible to find places where your code spends much time without doing anything: this is the typical sign of a cache miss and this is where you should get active.

它还可以找到代码花费很多时间而不做任何事情的地方:这是缓存未命中的典型标志,这是你应该活跃的地方。

Usually, programs spend very much time (say, 90%) in one place. Unfortunately, finding this place without profiling isn't possible. Guesswork often goes awry. So if you optimize in the wrong place, this won't help at all: if the overall time spent in that line is only 10%, your code will only get 10% faster (at best!). If, however, you succeed in removing the call that takes 90% of the time, your programm will get ten times faster.

通常,程序在一个地方花费很多时间(比方说,90%)。不幸的是,找不到这个没有剖析的地方是不可能的。猜测经常出错。因此,如果您在错误的位置进行优化,这根本无济于事:如果在该行中花费的总时间仅为10%,那么您的代码只会快10%(充其量!)。但是,如果您成功删除了占用90%时间的呼叫,则您的程序将快十倍。

This, in a nutshell, is profiling.

简而言之,这就是剖析。

Eclipse offers builtin profiling capabilies and I've been told that they're pretty good but since I don't know them, let someone else answer that.

Eclipse提供内置的分析功能,我被告知它们非常好,但由于我不了解它们,让其他人回答这个问题。

#2


2  

Konrad is right, but profiling covers other aspects of your program as well, such as memory consumption.

Konrad是对的,但是分析也涵盖了程序的其他方面,例如内存消耗。

#3


0  

YourKit is an excellent profiler for Java and will integrate nicely with Eclipse. It is definitely worth the money and generally thought to be the best Java profiler available.

YourKit是一个优秀的Java分析器,可以很好地与Eclipse集成。它绝对物有所值,并且通常被认为是最好的Java分析器。

#4


-1  

From what little research I've done on Java profiling with Eclipse, you can use JProfiler. I never really got much further than installing it and having a quick nose around though.

从我用Eclipse进行Java分析的小研究开始,您可以使用JProfiler。我从来没有比安装它更快,而且快速的鼻子。