Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does filtering classes for cpu profiling work in Java VisualVM?

I want to filter what classes are being cpu-profiled in Java VisualVm (Version 1.7.0 b110325). For this, I tried under Profiler -> Settings -> CPU-Settings to set "Profile only classes" to my package under test, which had no effect. Then I tried to get rid of all java.* and sun.* classes by setting them in "Do not profile classes", which had no effect either.

Is this simply a bug? Or am I missing something? Is there a workaround? I mean other than:

  • paying for a better profiler
  • doing sampling by hand (see One could use a profiler, but why not just halt the program?)
  • switch to the Call Tree view, which is no good since only the Profiler view gives me the percentages of consumed CPU per method.

I want to do this mainly to get halfway correct percentages of consumed CPU per method. For this, I need to get rid of the annoying measurements, e.g. for sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run() (around 70%). Many users seem to have this problem, see e.g.

  • Java VisualVM giving bizarre results for CPU profiling - Has anyone else run into this?
  • rmi.transport.tcp.tcptransport Connectionhandler consumes much CPU
  • Can't see my own application methods in Java VisualVM.
like image 415
DaveFar Avatar asked Aug 26 '11 13:08

DaveFar


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 Java 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.

What is VisualVM sampler?

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!

Is JVM a Java profiler?

A Java Profiler is a tool that monitors Java bytecode constructs and operations at the JVM level. These code constructs and operations include object creation, iterative executions (including recursive calls), method executions, thread executions, and garbage collections.


1 Answers

The reason you see sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run() in the profile is that you left the option Profile new Runnables selected.

Also, if you took a snapshot of your profiling session you would be able to see the whole callstack for any hotspot method - this way you could navigate from the run() method down to your own application logic methods, filtering out the noise generated by the Profile new Runnables option.

like image 155
JB- Avatar answered Sep 23 '22 03:09

JB-