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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With