You need to know how to use profilers / which one to use

This may seem like a silly question, but after you ask a few questions about stackoverflow and look at a question from other people, you often need to use profilers to see which part of the code is slower, etc.

Being a beginner in programming, I am new to all of this, but since I am creating a larger project, I feel that such a tool will be very useful from time to time. The only thing I do not know how to use them.

I usually use JDeveloper for coding in Java, and I read on the Internet that there is one built-in. I tried to use it, but I think I really didn’t know how, because I could not find which parts make my program slower. I don’t know if this is because I don’t know how to use it, or if it is known for not being good, so I decided that I would ask here to see where I should start.

I also have Eclipse installed and know how to use it (I use Eclipse when I code some Python or when I try to use tutorials for Android development), so if there is a free profiler that I could use for either of these two IDE, I would really like to know about this. Also, the tutorial or the basic things I need to know about profilers helped me a lot.

Thanks in advance and it’s a pity that my question is not about programming, but it seems like the best place to get valuable information about profilers.

+6
source share
3 answers

If you are confused, this is the majority of profiler providers .

The first thing to understand is that the programs are not slow, because they have slow parts (bottlenecks). They are slow because they do more than they need. They have time to drain.

It is like a leap. The bottleneck will be the bottleneck on the track where horses must accumulate and slow down. The drainage of time will be similar to another track, merged with the first, in which the horses wander and are forced to travel an extra distance. Then there may be another track merged with this, and another, etc.

A function call that could have been avoided is an example of a time leak.

Here, how I find the time of drains. It is simple and language independent. You can even do this with a simple tool like jStack.

The manufacturers of profilers understand well, but they are confused by the confusion of concepts.

For example, "where is the time spent." If this means “where the program counter is most often found”, it looks like the horse is in the wrong racetrack. You could try shortening this racetrack, but the real problem is that the horse should not even be there. that is, a function call that should be avoided.

Such as "statistical measurement accuracy." Do you need to measure how long a horse takes to get around the wrong race track to find out about it at the wrong racetrack? No, you just need to take a snapshot (sample stack). The longer this takes place on the wrong track, the greater the likelihood that you will see it. If you see him twice, you know what the problem is.

For example, call it "CPU Profile", which is a pretext to ignore the I / O time. Sometimes leak times are unnecessary I / O that you did not know about. It would be like a horse stopping to lay on a bag of oats. If you can take a picture while the horse is running, you will never notice. You would only notice that the time was suspiciously long.

There are more where they came from ...

+3
source

If you are looking for a free tool, jvisulavm is great. It comes with a standard JDK installation, its executable is usually located in the bin directory JAVA_HOME, next to java, javac, javadoc and their siblings. Here is a tutorial:

http://download.oracle.com/javase/6/docs/technotes/guides/visualvm/index.html

If you are looking for a more advanced commercial product, YourKit or jprofiler are interesting.

+3
source

Using a profiler is not a trivial task and requires a large amount of basic knowledge about the internal functions of VM. Therefore, it is best to start by reading about memory management, a hot spot, etc. Some worthy help can be found on the profiler help pages, see, for example, help for JProfiler .

In my experience, I only had to use the profiler several times when there were serious performance problems that could not be tracked in other ways. In many cases, simple tasks, such as timestamps in the log, help solve performance problems. Therefore, use the profiler as a last resort. He said that I had heard about cases where people used it on a regular basis. At least I’m talking about it, but I could never get this process to work for me.

I could not find a free profiler that would satisfy me. Commercial which I used at different times, JProbe and JProfiler . I liked JProfiler more, but both provide results.

Typically, the process begins by setting up your application inside the profiler and specifying which classes you want to look specifically at. When you run your application in the profiler, the classes get the tool in such a way that execution information and the VM are written. Therefore, after starting the application, you can analyze it to find out which code is consumed most of the time and which objects used most of the memory. You can also monitor streams, monitors, and a number of other things. To take advantage of all the data, you will need to learn a lot about the internal functions of VM and what you profile.

Good luck

+1
source

Source: https://habr.com/ru/post/892876/


All Articles