Oracle Coherence for C++ API
Release 3.7.1.0
E22845-01
00001 /* 00002 * ObjectCountHeapAnalyzer.hpp 00003 * 00004 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 00005 * 00006 * Oracle is a registered trademarks of Oracle Corporation and/or its 00007 * affiliates. 00008 * 00009 * This software is the confidential and proprietary information of Oracle 00010 * Corporation. You shall not disclose such confidential and proprietary 00011 * information and shall use it only in accordance with the terms of the 00012 * license agreement you entered into with Oracle. 00013 * 00014 * This notice may not be removed or altered. 00015 */ 00016 #ifndef COH_OBJECT_COUNT_HEAP_ANALYZER_HPP 00017 #define COH_OBJECT_COUNT_HEAP_ANALYZER_HPP 00018 00019 #include "coherence/lang/compatibility.hpp" 00020 00021 #include "coherence/lang/HeapAnalyzer.hpp" 00022 #include "coherence/native/NativeAtomic64.hpp" 00023 00024 #include <ostream> 00025 00026 COH_OPEN_NAMESPACE2(coherence,lang) 00027 00028 00029 /** 00030 * ObjectCountHeapAnalyzer provides simple heap analysis based solely on the 00031 * count of the number of live objects in the system. 00032 * 00033 * This heap analyzer has low CPU and memory costs. It is well suited for 00034 * performance sensitive production environments. 00035 * 00036 * @see ClassBasedHeapAnalyzer for more detailed heap analysis 00037 * 00038 * @author mf 2008.04.27 00039 */ 00040 class COH_EXPORT ObjectCountHeapAnalyzer 00041 : public class_spec<ObjectCountHeapAnalyzer, 00042 extends<Object>, 00043 implements<HeapAnalyzer> > 00044 { 00045 friend class factory<ObjectCountHeapAnalyzer>; 00046 00047 // ----- constructor ---------------------------------------------------- 00048 00049 protected: 00050 /** 00051 * Create a new ObjectCountHeapAnalyzer. 00052 * 00053 * @return the analyzer 00054 */ 00055 ObjectCountHeapAnalyzer(); 00056 00057 00058 // ----- nested class: Snapshot ----------------------------------------- 00059 00060 public: 00061 /** 00062 * Snapshot containing the object count. 00063 */ 00064 class COH_EXPORT Snapshot 00065 : public class_spec<Snapshot, 00066 extends<Object>, 00067 implements<HeapAnalyzer::Snapshot> > 00068 { 00069 friend class factory<Snapshot>; 00070 00071 // ----- constructors --------------------------------------- 00072 00073 protected: 00074 /** 00075 * Create a new Snapshot. 00076 * 00077 * @param cObjects the object count 00078 * 00079 * @return the new snapshot 00080 */ 00081 Snapshot(int64_t cObjects); 00082 00083 // ----- Snapshot interface --------------------------------- 00084 00085 public: 00086 /** 00087 * {@inheritDoc} 00088 */ 00089 virtual int64_t getObjectCount() const; 00090 00091 /** 00092 * {@inheritDoc} 00093 */ 00094 virtual HeapAnalyzer::Snapshot::View delta( 00095 HeapAnalyzer::Snapshot::View vThat) const; 00096 00097 // ----- Object interface: ---------------------------------- 00098 00099 public: 00100 /** 00101 * {@inheritDoc} 00102 */ 00103 virtual void toStream(std::ostream& out) const; 00104 00105 // ----- data members --------------------------------------- 00106 00107 protected: 00108 /** 00109 * The object count. 00110 */ 00111 int64_t m_cObjects; 00112 }; 00113 00114 00115 // ----- HeapAnalyzer interface ----------------------------------------- 00116 00117 public: 00118 /** 00119 * {@inheritDoc} 00120 */ 00121 virtual HeapAnalyzer::Snapshot::View capture() const; 00122 00123 /** 00124 * {@inheritDoc} 00125 */ 00126 virtual HeapAnalyzer::Snapshot::View delta( 00127 HeapAnalyzer::Snapshot::View vSnap) const; 00128 00129 /** 00130 * {@inheritDoc} 00131 */ 00132 virtual int64_t getObjectCount() const; 00133 00134 protected: 00135 /** 00136 * {@inheritDoc} 00137 */ 00138 virtual void registerObject(const Object& o); 00139 00140 /** 00141 * {@inheritDoc} 00142 */ 00143 virtual void unregisterObject(const Object& o); 00144 00145 00146 // ----- Object interface ----------------------------------------------- 00147 00148 public: 00149 /** 00150 * {@inheritDoc} 00151 */ 00152 virtual void toStream(std::ostream& out) const; 00153 00154 00155 // ----- data members --------------------------------------------------- 00156 00157 protected: 00158 /** 00159 * The size of the array of counters. 00160 */ 00161 static const size_t s_cCount = 257; 00162 00163 /** 00164 * Array of object counts. 00165 */ 00166 coherence::native::NativeAtomic64 m_acObjects[s_cCount]; 00167 }; 00168 00169 COH_CLOSE_NAMESPACE2 00170 00171 #endif // COH_OBJECT_COUNT_HEAP_ANALYZER_HPP