1

I am planing to develop a profiler by using the JVMTI API provided by Oracle. For a visualization I would like to implement a GUI (Qt framework) on top of the agent code. My first jvmti agent is aready compiling and running and I started to integrate the agent into my Qt project.

Now I am facing the problem how to couple agent with GUI. Should the GUI be launched inside the agent? For instance in the Agent_OnLoad function?

A long-term would be to start the profiling out of the GUI, though I cannot imagine how to realize that.

Konrad Reiche
  • 27,743
  • 15
  • 106
  • 143

1 Answers1

0

Well.. you have a number of choices the most obvious would be socket based comms. You'll have to assume that the majority of profiling use cases will involve a remote headless JVM on a server. In my profiler you can operate headless with a small start/stop/control utility on the same machine as the agent, data is collected on the server and transfered to the client for visualisation. You can also start the remote (or local) jvm with the agent and connect to the listening agent over a socket from the full GUI.. collecting over that socket to the client.

There is also the new "JVM Attach API" which allows you to "insert" an agent into an already running JVM, therefore if the target machine is UNI* then you could use ssh/scp from your GUI and script an sCP transfer of the agent to the server and SSH to initiate the attach.

So... sockets (IP and/or domain) and reuse that code from the GUI for a headless control/collection client

  • Socket would cover useful use cases, however I am afraid this is a bit more advanced. I could imagine providing a socket server began with the AgentOnLoad. I guess for my first steps it would be easier to attach the GUI directly to the agent - is this even possible? I mean the agent is compiled as a library. – Konrad Reiche Mar 15 '11 at 09:24
  • Hmmmm... then you are looking start starting the JVM as a JNI JVM withing the GUI process which will practically limit what you will be able to profile.... no application servers etc.... if it is a JNI JVM then you will have direct call ability as the GUI and JVM are in effect running in the same address space.... sockets are not that difficult QT is quite helpful with the nasty stuff – Paul Anderson Mar 15 '11 at 09:27
  • I think this changes my mind. So a practical approach would be to implement inside the agent the client-side socket and send the events to the GUI or the other way around? Doesn't the agent die together with the JVM? I would just go and try it out for myself, I just want to have a little sketch in mind! :-) – Konrad Reiche Mar 15 '11 at 09:33
  • Yes, classically the agent would open a server socket on a new thread and listen for the GUI to connect... you can limit this to a single agent/gui connection at any one time for simplicity. You can develop a very simple command protocol between the two (start, stop, reset etc). – Paul Anderson Mar 15 '11 at 09:36
  • The listening network thread would receive the start command which, in the same thread, call the JVM to "start profiling" , the JVM then calls your agent callbacks from the JVM thread(s) ... these callback will "collect" events and put them in a buffer... another thread that you would have started will asynchronously send this buffer to the GUI over the established socket.... now you could simplify the above by no having the sending thread but when the buffer is full the JVM will basically stop as your code sends the collected data to the GUI... this is not too bad for a first attempt – Paul Anderson Mar 15 '11 at 09:44
  • ... my profiler is fully asynchronous as it profiles some very complex environments and produces gigabytes of data per second. – Paul Anderson Mar 15 '11 at 09:44
  • This is very helpful, thanks. How would you design the datas which are sent over the socket? Custom data structures? For instance a class AllThreadInfo which stores the information which you receive when jvmti->GetAllThreads is called? – Konrad Reiche Mar 15 '11 at 09:51
  • thinking about it..... I may well be possible to implement a AT GUI binary that implements Agent_OnLoad ... a problem would be that the first call into the program would the the onLoad (called by the JVM) how would one call the probably required QT startup that is normally executed by the standard QT "main" entry point....... personally I would vote for the socket approach – Paul Anderson Mar 15 '11 at 09:59
  • yes.... that protocol is all up to you...... A Question... what events do you want to collect and how are you going to visualize? – Paul Anderson Mar 15 '11 at 10:00
  • I will focus exclusive on concurrent events, the topic of my thesis is profiling concurrency. The visualization will be part of my research, I have some ideas, but not manifested yet. Thread states with different colors, Thread life time in a graph, there is a neat Qt widget for graphs and some coloring for showing the thread dependency between the threads. This will be a long way. – Konrad Reiche Mar 15 '11 at 10:03
  • I played with something like that a few years ago.... http://www.youtube.com/watch?v=rl5_tAZL8pA .....but it was a bit too "square" for my liking.... today I would do something much more fluid... check out some of the more abstract examples at http://www.chromeexperiments.com/ you will need the latest chrome browser – Paul Anderson Mar 15 '11 at 10:11
  • This is great, though your video freaked me a little bit out, hehe :-) – Konrad Reiche Mar 15 '11 at 10:15
  • I just realized with this design I have the possibility to dock any GUI. I also could write the GUI in Java Swing, which is a bit tempting, as I have alot more experience in Java. I wonder if this is an option or if I should consider the deep dive into Qt. – Konrad Reiche Mar 15 '11 at 10:54
  • Hmmmm QT is very good... but the learning curve to fully exploit can be steep..... I'm personally leaning towards HTML5 Canvas rendering and JavaScript on the client using binary WebSockets for comms but this is pretty bleeding edge.... There are so many choices it's tough to know what to do..... If you like Java you could also chose Eclipse/SWT – Paul Anderson Mar 15 '11 at 11:15
  • @Paul-anderson I have put some thoughts into the whole project. Now where I am aiming to implement the agent headless, I guess I will implement the GUI in Swing. Further, I see no point in using the Qt framework at all. It is a nice framework, but getting into the concept of Qt, for instance signal and slot, etc. is even more overhead. – Konrad Reiche Mar 23 '11 at 18:37