Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-01 09:01:57

0001 // Created on: 2011-10-05
0002 // Created by: Kirill GAVRILOV
0003 // Copyright (c) 2013-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef OSD_MemInfo_HeaderFile
0017 #define OSD_MemInfo_HeaderFile
0018 
0019 #include <TCollection_AsciiString.hxx>
0020 
0021 //! This class provide information about memory utilized by current process.
0022 //! This information includes:
0023 //!  - Private Memory - synthetic value that tries to filter out the memory
0024 //!                     usage only by the process itself (allocated for data
0025 //!                     and stack), excluding dynamic libraries.
0026 //!                     These pages may be in RAM or in SWAP.
0027 //!  - Virtual Memory - amount of reserved and committed memory in the
0028 //!                     user-mode portion of the virtual address space.
0029 //!                     Notice that this counter includes reserved memory
0030 //!                     (not yet in used) and shared between processes memory (libraries).
0031 //!  - Working Set    - set of memory pages in the virtual address space of the process
0032 //!                     that are currently resident in physical memory (RAM).
0033 //!                     These pages are available for an application to use
0034 //!                     without triggering a page fault.
0035 //!  - Pagefile Usage - space allocated for the pagefile, in bytes.
0036 //!                     Those pages may or may not be in memory (RAM)
0037 //!                     thus this counter couldn't be used to estimate
0038 //!                     how many active pages doesn't present in RAM.
0039 //!
0040 //! Notice that none of these counters can be used as absolute measure of
0041 //! application memory consumption!
0042 //!
0043 //! User should analyze all values in specific case to make correct decision
0044 //! about memory (over)usage. This is also preferred to use specialized
0045 //! tools to detect memory leaks.
0046 //!
0047 //! This also means that these values should not be used for intellectual
0048 //! memory management by application itself.
0049 class OSD_MemInfo
0050 {
0051 
0052 public:
0053   enum Counter
0054   {
0055     MemPrivate = 0,    //!< Virtual memory allocated for data and stack excluding libraries
0056     MemVirtual,        //!< Reserved and committed memory of the virtual address space
0057     MemWorkingSet,     //!< Memory pages that are currently resident in physical memory
0058     MemWorkingSetPeak, //!< Peak working set size
0059     MemSwapUsage,      //!< Space allocated for the pagefile
0060     MemSwapUsagePeak,  //!< Peak space allocated for the pagefile
0061     MemHeapUsage,      //!< Total space allocated from the heap
0062     MemCounter_NB      //!< Indicates total counters number
0063   };
0064 
0065 public:
0066   //! Create and initialize. By default all countes are active
0067   Standard_EXPORT OSD_MemInfo(const bool theImmediateUpdate = true);
0068 
0069   //! Return true if the counter is active
0070   bool IsActive(const OSD_MemInfo::Counter theCounter) const
0071   {
0072     return myActiveCounters[theCounter];
0073   }
0074 
0075   //! Set all counters active. The information is collected for active counters.
0076   //! @param theActive state for counters
0077   Standard_EXPORT void SetActive(const bool theActive);
0078 
0079   //! Set the counter active. The information is collected for active counters.
0080   //! @param theCounter type of counter
0081   //! @param theActive state for the counter
0082   void SetActive(const OSD_MemInfo::Counter theCounter, const bool theActive)
0083   {
0084     myActiveCounters[theCounter] = theActive;
0085   }
0086 
0087   //! Clear counters
0088   Standard_EXPORT void Clear();
0089 
0090   //! Update counters
0091   Standard_EXPORT void Update();
0092 
0093   //! Return the string representation for all available counter.
0094   Standard_EXPORT TCollection_AsciiString ToString() const;
0095 
0096   //! Return value of specified counter in bytes.
0097   //! Notice that NOT all counters are available on various systems.
0098   //! size_t(-1) means invalid (unavailable) value.
0099   Standard_EXPORT size_t Value(const OSD_MemInfo::Counter theCounter) const;
0100 
0101   //! Return value of specified counter in MiB.
0102   //! Notice that NOT all counters are available on various systems.
0103   //! size_t(-1) means invalid (unavailable) value.
0104   Standard_EXPORT size_t ValueMiB(const OSD_MemInfo::Counter theCounter) const;
0105 
0106   //! Return floating value of specified counter in MiB.
0107   //! Notice that NOT all counters are available on various systems.
0108   //! double(-1) means invalid (unavailable) value.
0109   Standard_EXPORT double ValuePreciseMiB(const OSD_MemInfo::Counter theCounter) const;
0110 
0111 public:
0112   //! Return the string representation for all available counter.
0113   Standard_EXPORT static TCollection_AsciiString PrintInfo();
0114 
0115 protected:
0116   //! Return true if the counter is active and the value is valid
0117   bool hasValue(const OSD_MemInfo::Counter theCounter) const
0118   {
0119     return IsActive(theCounter) && myCounters[theCounter] != size_t(-1);
0120   }
0121 
0122 private:
0123   size_t myCounters[MemCounter_NB];       //!< Counters' values, in bytes
0124   bool   myActiveCounters[MemCounter_NB]; //!< container of active state for a counter
0125 };
0126 
0127 #endif // _OSD_MemInfo_H__