Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference between sampler and profiler in JvisualVM?

I found there are two plug-in in JvisualVM, one is sampler and another is profiler.

I also found they have a similar UI, however the results have a big difference, so what's the difference meaning for them?

And why they have a big difference?

like image 250
Jason Avatar asked Sep 23 '16 08:09

Jason


People also ask

What is profiler in VisualVM?

Java VisualVM enables you to take profiler snapshots to capture the results of a profiling session. A profiler snapshot captures the results at the moment the snapshot is taken. To take a snapshot, click the Take Snapshot of Collected Results button in the toolbar while a profiling session is in progress.

What is profiler in JVM?

Profiling is the process of examining an application to locate memory or performance-related issues. When profiling a Java application, you can monitor the Java Virtual Machine (JVM) and obtain data about application performance, including method timing, object allocation and garbage collection.

Is Jmx a Java profiler?

JMX (Java Management Extensions) combined with VisualVM are very useful tools to have when profiling a Java web app running on a Jetty web server, especially when you want to pinpoint what part of your application is using the most CPU or Memory.

What is VisualVM used for?

Java VisualVM is a tool that provides a visual interface for viewing detailed information about Java applications while they are running on a Java Virtual Machine (JVM), and for troubleshooting and profiling these applications.


1 Answers

In general:

A profiler is running all the time, so it gives you the complete call stack; at any given point in time.

A sampler only takes "snapshots" at distinct point in times.

Thing is: when you "profile" everything, then that slows down your JVM significantly; and it creates enormous amounts of data within a few seconds. Think about: the profiler will write down each and any method invocation that takes place!

So typically, you initially use a sampler, when you have "no idea" what is going on within your application. And then you just hope that the samples tell you something; like "hey, within our 10 000 samples, we are in that one method most of the time, why is that?" But as soon as you have a better understanding what you are "hunting" for, you would try to do a full profiler run in order to capture the whole call chain that leads into some method.

And then there is some "middle ground" - where you profile "everything" but exclude things. In other words: most profilers allow you to say "do not profile methods in classes in this or that package". But of course - excluding packages/hierarchies only makes sense when you already have a pretty good feeling which direction you intend to investigate.

like image 171
GhostCat Avatar answered Sep 19 '22 10:09

GhostCat