coherence/lang/ObjectCountHeapAnalyzer.hpp

00001 /*
00002 * ObjectCountHeapAnalyzer.hpp
00003 *
00004 * Copyright 2001-2008 by Oracle. 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 soley on the
00031 * count of the number of live objects in the system.
00032 *
00033 * This heap analyzer has next to no CPU or memory costs, there is a single
00034 * 64 bit counter which is updated using the non-blocking compare-and-set
00035 * operations. It is well suited for performance sensitive production
00036 * envrionments.
00037 *
00038 * @see ClassBasedHeapAnalyzer for more detailed heap analysis
00039 *
00040 * @author mf  2008.04.27
00041 */
00042 class COH_EXPORT ObjectCountHeapAnalyzer
00043     : public class_spec<ObjectCountHeapAnalyzer,
00044         extends<Object>,
00045         implements<HeapAnalyzer> >
00046     {
00047     friend class factory<ObjectCountHeapAnalyzer>;
00048 
00049     // ----- constructor ----------------------------------------------------
00050 
00051     protected:
00052         /**
00053         * Create a new ObjectCountHeapAnalyzer.
00054         *
00055         * @return the analyzer
00056         */
00057         ObjectCountHeapAnalyzer();
00058 
00059 
00060     // ----- nested class: Snapshot -----------------------------------------
00061 
00062     public:
00063         /**
00064         * Snapshot containging the object count.
00065         */
00066         class COH_EXPORT Snapshot
00067             : public class_spec<Snapshot,
00068                 extends<Object>,
00069                 implements<HeapAnalyzer::Snapshot> >
00070             {
00071             friend class factory<Snapshot>;
00072 
00073             // ----- constructors ---------------------------------------
00074 
00075             protected:
00076                 /**
00077                 * Create a new Snapshot.
00078                 *
00079                 * @return the new snapshot
00080                 */
00081                 Snapshot(int64_t cObjects);
00082 
00083 
00084             // ----- Snapshot interface ---------------------------------
00085 
00086             public:
00087                 /**
00088                 * {@inheritDoc}
00089                 */
00090                 virtual int64_t getObjectCount() const;
00091 
00092             // ----- Object interface: ----------------------------------
00093 
00094             public:
00095                 /**
00096                 * {@inheritDoc}
00097                 */
00098                 virtual void toStream(std::ostream& out) const;
00099 
00100             // ----- data members ---------------------------------------
00101 
00102             protected:
00103                 /**
00104                 * The object count.
00105                 */
00106                 int64_t m_cObjects;
00107             };
00108 
00109 
00110     // ----- HeapAnalyzer interface -----------------------------------------
00111 
00112     public:
00113         /**
00114         * {@inheritDoc}
00115         */
00116         virtual HeapAnalyzer::Snapshot::View capture() const;
00117 
00118         /**
00119         * {@inheritDoc}
00120         */
00121         virtual HeapAnalyzer::Snapshot::View delta(
00122                 HeapAnalyzer::Snapshot::View vSnap) const;
00123 
00124         /**
00125         * {@inheritDoc}
00126         */
00127         virtual int64_t getObjectCount() const;
00128 
00129     protected:
00130         /**
00131         * {@inheritDoc}
00132         */
00133         virtual void registerObject(const Object& o);
00134 
00135         /**
00136         * {@inheritDoc}
00137         */
00138         virtual void unregisterObject(const Object& o);
00139 
00140 
00141     // ----- Object interface -----------------------------------------------
00142 
00143     public:
00144         /**
00145         * {@inheritDoc}
00146         */
00147         virtual void toStream(std::ostream& out) const;
00148 
00149 
00150     // ----- data members ---------------------------------------------------
00151 
00152     protected:
00153         /**
00154         * The object count.
00155         */
00156         coherence::native::NativeAtomic64 m_cObjects;
00157     };
00158 
00159 COH_CLOSE_NAMESPACE2
00160 
00161 #endif // COH_OBJECT_COUNT_HEAP_ANALYZER_HPP
Copyright (c) 2000-2008 Oracle. All rights reserved.