00001 #ifndef CDBBDB_OBJECT_PROFILER_IMPL_HH 00002 #define CDBBDB_OBJECT_PROFILER_IMPL_HH 00003 00004 // File and Version Information: 00005 // $Id: CdbBdbObjectProfilerImpl.hh,v 1.2 2004/10/21 20:35:50 gapon Exp $ 00006 00007 #include "CdbBase/CdbCommon.hh" 00008 00009 #include <string> 00010 00011 #include <oo.h> // Objectivity/DB core API 00012 #include <ooas.h> // Objectivity/DB Active Schema API 00013 00014 // Forward declarations 00015 00016 class CdbBdbObjectProfilerUserAction; 00017 class CdbBdbObjectProfilerContext; 00018 00019 template< class T > class CdbBdbCache; 00020 00021 /// This class implements the "object profiling" facility for a graph of persistent objects. 00022 /** 00023 * More details... 00024 */ 00025 class CdbBdbObjectProfilerImpl { 00026 00027 friend class CdbBdbObjectProfiler; // who is able to create and destroy me 00028 00029 private: 00030 00031 /// Default constructor (NOT IMPLEMENTED) 00032 /** 00033 * Implements the contract of the corresponding method of the facade class. 00034 * 00035 * @see CdbBdbObjectProfiler::CdbBdbObjectProfiler() 00036 */ 00037 CdbBdbObjectProfilerImpl( ); 00038 00039 /// Normal constructor 00040 /** 00041 * Implements the contract of the corresponding method of the facade class. 00042 * 00043 * @see CdbBdbObjectProfiler::CdbBdbObjectProfiler() 00044 */ 00045 CdbBdbObjectProfilerImpl( CdbBdbObjectProfilerUserAction* theUserAction, 00046 bool verboseMode, 00047 bool debugMode ); 00048 00049 /// Destructor 00050 /** 00051 * Implements the contract of the corresponding method of the facade class. 00052 * 00053 * @see CdbBdbObjectProfiler::~CdbBdbObjectProfiler() 00054 */ 00055 virtual ~CdbBdbObjectProfilerImpl( ); 00056 00057 /// Profile the specified object 00058 /** 00059 * Implements the contract of the corresponding method of the facade class. 00060 * 00061 * @see CdbBdbObjectProfiler::profile() 00062 */ 00063 virtual bool profile( const ooHandle(ooObj)& theInputH ); 00064 00065 /// Set user action 00066 /** 00067 * Implements the contract of the corresponding method of the facade class. 00068 * 00069 * @see CdbBdbObjectProfiler::setUserAction() 00070 */ 00071 CdbBdbObjectProfilerUserAction* setUserAction( CdbBdbObjectProfilerUserAction* theUserAction ); 00072 00073 /// Get current size 00074 /** 00075 * Implements the contract of the corresponding method of the facade class. 00076 * 00077 * @see CdbBdbObjectProfiler::getSize() 00078 */ 00079 uint64 getSize( ) const; 00080 00081 /// Get current number of top-level objects 00082 /** 00083 * Implements the contract of the corresponding method of the facade class. 00084 * 00085 * @see CdbBdbObjectProfiler::getTopObjects() 00086 */ 00087 uint64 getTopObjects( ) const; 00088 00089 private: 00090 00091 /// An automatic prefix class 00092 /** 00093 * This internal helper class is meant to help with forming a proper prefix 00094 * string depending on the current "level" in a profileded graph. 00095 */ 00096 class Prefix { 00097 00098 private: 00099 00100 /// Default constructor (NOT IMPLEMENTED) 00101 /** 00102 * The object's default does not make any sense at all. 00103 */ 00104 Prefix( ); 00105 00106 /// Copy constructor (NOT IMPLEMENTED) 00107 /** 00108 * Copying of these objects does not make any sense at all. 00109 */ 00110 Prefix( const Prefix& ); 00111 00112 /// Assignment operator (NOT IMPLEMENTED) 00113 /** 00114 * Copying of these objects does not make any sense at all. 00115 */ 00116 Prefix& operator=( const Prefix& ); 00117 00118 public: 00119 00120 /// Normal constructor 00121 /** 00122 * Decrement the current level at the caller's context. 00123 * Set up the current prefix string at the current context. 00124 */ 00125 Prefix( int& theLevel, /**< a reference onto the caller's context */ 00126 const std::string& theStep = " " /**< the step between levels */ 00127 ); 00128 00129 /// Destructor 00130 /** 00131 * Decrement the current level at the caller's context. 00132 */ 00133 ~Prefix( ); 00134 00135 /// An explicit type conversion operator 00136 /** 00137 * Will return a pointer onto the current prefix string. 00138 * 00139 * NONE: The returned string is bound to the local object's context. 00140 */ 00141 const char* c_str( ) const; 00142 00143 private: 00144 00145 int& _level; // a reference onto the caller's context 00146 std::string _str; // the current prefix 00147 }; 00148 00149 // Helper methods 00150 00151 bool profileObject( const ooHandle(ooObj)& theH ); 00152 00153 bool profileObjectContents( const ooas::Class_Object& theClassObject, 00154 const Prefix& thePrefix ); 00155 00156 static uint64 sizeOfNumericValue( const Numeric_Value& theNumericValue ); 00157 00158 static uint64 sizeOfStringValue( String_Value theStringValue ); 00159 00160 static uint64 sizeOfReference( ); 00161 00162 private: 00163 00164 // Current context 00165 00166 bool _verboseMode; 00167 bool _debugMode; 00168 00169 CdbBdbObjectProfilerUserAction* _userAction; 00170 00171 // A set to mark OID-s of input objects which were already profiled. 00172 // The set is used for the following reasons: 00173 // 00174 // - to avoid prifiling objects which have already been prifiled 00175 // - to escape from the cyclic graph problem 00176 00177 CdbBdbCache< ooRef(ooObj) >* _dictionary; 00178 00179 // Supplementary data structures 00180 00181 int _level; // the current level in a prifiled graph (begins with 0 for the initial object) 00182 00183 // Profiler's statistics 00184 00185 uint64 _size; // The amount of data (in bytes) measured by the profiler 00186 uint64 _topObjects; // The number of unique "top-level" objects measured by the profiler 00187 }; 00188 00189 #endif // CDBBDB_OBJECT_PROFILER_IMPL_HH
1.3-rc3