Update of /cvsroot/javaprofiler/library/demo/04
In directory usw-pr-cvs1:/tmp/cvs-serv24727/demo/04
Added Files:
Makefile Makefile.mak Makefile.rules README Test.java dir.info
Log Message:
demo to introduce new features of Java IProf class added,
(net.sourceforge.javaprofiler.jpiimpl.commun.IProf)
--- 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 shows how to use iterators (getAllThruIterator() and
getChangedThruIterator() methods). It does the same as example 01 (very slow)
and 02 (fast). Read comments in the file.
--- 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;
private int askForMethods( int objId) throws Exception {
int numMethods = 0;
// ask for all methods of given class
Iterator iterator =
iprof.getAllThruIterator( objId, IProf.CLASS_METHODS, true,
true, IProf.NO_OPTIONAL_ARG);
while( iterator.hasNext()) {
// take the first one directly from I/O buffer
IProf.sID sid = (IProf.sID)iterator.next();
// write method name
IProf.sMethodInfo mi = (IProf.sMethodInfo)sid.info;
System.out.println( " METHOD: " + mi.methodName);
numMethods++;
}
System.out.println();
return numMethods;
}
private void askForClasses() throws Exception {
int numClasses = 0;
int numMethods = 0;
// ask for all classes
Iterator iterator =
iprof.getAllThruIterator( 0, IProf.CLASSES, true,
true, IProf.NO_OPTIONAL_ARG);
while( iterator.hasNext()) {
// take the first one directly from I/O buffer
// every time returned, sid references to same object
// only data inside it are changed
// WHY: because 'sameOutputObject' of getAllThruIterator()
// was set to 'true' => we don't waste our memory
IProf.sID sid = (IProf.sID)iterator.next();
// write class name
IProf.sClassInfo ci = (IProf.sClassInfo)sid.info;
System.out.println( "CLASS: " + ci.className);
// ask for all methods of choosen class
numMethods += askForMethods( sid.objId);
numClasses++;
}
System.out.println( "NUMBER OF CLASSES: " + numClasses);
// following two numbers should be the same
// if not, something is bad
LinkedList list = iprof.getAll( 0, IProf.METHODS);
System.out.println( "NUMBER OF METHODS (1): " + numMethods);
System.out.println( "NUMBER OF METHODS (2): " + list.size());
}
public void runTest() {
// initialize and start communication
// sockets are used by default
iprof = new IProf();
iprof.run();
try {
// til profiled program is going, do nothing
while( !iprof.isShutdowned()) {
System.out.println( "waiting...");
Thread.sleep( 1000);
}
// profiled program has finished, so ask for all classes
askForClasses();
// 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
|