From: Pavel V. <va...@us...> - 2001-11-20 22:31:48
|
Update of /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/data In directory usw-pr-cvs1:/tmp/cvs-serv27483 Added Files: SnapshotImpl.java Log Message: Snapshot implementation --- NEW FILE: SnapshotImpl.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. */ package net.sourceforge.javaprofiler.jpiimpl.data; import java.util.*; import net.sourceforge.javaprofiler.jpi.*; import net.sourceforge.javaprofiler.jpi.dump.*; import net.sourceforge.javaprofiler.jpiimpl.commun.*; import net.sourceforge.javaprofiler.jpiimpl.data.*; /** * Implementation of Snapshot. * * @see net.sourceforge.javaprofiler.jpi.Snapshot * @author Pavel Vacha */ public class SnapshotImpl implements Snapshot { String name; long time; private HashMap libIDs = new HashMap(); //converts libIds to references //its different for different snapshots! private LinkedList classes = new LinkedList(); private LinkedList methods = new LinkedList(); private LinkedList groupThreads = new LinkedList(); private LinkedList threads = new LinkedList(); //private LinkedList arenas = new LinkedList(); private LinkedList gcs = new LinkedList(); //conf boolean withTraces = true; boolean withThreads = true; boolean withCPU = true; boolean withAlloc = true; boolean withMon = true; //boolean withArenas = true; boolean withGC = true; //other boolean haveSnapshot = false; /** Creates new SnapshotImpl */ public SnapshotImpl( IProf iprof ) { //PENDING pass configuration makeSnapshot( iprof ); } //init method private void makeSnapshot( IProf iprof ) { //PENDING //if ( haveSnapshot ) //throw vyjimku; long start = System.currentTimeMillis(); LinkedList actLst = new LinkedList(); //temporary list LinkedList actLst2 = new LinkedList(); //temporary list LinkedList actLst3 = new LinkedList(); try { //Add some info like time, data, etc. //?? use clear() or different lists if (withCPU || withAlloc || withMon) { extract( null, classes, IProf.CLASSES, iprof ); extract( classes, methods, IProf.CLASS_METHODS, iprof ); if( withThreads ) { extract( null, groupThreads, IProf.GROUPS_OF_THREADS, iprof ); extract( groupThreads, threads, IProf.GROUP_THREADS, iprof ); } } if( withCPU ) { if( withTraces ) { extract( methods, null, IProf.CPU_METHOD_TRACES, iprof ); } if( withThreads ) { extract( threads, (withTraces) ? actLst : null, IProf.CPU_THREAD_METHODS, iprof ); if( withTraces ) { extract( actLst, null, IProf.CPU_THREAD_METHOD_TRACES, iprof ); } } } if( withAlloc ) { actLst3.clear(); actLst2.clear(); actLst.clear(); //PENDING extract( null, actLst3, IProf.OBJECT_TYPES, iprof ); extract( actLst3, (withTraces)? actLst : null, IProf.ALLOC_OBJECT_METHODS, iprof ); if( withTraces ) { extract( methods, null, IProf.ALLOC_METHOD_TRACES, iprof ); extract( actLst, null, IProf.ALLOC_OBJECT_METHOD_TRACES, iprof ); } if( withThreads ) { actLst.clear(); actLst2.clear(); actLst3.clear(); extract( threads, null, IProf.ALLOC_THREAD_OBJECTS, iprof ); extract( threads, actLst, IProf.ALLOC_THREAD_METHODS, iprof ); if( withTraces ) { extract( actLst, null, IProf.ALLOC_THREAD_METHOD_TRACES, iprof ); } extract( actLst, (withTraces)? actLst2 : null, IProf.ALLOC_THREAD_OBJECT_METHODS, iprof ); if( withTraces ) { extract( actLst2, null, IProf.ALLOC_THREAD_OBJECT_METHOD_TRACES, iprof); } } } if( withMon ) { if( withTraces ) { extract( methods, null, IProf.MON_METHOD_TRACES, iprof ); } if( withThreads ) { actLst.clear(); extract( threads, (withTraces) ? actLst : null, IProf.MON_THREAD_METHODS, iprof ); if( withTraces ) { extract( actLst, null, IProf.MON_THREAD_METHOD_TRACES, iprof ); } } } //?//PENDING //if ( withArenas ) { // extract( null, arenas, IProf.ARENAS ); //} if ( withGC ) { extract( null, gcs, IProf.GCS, iprof ); } } catch ( COMMUN_Exception e ) { System.out.println( "Erron in communication\n" ); } catch( Exception e ) { System.out.println( "Just error\n" + e); } long end = System.currentTimeMillis(); System.out.println( "\n\nTime: " + (end - start) ); } ////////////////////////////////////////////////////////////////////////// public int getThreadCount() { return threads.size(); } /** * Returns time when this snapshot was made. * * @return time when this snapshot was made. */ public long time() { return time; } /** * Performes monitor dump of the mirrored virtual machine. * A {@link MonitorInfo} object is included for all monitors * existing in the mirrored virtual machine. * * @return a <code>List</code> of {@link MonitorInfo} objects representing * monitors in the mirrored virtual machine. */ public List dumpMonitors() { //PENDIG return null; } /** * Returns size (in bytes) of free memory in the mirrored virtual machine. * * @return size (in bytes) of free memory in the mirrored virtual machine. */ public long freeMemory() { //PENDIG return 0; } /** * Returns <code>index</code>-th loaded type by the mirrored virtual machine. * * @param index index of some loaded type by the mirrored virtual machine. * @return a {@link ReferenceType} object representing <code>index</code>-th * loaded type by the mirrored virtual machine. */ public ReferenceType getClass(int index) { //PENDING //return classes.get( index ); return null; } /** * Returns number of all loaded types by the mirrored virtual machine. * * @return number of all loaded types by the mirrored virtual machine. */ public int getClassCount() { return classes.size(); } /** * Returns a list of the currently running threads. For each running thread * in the target VM, a {@link ThreadInfo} that holds information about it * is placed in the list. The returned list contains threads created through * <code>Thread</code>, all native threads attached to the target * VM through JNI, and system threads created by the target VM. * <p>Thread objects that have not yet been started * (through <code>Thread.start()</code>) and thread objects that * have completed their execution are not included in the returned list. * * @return a <code>List</code> of {@link ThreadInfo} objects, one for each * running thread in the mirrored VM. */ public List threads() { return threads; } /** * Sets name of this snapshot. * * @param name name of this snapshot. */ public void setName(String name) { this.name = name; } /** * Returns all loaded types. For each loaded type in the target VM * a {@link ReferenceType} will be placed in the returned list. The list * will include <code>ReferenceTypes</code> which mirror classes, interfaces, * and array types. * * @return a <code>List</code> of {@link ReferenceType} objects, each * mirroring a loaded type in the target VM. */ public List classes() { return classes; } /** * Returns size (in bytes) of allocated memory in the mirrored virtual * machine. * * @return size (in bytes) of allocated memory in the mirrored virtual * machine. */ public long totalMemory() { //PENDING return 0; } /** * Gets name of this snapshot. * * @return name of this snapshot. */ public String getName() { return name; } /** * Performed heap dump of the mirrored virtual machine. * * @return a {@link net.sourceforge.javaprofiler.jpi.dump.HeapDump} object * representing the content of the memory of the mirrored virtual machine. */ public HeapDump dumpHeap() { //PENDING return null; } ////////////////////////////////////////////////////////////////////////////// // Private methods ////////////////////////////////////////////////////////////////////////////// /* *You can't call following method in any order you think *You have to extract more general objects first! *This methods directly uses mirror strucutre and libIDs. */ /* Maybe rewrite it with direct use of commun.Commun and commun.Buffer *(data classes will have constructors for Buffer) */ private void extract( List in, List out, int whatType, IProf iprof ) throws COMMUN_Exception { //trhows boolean pass = false; ListIterator iter, iterInner; IProf.sID sid; LinkedList listInner; IDObjectData obj, objInner, objOpposite; if ( in != null ) { pass = true; iter = null; } else { iter = in.listIterator(); } try { //add hashtables for IDs (temporary) while( pass || iter.hasNext() ) { //IProf.sID sid = (IProf.sID) ((IDObjectData) in.next()).getID; //IProf.sInfo ci = (IProf.sClassInfo)iprof.getInfo( sid.infoId, IProf.CLASS_INFO); if ( iter == null ) { listInner = iprof.getAll( 0, whatType ); pass = false; obj = null; } else{ obj = (IDObjectData) iter.next(); listInner = iprof.getAll( obj.getID(), whatType ); } //Prof.sInfo will be in IProf.sId //fill in the former calling, there will be special param iterInner = listInner.listIterator(); while( iterInner.hasNext() ) { sid = (IProf.sID) iterInner.next(); //this could by factory objInner = createAndPutIn( whatType, sid, obj ); libIDs.put( new Integer(objInner.getID()), objInner ); if ( out != null ) out.add( objInner ); } } } //PENDING trow other exception catch ( BAD_OBJ_ID_Exception e ) { System.out.println( "Bad objID\n" ); } /* catch ( BAD_INFO_ID_Exception e ) { System.out.println( "Bad infoID\n" ); } catch ( BAD_INFO_TYPE_Exception e ) { System.out.println( "Bad info type\n" ); }*/ catch ( BAD_COMMAND_Exception e ) { System.out.println( "Bad command\n" ); } catch ( UNKNOWN_Exception e ) { System.out.println( "Uknown exception\n" ); } }; private static IDObjectData createAndPutIn( int whatType, IProf.sID sid, IDObjectData refObj ) { switch( whatType ) { case IProf.CLASSES: { return new ClassData( sid ); } case IProf.OBJECT_TYPES: { return new AllocClassData( sid, null ); //sid.info.left } // case IProf.THREADS: { //??should I support this? // return new ThreadData( sid ); // break; // } case IProf.GROUPS_OF_THREADS: { return new ThreadGroupData( sid ); } case IProf.ARENAS: { return new AllocArenaData( sid ); } case IProf.GCS: { return new GCData( sid ); } case IProf.GROUP_THREADS: { ThreadGroupData rf = (ThreadGroupData) refObj; ThreadData newObj = new ThreadData( sid, rf, null ); //?z info rf.addThread( newObj ); //PENDING connect to object from sid.info return newObj; } // case IProf.CLASS_FIELDS_STATICS: return new ClassData( sid ); // case IProf.CLASS_FIELDS_INSTANCES: return new ClassData( sid ); // case IProf.CLASS_METHODS: { //shoul I support this // return new MethodData( sid ); // break; // } case IProf.ALLOC_METHOD_TRACES: { MethodData rf = (MethodData) refObj; AllocTraceData newObj = new AllocTraceData( sid, rf ); rf.addAllocTrace( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.ALLOC_METHOD_OBJECTS: { MethodData rf = (MethodData) refObj; AllocClassMethodData newObj = new AllocClassMethodData( sid, null, rf ); //sid.info.up rf.addClass( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.ALLOC_OBJECT_METHODS: { AllocClassData rf = (AllocClassData) refObj; AllocClassMethodData newObj = new AllocClassMethodData( sid, rf, null ); //sid.info.left rf.addMethod( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.ALLOC_TRACE_OBJECTS: { AllocTraceData rf = (AllocTraceData) refObj; AllocClassTraceData newObj = new AllocClassTraceData( sid, null, rf ); //sid.info.left rf.addClass( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.ALLOC_OBJECT_METHOD_TRACES:{ AllocClassMethodData rf = (AllocClassMethodData) refObj; AllocClassTraceData newObj = new AllocClassTraceData( sid, rf, null ); //sid.info.left rf.addTrace( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.ALLOC_OBJECT_THREADS: { AllocClassData rf = (AllocClassData) refObj; AllocThreadClassData newObj = new AllocThreadClassData( sid, null, rf ); //sid.info.left] rf.addThread( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.ALLOC_THREAD_OBJECTS: { ThreadData rf = (ThreadData) refObj; AllocThreadClassData newObj = new AllocThreadClassData( sid, rf, null ); //sid.info.left rf.addClass( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.ALLOC_OBJECT_METHOD_THREADS:{ AllocClassMethodData rf =(AllocClassMethodData) refObj; AllocThreadClassMethodData newObj = new AllocThreadClassMethodData( sid, null, rf, null ); //sid.info.left rf.addThread( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.ALLOC_THREAD_OBJECT_METHODS:{ AllocThreadClassData rf = (AllocThreadClassData) refObj; AllocThreadClassMethodData newObj = new AllocThreadClassMethodData( sid, rf, null, null ); //sid.info.left rf.addMethod( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.ALLOC_THREAD_METHOD_OBJECTS:{ AllocThreadMethodData rf = (AllocThreadMethodData) refObj; AllocThreadClassMethodData newObj = new AllocThreadClassMethodData( sid, null, null, rf ); //sid.info.left rf.addClass( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.ALLOC_OBJECT_METHOD_TRACE_THREADS:{ AllocClassTraceData rf = (AllocClassTraceData) refObj; AllocThreadClassTraceData newObj = new AllocThreadClassTraceData( sid, rf, null, null ); //sid.info.left rf.addThread( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.ALLOC_THREAD_METHOD_TRACE_OBJECTS:{ AllocThreadTraceData rf = (AllocThreadTraceData) refObj; AllocThreadClassTraceData newObj = new AllocThreadClassTraceData( sid, null, null, rf ); //sid.info.left rf.addClass( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.ALLOC_THREAD_OBJECT_METHOD_TRACES:{ AllocThreadClassMethodData rf = (AllocThreadClassMethodData) refObj; AllocThreadClassTraceData newObj = new AllocThreadClassTraceData( sid, null, rf, null ); //sid.info.left rf.addTrace( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.ALLOC_THREAD_METHODS: { ThreadData rf =(ThreadData) refObj; AllocThreadMethodData newObj = new AllocThreadMethodData( sid, rf, null ); //sid.info.left rf.addAllocMethod( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.ALLOC_THREAD_METHOD_TRACES:{ AllocThreadMethodData rf = (AllocThreadMethodData) refObj; AllocThreadTraceData newObj = new AllocThreadTraceData( sid, rf, null ); //sid.info.left rf.addTrace( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.CPU_METHOD_TRACES: { MethodData rf = (MethodData) refObj; CPUTraceData newObj = new CPUTraceData( sid, rf ); rf.addCPUTrace( newObj ); return newObj; } case IProf.CPU_METHOD_THREADS: { MethodData rf = (MethodData) refObj; CPUThreadMethodData newObj = new CPUThreadMethodData( sid, null, rf ); //sid.info.left rf.addCPUThread( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.CPU_THREAD_METHODS: { ThreadData rf = (ThreadData) refObj; CPUThreadMethodData newObj = new CPUThreadMethodData( sid, rf, null ); //sid.info.left rf.addCPUMethod( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.CPU_METHOD_TRACE_THREADS:{ CPUTraceData rf = (CPUTraceData) refObj; CPUThreadTraceData newObj = new CPUThreadTraceData( sid, null, rf ); //sid.info.left rf.addThread( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.CPU_THREAD_METHOD_TRACES:{ CPUThreadMethodData rf = (CPUThreadMethodData) refObj; CPUThreadTraceData newObj = new CPUThreadTraceData( sid, rf, null ); //sid.info.left rf.addTrace( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.MON_METHOD_TRACES: { MethodData rf = (MethodData) refObj; MonTraceData newObj = new MonTraceData( sid, rf ); rf.addMonTrace( newObj ); return newObj; } case IProf.MON_METHOD_THREADS: { MethodData rf = (MethodData) refObj; MonThreadMethodData newObj = new MonThreadMethodData( sid, null, rf ); //sid.info.left rf.addMonThread( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.MON_THREAD_METHODS: { ThreadData rf = (ThreadData) refObj; MonThreadMethodData newObj = new MonThreadMethodData( sid, rf, null ); //sid.info.left rf.addMonMethod( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.MON_METHOD_TRACE_THREADS:{ MonTraceData rf = (MonTraceData) refObj; MonThreadTraceData newObj = new MonThreadTraceData( sid, null, rf ); //sid.info.left rf.addThread( newObj ); //PENDING connect to object from sid.info return newObj; } case IProf.MON_THREAD_METHOD_TRACES:{ MonThreadMethodData rf = (MonThreadMethodData) refObj; MonThreadTraceData newObj = new MonThreadTraceData( sid, rf, null ); //sid.info.left rf.addTrace( newObj ); //PENDING connect to object from sid.info return newObj; } // case IProf.MON_TRACES: return new ClassData( sid ); //PENDING default: return null; //throw some excetion } }; //toString() ////copy debuging printf from library } //?? //Constrocts for Data object from Buffer //concting to tree in obejcts? //TODO: // write exception handling code properly /* * $Log: SnapshotImpl.java,v $ * Revision 1.1 2001/11/20 22:31:45 vachis * Snapshot implementation * */ |