00001 #ifndef CDBBDB_OBJECT_PROFILER_HH 00002 #define CDBBDB_OBJECT_PROFILER_HH 00003 00004 // File and Version Information: 00005 // $Id: CdbBdbObjectProfiler.hh,v 1.2 2004/10/21 20:35:50 gapon Exp $ 00006 00007 #include "CdbBase/CdbCommon.hh" 00008 00009 #include <oo.h> // ooRef(ooObj), ooHandle(ooObj) 00010 00011 // Forward declarations 00012 00013 class CdbBdbObjectProfilerUserAction; 00014 class CdbBdbObjectProfilerImpl; 00015 00016 /// This class provides "object profiler" facility for persistent objects. 00017 /** 00018 * This facility uses the Objectivity/DB Active Schema API to navigate accross 00019 * an arbitrary graph of objects by visiting and profiling (collecting the object's 00020 * size satistic information for each node) and calling a user defined 00021 * action at each node. Each node is visited/profiled just once. A user defined action object 00022 * provides a feedback wether the profiling should propagate beyond a profiled 00023 * node or it should stop at this node or it should break profiling due to a error. 00024 * 00025 * IMPLEMENTATION NOTES: 00026 * 00027 * (1) This class uses PIMPL idiom to protect end users 00028 * of the class from being exposed to the buggy header 00029 * files of the Objectivity/DB Active Schema API. 00030 * 00031 * (2) This class violates CDB API convention on the inclusion 00032 * of "CdbBase/CdbCommon.hh" header file to avoid STD namespace 00033 * conflicts of the kind described above. 00034 * 00035 * ATTENTION: 00036 * 00037 * - This group of classes has nothing in common with the famous "Visitor" 00038 * pattern ("Go4"). 00039 */ 00040 class CdbBdbObjectProfiler { 00041 00042 private: 00043 00044 /// Default constructor (NOT IMPLEMENTED) 00045 /** 00046 * There is no way to get the consistent object's context without user defined 00047 * parameters passed through the normal constructor. 00048 */ 00049 CdbBdbObjectProfiler( ); 00050 00051 public: 00052 00053 /// Normal constructor 00054 /** 00055 * Sets the initial context for the profiling. This context can be reused 00056 * accross multiple calls to the profiling method itself. 00057 * 00058 * A non-zero pointer onto a user defined action is required. 00059 * 00060 * The ownership to a user action does not get transferred 00061 * into the current object. We may need non-const pointer to let a user 00062 * to maintain the context of user action between calls. 00063 * 00064 * Note, a user action object can be overriden by passing another user action 00065 * object by calling a special "setUserAction" method. 00066 */ 00067 CdbBdbObjectProfiler( CdbBdbObjectProfilerUserAction* theUserAction, 00068 bool verboseMode = false, 00069 bool debugMode = false ); 00070 00071 /// Destructor 00072 /** 00073 * More details... 00074 */ 00075 virtual ~CdbBdbObjectProfiler( ); 00076 00077 /// Visit the specified object 00078 /** 00079 * The operation will return "true" in case of success, it will return "false" 00080 * in case of any errors. 00081 */ 00082 bool profile( const ooHandle(ooObj)& theInputH ); 00083 00084 /// Set user action 00085 /** 00086 * If 0 pointer is passed then the current user action will be reset 00087 * and it will not be called anymore. 00088 * 00089 * The method will return a pointer onto the previous action (if any). 00090 * 00091 * @see class CdbBdbObjectProfilerUserAction 00092 */ 00093 CdbBdbObjectProfilerUserAction* setUserAction( CdbBdbObjectProfilerUserAction* theUserAction ); 00094 00095 /// Get current size 00096 /** 00097 * This method will return the number of bytes found by the profiler 00098 * by the time of the current request get executed. 00099 */ 00100 uint64 getSize( ) const; 00101 00102 /// Get current number of top-level objects 00103 /** 00104 * This method will return the number of "top-level" objects (not counting duplicated ones) 00105 * processed by the profiler by the time of the current request get executed. 00106 * 00107 * NOTES: 00108 * 00109 * - this procedure does NOT count "children" of composite "top-level" objects 00110 * - it does NOT count those objects processed by a user defined action either 00111 */ 00112 uint64 getTopObjects( ) const; 00113 00114 private: 00115 00116 // Here is my implementation 00117 00118 CdbBdbObjectProfilerImpl* _myImpl; 00119 }; 00120 00121 #endif // CDBBDB_OBJECT_PROFILER_HH
1.3-rc3