Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sampling in visual vm

Can anyone explain the science behind the sampling functionality of visualvm ?

I would have thought that collecting the amount of CPU spent on each particular method would require instrumenting the application to be profiled, but it doesnt look like visualvm is doing any kind of instrumenting, so I'm curious to know how it's done...

like image 610
Eleco Avatar asked Dec 02 '09 08:12

Eleco


2 Answers

It has a timer. When the timer fires, it copies the current contents of every thread's stack. Then it translates the stack frames into method and object names, and records a count against the relative methods.

Because of this, it doesn't need to instrument the code, and is therefore very lightweight. However, because it doesn't instrument the code is can miss short-running stuff. So it's mostly useful either for tracking long-running performance problems, or to quickly identify a serious hot-spot in your code.

like image 122
Noel Grandin Avatar answered Oct 04 '22 16:10

Noel Grandin


It looks like the new VisualVM-Sampler plugin gather performance and memory data by periodically polling the monitored application for thread dumps or memory histograms. Check this article for more details.

like image 20
Pascal Thivent Avatar answered Oct 04 '22 15:10

Pascal Thivent