21

JDK 1.6 comes bundled with a handy tool called VisualVM that lets you inspect and interact with running Java processes. One feature is that it auto-detects running JVMs on the local machine. Most are listed as " (pid xxxx)" but some have a name and an icon, like VisualVM itself and others like NetBeans (see the screenshot in this dzone article for example).

How do I inject my application name and icon into the JVM so it shows up properly in VisualVM's application list? Does my app need to be running JRE 1.6 or can I do this under 1.5 too?

Chris Dolan
  • 8,905
  • 2
  • 35
  • 73
  • Here's a hint I learned by looking at LocalVmManager in OpenJDK: the list of local VMs is discovered by looking in $TMP/hsperfdata_$USER/. Each file in there is named for the PID of the VM. Contained therein is the command line as "sun.rt.javaCommand" but the file for the VisualVM process does not contain the string "VisualVM" so it can't come directly from that file. – Chris Dolan Dec 13 '10 at 22:43

1 Answers1

31

I solved half of my own question via a NetBeans forum post answer. Adding a JVM command line arg of -Dvisualvm.display.name=FooBar makes VisualVM show the app as "FooBar". But I still can't figure out how to affect the icon.

UPDATE: Alas, I think I found my answer for the icon. The icons are hard-coded into VisualVM via MainClassApplicationTypeFactory in the VisualVM source, invoked from the static method ApplicationTypeFactory.getApplicationTypeFor(Application). I can't see any way to inject a new icon into VisualVM except by making a VisualVM plugin which could register a new type factory -- the Glassfish plugin does this via GlassFishApplicationTypeFactory.initialize() for example.

Stephan
  • 41,764
  • 65
  • 238
  • 329
Chris Dolan
  • 8,905
  • 2
  • 35
  • 73
  • Thanks, Chris. I was just wondering that on Friday. No more guessing game! – Andy Thomas Dec 15 '10 at 05:32
  • 3
    More advice to future readers: it appears to me that you can't have spaces in the app name. That is, -Dvisualvm.display.name=Foo Bar and -Dvisualvm.display.name="Foo Bar" don't work. – Chris Dolan Jan 30 '12 at 01:48
  • kinda lame to have to write a plugin and register only to have a decent visual representation of the app you want to track. Maybe a manifest like file that is auto discovered by VisualVM will be nice...or just use app's own icon...somehow – Alex Jan 17 '13 at 08:10
  • 6
    If you want to have a space in the process name, use a no-break space (U+00AD). –  Oct 15 '13 at 11:31
  • Anyone have any idea how this could be done for jps as well? It'd be nice if they all used a display.name or something. – Bill K Apr 04 '18 at 17:54
  • FYI, here's where you can find this information into the code : https://github.com/oracle/visualvm/blob/master/visualvm/application/src/org/graalvm/visualvm/application/ApplicationDescriptor.java#L45 – Guillaume Husta Oct 17 '18 at 10:28