From: Marek P. <ma...@us...> - 2001-11-21 22:32:16
|
Update of /cvsroot/javaprofiler/library/src/cpu In directory usw-pr-cvs1:/tmp/cvs-serv12170/src/cpu Modified Files: Makefile.rules cpuStack.cpp cpuStack.h cpuStatData.cpp cpuStatData.h cpuThreadMethod.cpp cpuThreadMethod.h cpuThreadTrace.cpp cpuThreadTrace.h cpuTrace.cpp cpuTrace.h dir.info sampling.cpp sampling.h Added Files: cpuThreadMethodKey.h cpuThreadTraceKey.h Log Message: some parts completely rewritten; changes in communication interface to make it faster; ported to linux --- NEW FILE: cpuThreadMethodKey.h --- /* * 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. */ #ifndef _CPU_THREAD_METHOD_KEY_H_ #define _CPU_THREAD_METHOD_KEY_H_ #include "../main/includes.h" /** Key for CpuThreadMethod class. ** Used for searching in hash tables. ** ** @author Petr Luner */ struct CpuThreadMethodKey { /// thread ID JNIEnv* envId; /// method ID jmethodID methodId; }; #endif // _CPU_THREAD_METHOD_KEY_H_ --- NEW FILE: cpuThreadTraceKey.h --- /* * 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. */ #ifndef _CPU_THREAD_TRACE_KEY_H_ #define _CPU_THREAD_TRACE_KEY_H_ #include "../main/includes.h" #include "../shared/traceKey.h" /** Key for CpuThreadTrace class. ** Used for searching in hash tables. ** ** @author Petr Luner */ struct CpuThreadTraceKey { /// thread ID JNIEnv* envId; /// trace key TraceKey traceKey; }; #endif // _CPU_THREAD_TRACE_KEY_H_ Index: Makefile.rules =================================================================== RCS file: /cvsroot/javaprofiler/library/src/cpu/Makefile.rules,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** Makefile.rules 2001/07/30 15:41:26 1.3 --- Makefile.rules 2001/11/21 22:31:42 1.4 *************** *** 1,23 **** cpuStack.o \ ! cpuStack.obj: cpuStack.cpp ../main/includes.h $(CCC) $(CPPFLAGS) cpuStack.cpp cpuStatData.o \ ! cpuStatData.obj: cpuStatData.cpp ../main/includes.h $(CCC) $(CPPFLAGS) cpuStatData.cpp cpuTrace.o \ ! cpuTrace.obj: cpuTrace.cpp ../main/includes.h $(CCC) $(CPPFLAGS) cpuTrace.cpp cpuThreadMethod.o \ ! cpuThreadMethod.obj: cpuThreadMethod.cpp ../main/includes.h $(CCC) $(CPPFLAGS) cpuThreadMethod.cpp cpuThreadTrace.o \ ! cpuThreadTrace.obj: cpuThreadTrace.cpp ../main/includes.h $(CCC) $(CPPFLAGS) cpuThreadTrace.cpp sampling.o \ ! sampling.obj: sampling.cpp ../main/includes.h $(CCC) $(CPPFLAGS) sampling.cpp --- 1,23 ---- cpuStack.o \ ! cpuStack.obj: cpuStack.cpp $(CCC) $(CPPFLAGS) cpuStack.cpp cpuStatData.o \ ! cpuStatData.obj: cpuStatData.cpp $(CCC) $(CPPFLAGS) cpuStatData.cpp cpuTrace.o \ ! cpuTrace.obj: cpuTrace.cpp $(CCC) $(CPPFLAGS) cpuTrace.cpp cpuThreadMethod.o \ ! cpuThreadMethod.obj: cpuThreadMethod.cpp $(CCC) $(CPPFLAGS) cpuThreadMethod.cpp cpuThreadTrace.o \ ! cpuThreadTrace.obj: cpuThreadTrace.cpp $(CCC) $(CPPFLAGS) cpuThreadTrace.cpp sampling.o \ ! sampling.obj: sampling.cpp $(CCC) $(CPPFLAGS) sampling.cpp Index: cpuStack.cpp =================================================================== RCS file: /cvsroot/javaprofiler/library/src/cpu/cpuStack.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** cpuStack.cpp 2001/09/02 20:14:21 1.3 --- cpuStack.cpp 2001/11/21 22:31:42 1.4 *************** *** 33,37 **** */ ! #include "../main/includes.h" CpuStack::~CpuStack() { --- 33,37 ---- */ ! #include "../cpu/cpuStack.h" CpuStack::~CpuStack() { *************** *** 78,80 **** size = newSize; } - --- 78,79 ---- Index: cpuStack.h =================================================================== RCS file: /cvsroot/javaprofiler/library/src/cpu/cpuStack.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** cpuStack.h 2001/09/02 20:14:21 1.3 --- cpuStack.h 2001/11/21 22:31:42 1.4 *************** *** 36,43 **** #define _CPU_STACK_H_ /** Stack for CPU profiling purposes. ** Essentially this class represents an image of a thread call ** stack and serves for recording method entry times and other ! ** information needed for computation of method total and pure ** time consumation. The events JVMPI_EVENT_METHOD_ENTRY and ** JVMPI_EVENT_METHOD_EXIT are used to update the stack --- 36,45 ---- #define _CPU_STACK_H_ + #include "../main/includes.h" + /** Stack for CPU profiling purposes. ** Essentially this class represents an image of a thread call ** stack and serves for recording method entry times and other ! ** information needed for computing of method total and pure ** time consumation. The events JVMPI_EVENT_METHOD_ENTRY and ** JVMPI_EVENT_METHOD_EXIT are used to update the stack *************** *** 49,53 **** class CpuStack { - private: /// Internal stack frame --- 51,54 ---- *************** *** 63,85 **** jlong calleesTime; }; ! // stack array Frame* stack; ! // stack size long size; ! // top stack index long top; public: ! /// Constructor ! CpuStack() { ! stack = NULL; ! size = 0; ! top = -1; ! } /// Destructor --- 64,89 ---- jlong calleesTime; }; + + private: ! /// stack array Frame* stack; ! /// stack size long size; ! /// top stack index long top; public: + + /// Default constructor. + CpuStack() : ! stack( NULL), ! size( 0), ! top( -1) ! {} /// Destructor *************** *** 88,108 **** /** Pushes method call on the stack. ** ! ** @param callFrame JVMPI method call frame ! ** @param entryTime time of method entry */ ! void push(JVMPI_CallFrame& callFrame, jlong entryTime); /** Bills the cost of a top method and pops it from the stack. ** ! ** @param exitTime top method exit time ! ** @param totalTime total time consumed by top method ! ** @param pureTime pure time consumed by top method */ ! void pop(jlong exitTime, jlong& totalTime, jlong& pureTime); /** Gets top call trace. ** ! ** @param maxFrames maximum frames to return ! ** @param frames buffer for returned frames ** ** @return number of frames returned */ --- 92,112 ---- /** Pushes method call on the stack. ** ! ** @param callFrame JVMPI method call frame ! ** @param entryTime time of method entry */ ! void push( JVMPI_CallFrame& callFrame, jlong entryTime); /** Bills the cost of a top method and pops it from the stack. ** ! ** @param exitTime top method exit time ! ** @param totalTime total time consumed by top method ! ** @param pureTime pure time consumed by top method */ ! void pop( jlong exitTime, jlong& totalTime, jlong& pureTime); /** Gets top call trace. ** ! ** @param maxFrames maximum frames to return ! ** @param frames buffer for returned frames ** ** @return number of frames returned */ *************** *** 117,119 **** #endif // _CPU_STACK_H_ - --- 121,122 ---- Index: cpuStatData.cpp =================================================================== RCS file: /cvsroot/javaprofiler/library/src/cpu/cpuStatData.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** cpuStatData.cpp 2001/09/02 20:14:21 1.6 --- cpuStatData.cpp 2001/11/21 22:31:42 1.7 *************** *** 33,37 **** */ ! #include "../main/includes.h" void CpuStatData::addCpuStat(jlong addHits, jlong addPureTime) { --- 33,37 ---- */ ! #include "../cpu/cpuStatData.h" void CpuStatData::addCpuStat(jlong addHits, jlong addPureTime) { Index: cpuStatData.h =================================================================== RCS file: /cvsroot/javaprofiler/library/src/cpu/cpuStatData.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** cpuStatData.h 2001/09/23 16:50:15 1.7 --- cpuStatData.h 2001/11/21 22:31:42 1.8 *************** *** 36,39 **** --- 36,44 ---- #define _CPU_STAT_DATA_H_ + #include "../main/includes.h" + #include "../commun/binaryFormat.h" + #include "../commun/statDataModification.h" + #include "../commun/buffer.h" + /** CPU statistics data. ** Used as a base class for other classes to hold CPU usage *************** *** 46,50 **** class CpuStatData: public DataBinaryFormat, public StatDataModification { - public: --- 51,54 ---- *************** *** 57,84 **** public: ! /** Constructor. ** Performs statistics initialization. */ ! CpuStatData() { ! pureTime = (jlong)0; ! hits = (jlong)0; ! }; /** Updates statistics. ** ! ** @param addHits number of hits to be added ! ** @param addPureTime pure time to be added */ ! virtual void addCpuStat(jlong addHits, jlong addPureTime); /** Converts statistics data to a binary format used ** for communication with client. ** ! ** @param b buffer where to append data ** ** @return reference to same Buffer object as argument 'b' */ ! virtual Buffer& dataToBin(Buffer& b); public: --- 61,92 ---- public: ! /** Default constructor. ** Performs statistics initialization. */ + + CpuStatData() : ! pureTime( 0), ! hits( 0) ! {} + /// Destructor. + virtual ~CpuStatData() {} + /** Updates statistics. ** ! ** @param addHits number of hits to be added ! ** @param addPureTime pure time to be added */ ! virtual void addCpuStat( jlong addHits, jlong addPureTime); /** Converts statistics data to a binary format used ** for communication with client. ** ! ** @param b buffer where to append data ** ** @return reference to same Buffer object as argument 'b' */ ! virtual Buffer& dataToBin( Buffer& b); public: *************** *** 90,92 **** #endif // _CPU_STAT_DATA_H_ - --- 98,99 ---- Index: cpuThreadMethod.cpp =================================================================== RCS file: /cvsroot/javaprofiler/library/src/cpu/cpuThreadMethod.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** cpuThreadMethod.cpp 2001/09/18 22:19:28 1.7 --- cpuThreadMethod.cpp 2001/11/21 22:31:42 1.8 *************** *** 33,40 **** */ ! #include "../main/includes.h" - Allocator CpuThreadMethod::_allocator( sizeof( CpuThreadMethod)); - void CpuThreadMethod::addCpuStat(jlong addHits, jlong addPureTime) { --- 33,45 ---- */ ! #include "../cpu/cpuThreadMethod.h" ! #include "../shared/method.h" ! #include "../prof/prof.h" ! #include "../cpu/cpuThreadTrace.h" ! ! #ifdef USE_ALLOCATOR ! Allocator CpuThreadMethod::_allocator; ! #endif void CpuThreadMethod::addCpuStat(jlong addHits, jlong addPureTime) { *************** *** 52,54 **** --- 57,88 ---- tt = threadTraces.next(tt); } + } + + const CpuThreadMethodKey& CpuThreadMethod::getKey( CpuThreadMethodKey& key) { + + thread->getKey(key.envId); + method->getKey(key.methodId); + + return key; + } + + int CpuThreadMethod::operator==( const CpuThreadMethodKey& key) { + + return (*thread == key.envId) && (*method == key.methodId); + } + + int CpuThreadMethod::hashKey( const CpuThreadMethodKey& key) { + + return Thread::hashKey(key.envId) ^ Method::hashKey(key.methodId); + } + + int CpuThreadMethod::isActive() { + + return (method->isActive() && thread->isActive()); + } + + void CpuThreadMethod::setUnchanged() { + + IdObject::setUnchanged(); + clearDataChanged(); } Index: cpuThreadMethod.h =================================================================== RCS file: /cvsroot/javaprofiler/library/src/cpu/cpuThreadMethod.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -r1.9 -r1.10 *** cpuThreadMethod.h 2001/09/02 20:14:21 1.9 --- cpuThreadMethod.h 2001/11/21 22:31:42 1.10 *************** *** 36,53 **** #define _CPU_THREAD_METHOD_H_ ! /** Key for CpuThreadMethod class. ! ** Used for searching in hash tables. ! ** ! ** @author Petr Luner */ ! ! struct CpuThreadMethodKey { - /// thread ID - JNIEnv* envId; - - /// method ID - jmethodID methodId; - }; - /** Crossroad of threads and methods for CPU profiling. ** This class consists of statistic information about --- 36,48 ---- #define _CPU_THREAD_METHOD_H_ ! #include "../main/includes.h" ! #include "../list/listItem.h" ! #include "../commun2/idObject.h" ! #include "../cpu/cpuStatData.h" ! #include "../list/list.h" ! #include "../cpu/cpuThreadTrace.h" ! #include "../cpu/cpuThreadMethodKey.h" ! #include "../allocator/allocator.h" /** Crossroad of threads and methods for CPU profiling. ** This class consists of statistic information about *************** *** 58,66 **** ** @author Petr Luner */ ! class CpuThreadMethod: public IdObject, ! public LI1, ! public LI2, ! public LI3, ! public CpuStatData { public: --- 53,61 ---- ** @author Petr Luner */ ! class CpuThreadMethod: public LI1, ! public LI2, ! public LI3, ! public IdObject, ! public CpuStatData { public: *************** *** 81,112 **** method( NULL), thread( NULL) ! {}; /** Updates CPU statistics. ** Also updates CPU statistics of corresponding method. ** ! ** @param addHits number of hits to be added ! ** @param addPureTime pure time to be added */ ! virtual void addCpuStat(jlong addHits, jlong addPureTime); /** Retrieves object's key. ** ! ** @param key where to store the key ! ** @return key ** ** @see Hash */ ! const CpuThreadMethodKey& getKey(CpuThreadMethodKey& key) { ! ! thread->getKey(key.envId); ! method->getKey(key.methodId); ! return key; ! } /** Compares object with given key. ** ** @param key key ** @return 1 (true); ** 0 (false) --- 76,107 ---- method( NULL), thread( NULL) + + {} ! /// Destructor. ! virtual ~CpuThreadMethod() {} /** Updates CPU statistics. ** Also updates CPU statistics of corresponding method. ** ! ** @param addHits number of hits to be added ! ** @param addPureTime pure time to be added */ ! virtual void addCpuStat( jlong addHits, jlong addPureTime); /** Retrieves object's key. ** ! ** @param key where to store the key ** + ** @return key + ** ** @see Hash */ ! const CpuThreadMethodKey& getKey( CpuThreadMethodKey& key); /** Compares object with given key. ** ** @param key key + ** ** @return 1 (true); ** 0 (false) *************** *** 114,131 **** ** @see Hash */ ! int operator==(const CpuThreadMethodKey& key) { ! ! return (*thread == key.envId) && (*method == key.methodId); ! } /** Hash function. ** ! ** @param reference to a key ** @return hash value */ - - static int hashKey(const CpuThreadMethodKey& key) { ! return Thread::hashKey(key.envId) ^ Method::hashKey(key.methodId); ! } /** Performs deactivation. */ --- 109,121 ---- ** @see Hash */ ! int operator==( const CpuThreadMethodKey& key); /** Hash function. ** ! ** @param key reference to a key ! ** ** @return hash value */ ! static int hashKey( const CpuThreadMethodKey& key); /** Performs deactivation. */ *************** *** 133,136 **** --- 123,127 ---- void deactivate(); + #ifdef USE_ALLOCATOR private: *************** *** 142,150 **** /** Overloaded new() operator. */ ! void* operator new( size_t) { return _allocator.get();} /** Overloaded delete() operator. */ void operator delete( void* unit) { _allocator.put( unit);} public: --- 133,142 ---- /** Overloaded new() operator. */ ! void* operator new( size_t sz) { return _allocator.get( sz);} /** Overloaded delete() operator. */ void operator delete( void* unit) { _allocator.put( unit);} + #endif public: *************** *** 152,156 **** /** Class identification. ** ! ** @return unique class type identified */ virtual eClassIdent getClassIdent() { return CPU_THREAD_METHOD;} --- 144,148 ---- /** Class identification. ** ! ** @return unique class type identifier */ virtual eClassIdent getClassIdent() { return CPU_THREAD_METHOD;} *************** *** 162,166 **** ** 1 (active) */ ! virtual int isActive() { return (method->isActive() && thread->isActive());} /** Indication that object has changed its data. --- 154,158 ---- ** 1 (active) */ ! virtual int isActive(); /** Indication that object has changed its data. *************** *** 173,181 **** /** Set the structure is unchanged although it may not be. */ ! virtual void setUnchanged() { ! ! IdObject::setUnchanged(); ! clearDataChanged(); ! } }; --- 165,169 ---- /** Set the structure is unchanged although it may not be. */ ! virtual void setUnchanged(); }; Index: cpuThreadTrace.cpp =================================================================== RCS file: /cvsroot/javaprofiler/library/src/cpu/cpuThreadTrace.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** cpuThreadTrace.cpp 2001/09/18 22:19:28 1.7 --- cpuThreadTrace.cpp 2001/11/21 22:31:42 1.8 *************** *** 33,39 **** */ ! #include "../main/includes.h" ! Allocator CpuThreadTrace::_allocator( sizeof( CpuThreadTrace)); void CpuThreadTrace::addCpuStat(jlong addHits, jlong addPureTime) { --- 33,44 ---- */ ! #include "../cpu/cpuThreadTrace.h" ! #include "../cpu/cpuThreadMethod.h" ! #include "../cpu/cpuTrace.h" ! #include "../prof/prof.h" ! #ifdef USE_ALLOCATOR ! Allocator CpuThreadTrace::_allocator; ! #endif void CpuThreadTrace::addCpuStat(jlong addHits, jlong addPureTime) { *************** *** 47,49 **** --- 52,82 ---- Prof::prof().activeCpuThreadTraces.removeNoRehash(this); + } + + const CpuThreadTraceKey& CpuThreadTrace::getKey(CpuThreadTraceKey& key) { + + threadMethod->thread->getKey(key.envId); + trace->getKey(key.traceKey); + return key; + } + + int CpuThreadTrace::operator==(const CpuThreadTraceKey& key) { + + return (*threadMethod->thread == key.envId) && (*trace == key.traceKey); + } + + int CpuThreadTrace::hashKey(const CpuThreadTraceKey& key) { + + return Thread::hashKey(key.envId) ^ Trace::hashKey(key.traceKey); + } + + int CpuThreadTrace::isActive() { + + return (trace->isActive() && threadMethod->isActive()); + } + + void CpuThreadTrace::setUnchanged() { + + IdObject::setUnchanged(); + clearDataChanged(); } Index: cpuThreadTrace.h =================================================================== RCS file: /cvsroot/javaprofiler/library/src/cpu/cpuThreadTrace.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -r1.9 -r1.10 *** cpuThreadTrace.h 2001/09/02 20:14:21 1.9 --- cpuThreadTrace.h 2001/11/21 22:31:42 1.10 *************** *** 36,53 **** #define _CPU_THREAD_TRACE_H_ ! /** Key for CpuThreadTrace class. ! ** Used for searching in hash tables. ! ** ! ** @author Petr Luner */ ! ! struct CpuThreadTraceKey { - /// thread ID - JNIEnv* envId; - - /// trace key - TraceKey traceKey; - }; - /** Crossroad of threads and traces for CPU profiling. ** This class consists of statistic information about --- 36,46 ---- #define _CPU_THREAD_TRACE_H_ ! #include "../main/includes.h" ! #include "../list/listItem.h" ! #include "../commun2/idObject.h" ! #include "../cpu/cpuStatData.h" ! #include "../cpu/cpuThreadTraceKey.h" ! #include "../allocator/allocator.h" /** Crossroad of threads and traces for CPU profiling. ** This class consists of statistic information about *************** *** 58,66 **** ** @author Petr Luner */ ! class CpuThreadTrace: public IdObject, ! public LI1, ! public LI2, ! public LI3, ! public CpuStatData { public: --- 51,59 ---- ** @author Petr Luner */ ! class CpuThreadTrace: public LI1, ! public LI2, ! public LI3, ! public IdObject, ! public CpuStatData { public: *************** *** 78,83 **** threadMethod( NULL), trace( NULL) ! {}; /** Updates CPU statistics. --- 71,79 ---- threadMethod( NULL), trace( NULL) + + {} ! /// Destructor. ! virtual ~CpuThreadTrace() {} /** Updates CPU statistics. *************** *** 85,110 **** ** and CpuThreadMethod. ** ! ** @param addHits number of hits to be added ! ** @param addPureTime pure time to be added */ ! virtual void addCpuStat(jlong addHits, jlong addPureTime); /** Retrieves object's key. ** ! ** @param key where to store the key ** @return key ** ** @see Hash */ ! const CpuThreadTraceKey& getKey(CpuThreadTraceKey& key) { ! ! threadMethod->thread->getKey(key.envId); ! trace->getKey(key.traceKey); ! return key; ! } /** Compares object with given key. ** ** @param key key ** @return 1 (true); ** 0 (false) --- 81,103 ---- ** and CpuThreadMethod. ** ! ** @param addHits number of hits to be added ! ** @param addPureTime pure time to be added */ ! virtual void addCpuStat( jlong addHits, jlong addPureTime); /** Retrieves object's key. ** ! ** @param key where to store the key ! ** ** @return key ** ** @see Hash */ ! const CpuThreadTraceKey& getKey( CpuThreadTraceKey& key); /** Compares object with given key. ** ** @param key key + ** ** @return 1 (true); ** 0 (false) *************** *** 112,129 **** ** @see Hash */ ! int operator==(const CpuThreadTraceKey& key) { ! ! return (*threadMethod->thread == key.envId) && (*trace == key.traceKey); ! } /** Hash function. ** ! ** @param reference to a key ** @return hash value */ - - static int hashKey(const CpuThreadTraceKey& key) { ! return Thread::hashKey(key.envId) ^ Trace::hashKey(key.traceKey); ! } /** Performs deactivation. */ --- 105,117 ---- ** @see Hash */ ! int operator==( const CpuThreadTraceKey& key); /** Hash function. ** ! ** @param key reference to a key ! ** ** @return hash value */ ! static int hashKey( const CpuThreadTraceKey& key); /** Performs deactivation. */ *************** *** 131,134 **** --- 119,123 ---- void deactivate(); + #ifdef USE_ALLOCATOR private: *************** *** 140,148 **** /** Overloaded new() operator. */ ! void* operator new( size_t) { return _allocator.get();} /** Overloaded delete() operator. */ void operator delete( void* unit) { _allocator.put( unit);} public: --- 129,138 ---- /** Overloaded new() operator. */ ! void* operator new( size_t sz) { return _allocator.get( sz);} /** Overloaded delete() operator. */ void operator delete( void* unit) { _allocator.put( unit);} + #endif public: *************** *** 150,154 **** /** Class identification. ** ! ** @return unique class type identified */ virtual eClassIdent getClassIdent() { return CPU_THREAD_TRACE;} --- 140,144 ---- /** Class identification. ** ! ** @return unique class type identifier */ virtual eClassIdent getClassIdent() { return CPU_THREAD_TRACE;} *************** *** 160,164 **** ** 1 (active) */ ! virtual int isActive() { return (trace->isActive() && threadMethod->isActive());} /** Indication that object has changed its data. --- 150,154 ---- ** 1 (active) */ ! virtual int isActive(); /** Indication that object has changed its data. *************** *** 171,179 **** /** Set the structure is unchanged although it may not be. */ ! virtual void setUnchanged() { ! ! IdObject::setUnchanged(); ! clearDataChanged(); ! } }; --- 161,165 ---- /** Set the structure is unchanged although it may not be. */ ! virtual void setUnchanged(); }; Index: cpuTrace.cpp =================================================================== RCS file: /cvsroot/javaprofiler/library/src/cpu/cpuTrace.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** cpuTrace.cpp 2001/09/18 22:19:28 1.7 --- cpuTrace.cpp 2001/11/21 22:31:42 1.8 *************** *** 33,39 **** */ ! #include "../main/includes.h" ! Allocator CpuTrace::_allocator( sizeof( CpuTrace)); void CpuTrace::addCpuStat(jlong addHits, jlong addPureTime) { --- 33,43 ---- */ ! #include "../cpu/cpuTrace.h" ! #include "../shared/method.h" ! #include "../prof/prof.h" ! #ifdef USE_ALLOCATOR ! Allocator CpuTrace::_allocator; ! #endif void CpuTrace::addCpuStat(jlong addHits, jlong addPureTime) { *************** *** 46,48 **** --- 50,63 ---- Prof::prof().activeCpuTraces.removeNoRehash(this); + } + + int CpuTrace::isActive() { + + return method->isActive(); + } + + void CpuTrace::setUnchanged() { + + IdObject::setUnchanged(); + clearDataChanged(); } Index: cpuTrace.h =================================================================== RCS file: /cvsroot/javaprofiler/library/src/cpu/cpuTrace.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -r1.9 -r1.10 *** cpuTrace.h 2001/09/02 20:14:21 1.9 --- cpuTrace.h 2001/11/21 22:31:42 1.10 *************** *** 36,39 **** --- 36,48 ---- #define _CPU_TRACE_H_ + #include "../main/includes.h" + #include "../list/listItem.h" + #include "../commun2/idObject.h" + #include "../shared/trace.h" + #include "../cpu/cpuStatData.h" + #include "../list/list.h" + #include "../cpu/cpuThreadTrace.h" + #include "../allocator/allocator.h" + /** Trace for CPU profiling. ** We decided to use different traces *************** *** 44,52 **** ** @author Petr Luner */ ! class CpuTrace: public IdObject, ! public LI1, ! public LI2, public Trace, ! public CpuStatData { public: --- 53,61 ---- ** @author Petr Luner */ ! class CpuTrace: public LI1, ! public LI2, ! public IdObject, public Trace, ! public CpuStatData { public: *************** *** 63,74 **** method( NULL) ! {}; /** Updates CPU statistics. ** Also updates CPU statistics of corresponding method. ** ! ** @param addHits number of hits to be added ! ** @param addPureTime pure time to be added */ virtual void addCpuStat(jlong addHits, jlong addPureTime); --- 72,86 ---- method( NULL) + + {} ! /// Destructor. ! virtual ~CpuTrace() {} /** Updates CPU statistics. ** Also updates CPU statistics of corresponding method. ** ! ** @param addHits number of hits to be added ! ** @param addPureTime pure time to be added */ virtual void addCpuStat(jlong addHits, jlong addPureTime); *************** *** 78,81 **** --- 90,94 ---- void deactivate(); + #ifdef USE_ALLOCATOR private: *************** *** 87,95 **** /** Overloaded new() operator. */ ! void* operator new( size_t) { return _allocator.get();} /** Overloaded delete() operator. */ void operator delete( void* unit) { _allocator.put( unit);} public: --- 100,109 ---- /** Overloaded new() operator. */ ! void* operator new( size_t sz) { return _allocator.get( sz);} /** Overloaded delete() operator. */ void operator delete( void* unit) { _allocator.put( unit);} + #endif public: *************** *** 97,101 **** /** Class identification. ** ! ** @return unique class type identified */ virtual eClassIdent getClassIdent() { return CPU_TRACE;} --- 111,115 ---- /** Class identification. ** ! ** @return unique class type identifier */ virtual eClassIdent getClassIdent() { return CPU_TRACE;} *************** *** 107,111 **** ** 1 (active) */ ! virtual int isActive() { return method->isActive();} /** Indication that object has changed its data. --- 121,125 ---- ** 1 (active) */ ! virtual int isActive(); /** Indication that object has changed its data. *************** *** 118,126 **** /** Set the structure is unchanged although it may not be. */ ! virtual void setUnchanged() { ! ! IdObject::setUnchanged(); ! clearDataChanged(); ! } }; --- 132,136 ---- /** Set the structure is unchanged although it may not be. */ ! virtual void setUnchanged(); }; Index: dir.info =================================================================== RCS file: /cvsroot/javaprofiler/library/src/cpu/dir.info,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** dir.info 2001/07/30 15:41:26 1.4 --- dir.info 2001/11/21 22:31:42 1.5 *************** *** 1,3 **** FILES = cpuStack cpuStatData cpuThreadMethod cpuThreadTrace cpuTrace sampling - CLEAN_FILES = *.pdb *.obj *.o --- 1,2 ---- Index: sampling.cpp =================================================================== RCS file: /cvsroot/javaprofiler/library/src/cpu/sampling.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -r1.9 -r1.10 *** sampling.cpp 2001/09/18 22:19:28 1.9 --- sampling.cpp 2001/11/21 22:31:42 1.10 *************** *** 33,42 **** */ ! #include "../main/includes.h" ! Sampling::Sampling() { _cmd = CMD_TURN_ON; #ifdef WIN32 _turnedOn = CreateEvent(NULL, TRUE, TRUE, NULL); --- 33,54 ---- */ ! #include "../cpu/sampling.h" ! #include "../prof/prof.h" ! #include "../delay/delay.h" ! #include "../prof/synchronized.h" ! #include "../cpu/cpuThreadMethod.h" ! #include "../cpu/cpuThreadTrace.h" ! #include "../cpu/cpuTrace.h" ! Sampling::Sampling( JVMPI_Interface* jvmpi) : + #ifdef USE_RAW_MONITORS + _lock( "_sampling_raw_monitor", jvmpi), + #endif + _terminated( 1) { + _cmd = CMD_TURN_ON; + #ifndef USE_RAW_MONITORS #ifdef WIN32 _turnedOn = CreateEvent(NULL, TRUE, TRUE, NULL); *************** *** 46,49 **** --- 58,62 ---- pthread_mutex_init(&_mutex, NULL); #endif + #endif #ifdef _DEBUG *************** *** 56,59 **** --- 69,73 ---- Sampling::~Sampling() { + #ifndef USE_RAW_MONITORS #ifdef WIN32 CloseHandle(_turnedOn); *************** *** 63,70 **** --- 77,87 ---- pthread_mutex_destroy(&_mutex); #endif + #endif } void Sampling::main() { + _terminated = 0; + Prof* _prof = &Prof::prof(); unsigned long waitTime = 1; *************** *** 74,98 **** unsigned long endTime; ! #ifdef _DEBUG start = Delay::getMilliticks(); ! #endif for (;;) { #ifdef WIN32 - WaitForSingleObject(_turnedOn, INFINITE); - #else - pthread_mutex_lock(&_mutex); while (_cmd == CMD_TURN_OFF) pthread_cond_wait(&_cond, &_mutex); pthread_mutex_unlock(&_mutex); #endif ! if (_cmd == CMD_TERMINATE) return; _prof->gcLock.wait(); _prof->jvmpiInterface->DisableGC(); --- 91,125 ---- unsigned long endTime; ! #ifdef _DEBUG start = Delay::getMilliticks(); ! #endif for (;;) { + #ifndef USE_RAW_MONITORS #ifdef WIN32 WaitForSingleObject(_turnedOn, INFINITE); #else pthread_mutex_lock(&_mutex); while (_cmd == CMD_TURN_OFF) pthread_cond_wait(&_cond, &_mutex); pthread_mutex_unlock(&_mutex); + #endif + #endif + #ifdef USE_RAW_MONITORS + Synchronized sync( _lock); #endif ! if (_cmd == CMD_TERMINATE) { + _terminated = 1; + return; + } + + #ifdef USE_RAW_MONITORS + sync.release(); + #endif + _prof->gcLock.wait(); _prof->jvmpiInterface->DisableGC(); *************** *** 110,116 **** endTime = Delay::getMilliticks(); ! #ifdef _DEBUG finish = endTime; ! #endif _prof->dataLock.release(); --- 137,143 ---- endTime = Delay::getMilliticks(); ! #ifdef _DEBUG finish = endTime; ! #endif _prof->dataLock.release(); *************** *** 136,141 **** int Sampling::startThread(int turnedOn) { #ifdef WIN32 - if (turnedOn) { --- 163,168 ---- int Sampling::startThread(int turnedOn) { + #ifndef USE_RAW_MONITORS #ifdef WIN32 if (turnedOn) { *************** *** 148,157 **** ResetEvent(_turnedOn); } - #else - if (turnedOn) _cmd = CMD_TURN_ON; else _cmd = CMD_TURN_OFF; #endif --- 175,188 ---- ResetEvent(_turnedOn); } #else if (turnedOn) _cmd = CMD_TURN_ON; else _cmd = CMD_TURN_OFF; + #endif + #else + if( !turnedOn) { + _cmd = CMD_TURN_OFF; + return 0; + } #endif *************** *** 163,168 **** void Sampling::terminateThread() { #ifdef WIN32 - EnterCriticalSection(&_cs); --- 194,199 ---- void Sampling::terminateThread() { + #ifndef USE_RAW_MONITORS #ifdef WIN32 EnterCriticalSection(&_cs); *************** *** 171,177 **** LeaveCriticalSection(&_cs); - #else - pthread_mutex_lock(&_mutex); --- 202,206 ---- *************** *** 180,191 **** pthread_mutex_unlock(&_mutex); ! #endif } void Sampling::turnOn() { #ifdef WIN32 - EnterCriticalSection(&_cs); --- 209,223 ---- pthread_mutex_unlock(&_mutex); ! #endif ! #else ! Synchronized sync( _lock); ! _cmd = CMD_TERMINATE; #endif } + #ifndef USE_RAW_MONITORS void Sampling::turnOn() { #ifdef WIN32 EnterCriticalSection(&_cs); *************** *** 197,203 **** LeaveCriticalSection(&_cs); - #else - pthread_mutex_lock(&_mutex); --- 229,233 ---- *************** *** 209,213 **** pthread_mutex_unlock(&_mutex); - #endif } --- 239,242 ---- *************** *** 216,220 **** #ifdef WIN32 - EnterCriticalSection(&_cs); --- 245,248 ---- *************** *** 226,232 **** LeaveCriticalSection(&_cs); - #else - pthread_mutex_lock(&_mutex); --- 254,258 ---- *************** *** 237,243 **** pthread_mutex_unlock(&_mutex); - #endif } void Sampling::doOneSample() { --- 263,269 ---- pthread_mutex_unlock(&_mutex); #endif } + #endif // !USE_RAW_MONITORS void Sampling::doOneSample() { *************** *** 254,260 **** CpuStatData* stat; ! #ifdef _DEBUG samples++; ! #endif if (_prof->setup.cpu.level == Setup::LEVEL_METHOD) traceDepth = 1; --- 280,286 ---- CpuStatData* stat; ! #ifdef _DEBUG samples++; ! #endif if (_prof->setup.cpu.level == Setup::LEVEL_METHOD) traceDepth = 1; *************** *** 349,351 **** --- 375,386 ---- Prof::prof().sampling.main(); + } + + int Sampling::isTerminated() { + + #ifdef USE_RAW_MONITORS + Synchronized sync( _lock); + #endif + + return _terminated; } Index: sampling.h =================================================================== RCS file: /cvsroot/javaprofiler/library/src/cpu/sampling.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** sampling.h 2001/09/02 20:14:21 1.8 --- sampling.h 2001/11/21 22:31:43 1.9 *************** *** 36,39 **** --- 36,42 ---- #define _SAMPLING_H_ + #include "../main/includes.h" + #include "../prof/lock.h" + /** CPU Sampling. ** This class implements sampling method for CPU profiling. *************** *** 53,64 **** }; /// current command CMD _cmd; #ifdef WIN32 /// handle to 'turned on' event object HANDLE _turnedOn; ! /// for thread control synchronization CRITICAL_SECTION _cs; #else --- 56,73 ---- }; + private: + /// current command CMD _cmd; + #ifdef USE_RAW_MONITORS + /// critical section + Lock _lock; + #else #ifdef WIN32 /// handle to 'turned on' event object HANDLE _turnedOn; ! /// thread synchronization control CRITICAL_SECTION _cs; #else *************** *** 69,87 **** pthread_mutex_t _mutex; #endif ! ! private: ! ! /// Thread main function. ! void main(); ! ! /// Performs one sample. ! void doOneSample(); public: ! /// Consctructor ! Sampling(); ! /// Destructor ~Sampling(); --- 78,93 ---- pthread_mutex_t _mutex; #endif ! #endif public: ! /** Constructor. It initializes locks needed ! ** while sampling. ! ** ! ** @param jvmpi pointer to JVMPI interface */ ! ! Sampling( JVMPI_Interface* jvmpi); ! /// Destructor. ~Sampling(); *************** *** 90,94 **** ** profiler start-up. ** ! ** @param turnedOn whether sampling is turned on or off ** ** @return 0 (ok) --- 96,100 ---- ** profiler start-up. ** ! ** @param turnedOn whether sampling is turned on or off ** ** @return 0 (ok) *************** *** 98,117 **** /** Terminates sampling thread. ! ** The operation is asynchronyous to prevent deadlocks. */ void terminateThread(); /** Turns sampling on. ! ** The operation is asynchronyous to prevent deadlocks. */ void turnOn(); /** Turns sampling off. ! ** The operation is asynchronyous to prevent deadlocks. */ void turnOff(); private: /** Start routine for sampling thread. ** --- 104,133 ---- /** Terminates sampling thread. ! ** The operation is asynchronous to prevent deadlocks. */ void terminateThread(); + #ifndef USE_RAW_MONITORS /** Turns sampling on. ! ** The operation is asynchronous to prevent deadlocks. */ void turnOn(); /** Turns sampling off. ! ** The operation is asynchronous to prevent deadlocks. */ void turnOff(); + #endif private: + /// Main thread function. + void main(); + + /// Performs one sample. + void doOneSample(); + + private: + /** Start routine for sampling thread. ** *************** *** 126,131 **** unsigned long finish; unsigned long samples; ! #endif }; --- 142,161 ---- unsigned long finish; unsigned long samples; + #endif // _DEBUG ! private: ! ! /// thread termination flag ! int _terminated; ! ! public: ! ! /** Returns true/false in dependance on sampling thread has ! ** been terminated or not yet. ! ** ! ** @return 1 (thread stopped); ! ** 0 (still runnning) */ ! ! int isTerminated(); }; |