4

I've been looking at various java performance monitoring tools.

I worked out a solution that uses perf4j + aspectj, so that I can define which classes to monitor with an aspectj pointcut expression. However aspectj also (AFAIK), does not allow you to change the pointcut expression at runtime. So if I need to monitor new classes I would have to change the aop.xml and recompile (or atleast restart the app if using AspectJ load time weaving).

I have not found anything so far that can instrument classes at runtime without needing a restart of the application. Is there a tool/technology out there which can do that?

gresdiplitude
  • 1,665
  • 1
  • 15
  • 27
  • Interesting question, if you don't mind can you add a scenario for which you need to instrument a class? I couldn't think of one. – kosa Aug 02 '12 at 14:57
  • There are general obstacles that probably get in your way (see this question [Unload a already loaded class](http://stackoverflow.com/questions/2095974/how-to-unload-a-already-loaded-class-in-java)). – Durandal Aug 02 '12 at 15:06

4 Answers4

3

These types of tools typically don't instrument classes at runtime. Instead they use the JVMTI interface (if you don't understand what this is, google it).

Prime examples of products that use it:

Yourkit, JProfiler

There's a few open source tools, but I haven't really found any of them to be nearly as polished as their commercial counterparts.

Matt
  • 11,523
  • 2
  • 23
  • 33
  • JRat (http://jrat.sourceforge.net/) is a well-known open source profiler. For looking at the source code it should be ok. – Philipp Wendler Aug 02 '12 at 15:27
  • visualvm is somewhat lacking in features. it doesn't have nearly the capability of something like jprofiler or yourkit, though in some situations it can be very useful. – Matt Aug 02 '12 at 18:57
1

Found a perfect little library BTrace, which does exactly what I needed. It works by manipulating the byte code of the instrumented class at runtime, no need to restart your application. Check out the user guide to see how easy it is to set it up.

Another thing worth mentioning about Btrace is that, the authors have made a lot effort to make it safe to work in a production environment.

To guarantee that the tracing actions are "read-only" (i.e., the trace actions don't change the state of the program traced) and bounded (i.e., trace actions terminate in bounded time), a BTrace program is allowed to do only a restricted set of actions.

gresdiplitude
  • 1,665
  • 1
  • 15
  • 27
0

I suggest using Eclipse's (or NetBeans) debugger/profiler.
It is very powerful.

There is also an entire project dedicated to these tools:
http://www.eclipse.org/projects/project.php?id=tptp.performance

and some interesting plugins:
http://code.google.com/a/eclipselabs.org/p/jvmmonitor/

Edmon
  • 4,752
  • 4
  • 32
  • 42
0

As Matt said, YouKit Java Profiler can instrument Java byte-code. YourKit allows to write own probes and insert them into the running Java apps. Probe API allows to access method parameters, return values, catch exceptions, etc.

The docs is here: http://www.yourkit.com/docs/11/help/probes.jsp

  • Two things 1/ I don't like the idead of running a profiler in a production environment. 2/ It's not free. – gresdiplitude Aug 10 '12 at 13:35
  • [Per the faq's](http://stackoverflow.com/faq#promotion), please be sure to disclose your affiliation with products you are recommending within your response. – Leigh Aug 11 '12 at 06:08