From: Marek P. <ma...@us...> - 2002-03-06 22:03:23
|
Update of /cvsroot/javaprofiler/library/demo/07 In directory usw-pr-cvs1:/tmp/cvs-serv25203/demo/07 Added Files: Makefile Makefile.mak Makefile.rules README Test.java dir.info Log Message: examples --- NEW FILE: Makefile --- include ../../config.mk include Makefile.rules --- NEW FILE: Makefile.mak --- !include ../../config.mk !include Makefile.rules --- NEW FILE: Makefile.rules --- Test.o \ Test.obj: $(JAVAC) $(JAVACFLAGS) Test.java --- NEW FILE: README --- This example show how to gain a calltree from the library using the getCallTreeThruIterator() method. --- NEW FILE: Test.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"); you may not use this file except * in compliance with the License. A copy of the License is available * at http://www.sun.com/ * * The Original Code is the Java Profiler module. The Initial Developers * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. * * Portions created by Jan Stola are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Pavel Vacha are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Michal Pise are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Petr Luner are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Lukas Petru are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Marek Przeczek are Copyright (C) 2000-2001. * All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ import java.lang.*; import java.util.*; import net.sourceforge.javaprofiler.jpiimpl.commun.*; public class Test { // communication interface private IProf iprof = null; public void runTest() { // initialize and start communication // we use socket communication where Java module will // stay for a server (so dynamic library must stay for a client) iprof = new IProf(); iprof.run(); try { // first of all, we need a thread ID Iterator iterator = iprof.getAllThruIterator( 0, IProf.THREADS, true); while( iterator.hasNext()) { IProf.sID sid = (IProf.sID)iterator.next(); // ask for more info IProf.sThreadInfo sti = (IProf.sThreadInfo)iprof.getInfo( sid.infoId, IProf.THREAD_INFO); System.out.println( "thread: " +sti.threadName); System.out.println( "info ID: " + sid.infoId); System.out.println( "object ID: " + sid.objId); // now, ask for calltree iterator of this thread Iterator ct_iterator = iprof.getCallTreeThruIterator( sid.objId, true); if( ct_iterator == null) System.out.println( "calltree is empty !"); else { int numOfItems = 0; // count number of items in calltree while( ct_iterator.hasNext()) { numOfItems++; ct_iterator.next(); } System.out.println( "okay, #items = " + numOfItems); } System.out.println(); } // now, i don't want anything else, // so I shutdown profiled JVM definitely iprof.shutdown(); } catch( Exception e) { System.err.println( "an error occurred, exception:"); System.err.println( e.getClass().getName()); } // communication must be stopped even if an error occurred ! iprof.stop(); iprof = null; } public static void main( String[] arg) { // let's run the test (new Test()).runTest(); } }; --- NEW FILE: dir.info --- FILES = Test CLEAN_FILES = *.class |