LTM is a Java tool for giving an overview of the life time of
instances. It is based on a method described by
Jack Shirazi
and uses PhantomReferences
and a modified
java.lang.Object
. By using it you are able to track
object creation and garbage collection and count the number of currently
life instances per class. The collected data can be viewed using a
simple graphical viewer. LTM is described in detail in my article
Überwachung der Anzahl aktiver Objekte
in JavaSPEKTRUM, 1/2006.
Note that professional profiling tools are much more powerful and reliable. LTM was only developed because we could not suffer the overhead of a full blown memory snapshot algorithm.
To install LTM, simply extract the ltm-*.zip and put it into
your bootclasspath with LTM.jar. LTM is JDK 1.3 compliant and does not
depend on any other libraries. When using another JRE than 1.4, you will
have to modify your java.lang.Object
as well and put if
before LTM.jar into your bootclasspath:
// --- code added to object --- public Object() { if (at.herold.test.objlifetime.MonitoringFlag.monitoring) { at.herold.test.objlifetime.ObjectLifetimeMonitoring.monitor(this); } } // --- code added to object ---
java -Xbootclasspath/p:LTM.jar -classpath <your application's classpath> at.herold.test.objlifetime.ObjectLifetimeMonitoring s <your application's main class> <your application's parameters if any>
java -jar LTM.jar
start
" on the same machine running the application. This enables
the counting of objects.java -jar LTM.jar stop
". The
application will continue to run normally.java -jar LTM.jar save
".
This saves the raw data using a constant file name.java -jar LTMViewer.jar <raw file>
". This
loads, analyses and displays the object lifetime statistics. An JPG image is saved
as well.In case you want to add or change something, there are the following packages:
at.herold.test.objlifetime
contains the LTM core classes.
Monitoring is managed by the AdminThread
, which listens to
a socket for commands.at.herold.test.objlifetime.viewer
contains the viewer to analyse
the saved data from the LTM. Analyzing classes are subclasses of
LifeTimeAnalyser
.LTM is Open Source under the GPL license.