views:

118

answers:

6

I'm not sure how useful this would be, but I thought it might be neat to visualize the objects being used in my program and which objects are being referenced from where. I'm guessing it would generate some data that would be used by a program like graphviz. Are there any tools that do this, otherwise how hard would it be to do this myself? Ideally this would work for any arbitrary program, though if necessary I could make some modifications to the code (such as to add a dumpObjects() call or whatever)

I'm interested in doing this for java, but if there are solutions for other languages please post those too.

A: 

not sure if that is what you are aiming at, but Doxygen will do pretty much all of that.

it will take a heap of compiling code and turn it into cross referenced html, rtf of pdf. completed will calling tree for each function and "referenced by " for each variable

Alon
Sorry, I meant objects being used at runtime.
swampsjohn
+8  A: 

A profiler would allow you to see what objects are created at runtime. This is the output of JProfiler for instance:

jprofiler heap walker

Jerome
JProbe is another profiler that has a similar sort of memory profiling feature. I used it ~10 years ago to fix some Java code written by people who mistakenly thought it wasn't possible to have memory leaks in Java. To find leas you take a "snapshot" at a particular point, do a set of operations in your program that you think may be leaky and then return the program to it's original state. Any objects created after the snapshot pointed to by objects created before the snapshot are potential leaky objects.
Laurence Gonsalves
+1  A: 

An interesting use case would be memory analysis and optimization. This is precisely what Eclipse MAT is about. Check it out.

alt text

Pascal Thivent
+1  A: 

Sun have developed the VisualVM which includes memory and process profiling. It also supports plugins for technology such as OSGi.

James Webster
A: 

YourKit Java Profiler http://www.yourkit.com

Object explorer (incoming and outgoing references):

alt text

Biggest objects:

alt text

Class loaders:

alt text

Serge
A: 

For visualising graph structures (including object graphs), there are lots of tools based on GraphViz: http://www.graphviz.org/

cartoonfox