Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to know how to use profilers / which one to use

Tags:

java

profiler

This might seem like a silly question, but after asking some questions on stackoverflow and looking at other people's question, one thing that comes often is to use profilers to see which part of the code runs slow, etc.

Being a programming beginner, I'm new to all of this, but since I'm creating bigger and bigger project, I feel like such a tool would prove to be very useful at times. The only thing is, I don't know how to use them.

Usually, I use JDeveloper to code in Java, and I read on the internet that there's one built-in. I tried using it but I guess I didn't really know how because I couldn't find which parts where making my program slower. I don't know if it's because I don't know how to use it or if it's known for not being good, so I figured I'd ask here to see with which one I should start.

I have Eclipse installed as well and know how to use it (I use Eclipse when I'm coding some Python or when I'm trying tutorials for Android-development), so if there's a free profiler I could use for either of those two IDEs, I'd really like knowing about it. Also, a tutorial or basic things I need to know about profilers would help me a lot.

Thanks in advance and sorry that my question isn't really about programming, but this seems like the best place to get valuable information about profilers.

like image 770
Adam Smith Avatar asked Jul 16 '11 03:07

Adam Smith


People also ask

What is the use of profiler?

A profiler can be used to understand code from a timing point of view, with the objective of optimizing it to handle various runtime conditions or various loads. Profiling results can be ingested by a compiler that provides profile-guided optimization.

How do you use profiling tools?

You can use profiling tools to identify which portions of the program are executed most frequently or where most of the time is spent. Profiling tools are typically used after a basic tool, such as the vmstat or iostat commands, shows that a CPU bottleneck is causing a performance problem.

How do I use coder profiler?

Code profiling examines the application code to ensure it is optimized, resulting in high application performance. It analyzes the memory, CPU, and network utilized by each software component or routine.

What are code profiling tools?

Code profiling tools allow you to analyze the performance of your code by measuring the time it takes your methods to run and the amount of CPU and memory they consume.


2 Answers

If you're confused, so are most of the profiler vendors.

The first thing to understand is - programs aren't slow because they have slow parts (bottlenecks). They are slow because they do more than they have to. They have time drains.

It's like a horse race. A bottleneck would be a narrow place in the track, where the horses have to pile up and slow down. A time drain would be like another track fused with the first, into which horses wander and have to travel an extra distance. Then there could be another track fused with that one, and another, and so on.

A function call that could be avoided is an example of a time drain.

Here's how I find time drains. It's simple and language-independent. You can even do it with a simple tool like jStack.

Profiler makers mean well, but they are hampered by a bunch of confusing concepts.

Such as "where the time is spent". If what this means is "where the program counter is found most often", that's like the horse being in the wrong racetrack. You could try to shorten that racetrack, but the real problem is the horse shouldn't even be there. i.e. there's a function call that should have been avoided.

Such as "statistical accuracy of measurement". Do you need to measure how long the horse takes to get around the wrong racetrack to know it's on the wrong racetrack? No, you just need to take a snapshot (stack sample). The longer it's on the wrong racetrack, the more likely you'll see it. If you see it there twice, you know what the problem is.

Such as calling it a "CPU Profiler", that being an excuse to ignore I/O time. Sometimes the time drain is needless I/O you were not aware of. That would be like the horse stopping to munch on a bag of oats. If you can only take your snapshot while the horse is running, you would never notice. You would only notice that the time was suspiciously long.

There's more where those came from ...

like image 111
Mike Dunlavey Avatar answered Oct 02 '22 20:10

Mike Dunlavey


If you are looking for a free tool, jvisulavm is a great one. It comes with a standard JDK install, its executable is usually under the bin directory of the 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 both interesting.

like image 35
Moe Matar Avatar answered Oct 02 '22 20:10

Moe Matar