Oracle Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.1.2)

E26041-01

coherence/lang/ClassBasedHeapAnalyzer.hpp

00001 /*
00002 * ClassBasedHeapAnalyzer.hpp
00003 *
00004 * Copyright (c) 2000, 2013, 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_CLASS_BASED_HEAP_ANALYZER_HPP
00017 #define COH_CLASS_BASED_HEAP_ANALYZER_HPP
00018 
00019 #include "coherence/lang/compatibility.hpp"
00020 
00021 #include "coherence/lang/AbstractHeapAnalyzer.hpp"
00022 #include "coherence/lang/Comparable.hpp"
00023 #include "coherence/lang/FinalView.hpp"
00024 
00025 #include <ostream>
00026 
00027 COH_OPEN_NAMESPACE2(coherence,util)
00028 class Map;
00029 COH_CLOSE_NAMESPACE2
00030 
00031 COH_OPEN_NAMESPACE2(coherence,lang)
00032 
00033 using coherence::util::Map;
00034 
00035 
00036 /**
00037 * ClassBasedHeapAnalyzer provides heap analysis at the class level, that is
00038 * it tracks the number of live instances of each class.
00039 *
00040 * The memory consumption of this heap analyzer is relative to the number of
00041 * classes used within the process. The CPU consumption is also very low, each
00042 * registration consists of roughly four compare-and-set operations. It is well
00043 * suited for development as well as many production environments.
00044 *
00045 * @see ObjectCountHeapAnalyzer for a lower overhead analyzer
00046 *
00047 * @author mf  2008.04.27
00048 */
00049 class COH_EXPORT ClassBasedHeapAnalyzer
00050     : public class_spec<ClassBasedHeapAnalyzer,
00051         extends<AbstractHeapAnalyzer> >
00052     {
00053     friend class factory<ClassBasedHeapAnalyzer>;
00054 
00055     // ----- constructor ----------------------------------------------------
00056 
00057     protected:
00058         /**
00059         * Create a new ClassBasedHeapAnalyzer.
00060         *
00061         * @param fShowAllocations  true if allocations should also be shown
00062         */
00063         ClassBasedHeapAnalyzer(bool fShowAllocations = false);
00064 
00065 
00066     // ----- nested class: ClassStats ---------------------------------------
00067 
00068     public:
00069         /**
00070         * Statistics relating to a class.
00071         */
00072         class COH_EXPORT ClassStats
00073             : public class_spec<ClassStats,
00074                 extends<Object>,
00075                 implements<Comparable> >
00076             {
00077             friend class factory<ClassStats>;
00078 
00079             protected:
00080                 /**
00081                 * Create a new ClassStats.
00082                 *
00083                 * @param cObjs   the instance count
00084                 * @param cBytes  the byte count
00085                 * @param cAlloc  the allocation count
00086                 * @return the new ClassStats
00087                 */
00088                 ClassStats(int64_t cObjs, int64_t cBytes, int64_t cAlloc);
00089 
00090             // ----- ClassStats interface ---------------------------------
00091 
00092             public:
00093                 /**
00094                 * Return the instance count for the class.
00095                 */
00096                 virtual int64_t getObjectCount() const;
00097 
00098                 /**
00099                 * Return the byte count for the class.
00100                 */
00101                 virtual int64_t getByteCount() const;
00102 
00103                 /**
00104                 * Return the allocation count for the class.
00105                 */
00106                 virtual int64_t getAllocationCount() const;
00107 
00108             // ----- Comparable interface ---------------------------------
00109 
00110             public:
00111                 /**
00112                 * {@inheritDoc}
00113                 */
00114                 int32_t compareTo(Object::View v) const;
00115 
00116             // ----- Object interface -------------------------------------
00117 
00118             public:
00119                 /**
00120                 * {@inheritDoc}
00121                 */
00122                 virtual void toStream(std::ostream& out) const;
00123 
00124             // ----- data members -----------------------------------------
00125 
00126             protected:
00127                 /**
00128                 * The number of instances of the class.
00129                 */
00130                 int64_t m_cInstanceCount;
00131 
00132                 /**
00133                 * The byte size of all the instances.
00134                 */
00135                 int64_t m_cByteCount;
00136 
00137                 /**
00138                 * The total number of allocations of the class.
00139                 */
00140                 int64_t m_cAllocationCount;
00141             };
00142 
00143     // ----- nested class: Snapshot -----------------------------------------
00144 
00145     public:
00146         /**
00147         * Snapshot containing the object count.
00148         */
00149         class COH_EXPORT Snapshot
00150             : public class_spec<Snapshot,
00151                 extends<Object>,
00152                 implements<HeapAnalyzer::Snapshot> >
00153             {
00154             friend class factory<Snapshot>;
00155 
00156             // ----- constructors ---------------------------------------
00157 
00158             protected:
00159                 /**
00160                 * Create a new Snapshot.
00161                 */
00162                 Snapshot(TypedHandle<const Map> vMap, bool fShowAllocations);
00163 
00164             // ----- Snapshot interface ---------------------------------
00165 
00166             public:
00167                 /**
00168                 * Return the Snapshots map of class names to ClassStats.
00169                 *
00170                 * The keys are class names, the values are ClassStats.
00171                 *
00172                 * @return the snapshots map.
00173                 */
00174                 virtual TypedHandle<const Map> getStatsMap() const;
00175 
00176                 /**
00177                 * {@inheritDoc}
00178                 */
00179                 virtual int64_t getObjectCount() const;
00180 
00181                 /**
00182                 * {@inheritDoc}
00183                 */
00184                 virtual HeapAnalyzer::Snapshot::View delta(
00185                         HeapAnalyzer::Snapshot::View vThat) const;
00186 
00187             // ----- Object interface: ----------------------------------
00188 
00189             public:
00190                 /**
00191                 * {@inheritDoc}
00192                 */
00193                 virtual void toStream(std::ostream& out) const;
00194 
00195             // ----- data members ---------------------------------------
00196 
00197             protected:
00198                 /**
00199                 * The map of class names to ClassStats.
00200                 */
00201                 FinalView<Object> f_vMapStats;
00202 
00203                 /**
00204                 * True if allocations are to be shown.
00205                 */
00206                 bool m_fShowAllocations;
00207             };
00208 
00209 
00210     // ----- AbstractHeapAnalyzer interface ---------------------------------
00211 
00212     protected:
00213         /**
00214         * {@inheritDoc}
00215         */
00216         virtual void safeRegisterObject(const Object& o);
00217 
00218         /**
00219         * {@inheritDoc}
00220         */
00221         virtual void safeUnregisterObject(const Object& o);
00222 
00223 
00224     // ----- HeapAnalyzer interface -----------------------------------------
00225 
00226     public:
00227         /**
00228         * {@inheritDoc}
00229         */
00230         virtual HeapAnalyzer::Snapshot::View capture() const;
00231 
00232         /**
00233         * {@inheritDoc}
00234         */
00235         virtual HeapAnalyzer::Snapshot::View delta(
00236                 HeapAnalyzer::Snapshot::View vSnap) const;
00237 
00238         /**
00239         * {@inheritDoc}
00240         */
00241         virtual int64_t getObjectCount() const;
00242 
00243     protected:
00244         /**
00245         * {@inheritDoc}
00246         */
00247         virtual void registerObject(const Object& o);
00248 
00249         /**
00250         * {@inheritDoc}
00251         */
00252         virtual void unregisterObject(const Object& o);
00253 
00254 
00255     // ----- data members ---------------------------------------------------
00256 
00257     protected:
00258         /**
00259         * True if allocations should be printed as part of analysis.
00260         */
00261         bool m_fShowAllocations;
00262 
00263 
00264     // ----- friends --------------------------------------------------------
00265 
00266     friend class Snapshot;
00267     };
00268 
00269 COH_CLOSE_NAMESPACE2
00270 
00271 #endif // COH_CLASS_BASED_HEAP_ANALYZER_HPP
Copyright © 2000, 2013, Oracle and/or its affiliates. All rights reserved.