From: Marek P. <ma...@us...> - 2001-11-21 22:31:55
|
Update of /cvsroot/javaprofiler/library/demo/02 In directory usw-pr-cvs1:/tmp/cvs-serv12170/demo/02 Added Files: Makefile Makefile.mak Makefile.rules README Test.java dir.info Log Message: some parts completely rewritten; changes in communication interface to make it faster; ported to linux --- 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 --- Same demo program as in 01/ subdirectory. The difference is in how information about classes and methods are sent. In previous example (01), information about specific object (eg. class name, method name etc. not statistic data) was requested by special IProf::getInfo() method, which is a bit slow if you do a lot of requests. This example uses advantage of IProf::getAll() method (IProf::getChanged() does the same) to send information about specific object together with its statistic data which points to faster communication. --- 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; // number of all methods together private int numMethods = 0; private void askForMethods( int objId) throws Exception { // ask for all methods of given class LinkedList listMethods = iprof.getAll( objId, IProf.CLASS_METHODS, true, 0); ListIterator iterator = listMethods.listIterator(); while( iterator.hasNext()) { // take the first one from the list IProf.sID sid = (IProf.sID)iterator.next(); // write method name IProf.sMethodInfo mi = (IProf.sMethodInfo)sid.info; System.out.println( " METHOD: " + mi.methodName); } numMethods += listMethods.size(); System.out.println(); } private void askForClasses() throws Exception { // ask for all classes LinkedList listClasses = iprof.getAll( 0, IProf.CLASSES, true, 0); ListIterator iterator = listClasses.listIterator(); while( iterator.hasNext()) { // take the first one from the list 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 askForMethods( sid.objId); } System.out.println( "NUMBER OF CLASSES: " + listClasses.size()); // 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()) 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 |