0

JVisualVM can connect to a remote JVM through JMX.

I need to collect CPU sampling data from remote JVMs the way JVisualVM does. Looks like JVisualVM is collecting sampling data from the exposed MBeans on remote JVMs.

Which classes are relevant in JVisualVM source to start with?

RRM
  • 2,495
  • 29
  • 46
  • 1
    JVisualVM has nothing to do with the hprof agentlib (which is removed in Java 9) – Ingo Kegel Jul 13 '17 at 20:34
  • I know. What I was asking was how does JVisualVM collect the CPU profiling/sampling data. Which classes from its source code should I start with? – RRM Jul 14 '17 at 08:01
  • 1
    From your changed question: `Looks like JVisualVM is collecting sampling data from the exposed MBeans on remote JVMs` -> That is not correct. VisualVM is a JVMTI-based profiler and sampling is implemented in native code. There are no MBeans that provide method-level call trees or hot spots. – Ingo Kegel Jul 14 '17 at 09:30
  • Which class in the JVisualVM calls those native methods? – RRM Jul 14 '17 at 12:57
  • 1
    No it's not like that. There is no class that calls native methods. it's a native profiling agent that is loaded via -agentpath. You cannot use this from Java somehow as if it were a library. – Ingo Kegel Jul 14 '17 at 14:41
  • Then how is JVisualVM able to show the sampling output in its GUI? – RRM Jul 17 '17 at 08:56
  • 1
    A profiler typically maintains a connection to the profiling agent through a TCP socket. The profiling data is managed by the native profiling agent and transmitted to the frontend on request. It would be possible to make an API for what you are looking for but I'm not aware that JVisualVM offers anything like that. In [JProfiler](https://www.ej-technologies.com/products/jprofiler/overview.html) there is such functionality, see `api/samples/platform/src-profiler/TestProfiler.java` for an example (disclaimer: my company develops JProfiler) – Ingo Kegel Jul 17 '17 at 13:06

0 Answers0