|
||||
File indexing completed on 2025-01-18 10:04:37
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 prefferred 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 0054 enum Counter 0055 { 0056 MemPrivate = 0, //!< Virtual memory allocated for data and stack excluding libraries 0057 MemVirtual, //!< Reserved and committed memory of the virtual address space 0058 MemWorkingSet, //!< Memory pages that are currently resident in physical memory 0059 MemWorkingSetPeak, //!< Peak working set size 0060 MemSwapUsage, //!< Space allocated for the pagefile 0061 MemSwapUsagePeak, //!< Peak space allocated for the pagefile 0062 MemHeapUsage, //!< Total space allocated from the heap 0063 MemCounter_NB //!< Indicates total counters number 0064 }; 0065 0066 public: 0067 0068 //! Create and initialize. By default all countes are active 0069 Standard_EXPORT OSD_MemInfo (const Standard_Boolean theImmediateUpdate = Standard_True); 0070 0071 //! Return true if the counter is active 0072 Standard_Boolean IsActive (const OSD_MemInfo::Counter theCounter) const { return myActiveCounters[theCounter]; } 0073 0074 //! Set all counters active. The information is collected for active counters. 0075 //! @param theActive state for counters 0076 Standard_EXPORT void SetActive (const Standard_Boolean theActive); 0077 0078 //! Set the counter active. The information is collected for active counters. 0079 //! @param theCounter type of counter 0080 //! @param theActive state for the counter 0081 void SetActive (const OSD_MemInfo::Counter theCounter, const Standard_Boolean theActive) { myActiveCounters[theCounter] = theActive; } 0082 0083 //! Clear counters 0084 Standard_EXPORT void Clear(); 0085 0086 //! Update counters 0087 Standard_EXPORT void Update(); 0088 0089 //! Return the string representation for all available counter. 0090 Standard_EXPORT TCollection_AsciiString ToString() const; 0091 0092 //! Return value of specified counter in bytes. 0093 //! Notice that NOT all counters are available on various systems. 0094 //! Standard_Size(-1) means invalid (unavailable) value. 0095 Standard_EXPORT Standard_Size Value (const OSD_MemInfo::Counter theCounter) const; 0096 0097 //! Return value of specified counter in MiB. 0098 //! Notice that NOT all counters are available on various systems. 0099 //! Standard_Size(-1) means invalid (unavailable) value. 0100 Standard_EXPORT Standard_Size ValueMiB (const OSD_MemInfo::Counter theCounter) const; 0101 0102 //! Return floating value of specified counter in MiB. 0103 //! Notice that NOT all counters are available on various systems. 0104 //! Standard_Real(-1) means invalid (unavailable) value. 0105 Standard_EXPORT Standard_Real ValuePreciseMiB (const OSD_MemInfo::Counter theCounter) const; 0106 0107 public: 0108 0109 //! Return the string representation for all available counter. 0110 Standard_EXPORT static TCollection_AsciiString PrintInfo(); 0111 0112 protected: 0113 0114 //! Return true if the counter is active and the value is valid 0115 Standard_Boolean hasValue (const OSD_MemInfo::Counter theCounter) const 0116 { return IsActive (theCounter) && myCounters[theCounter] != Standard_Size(-1); } 0117 0118 private: 0119 0120 Standard_Size myCounters[MemCounter_NB]; //!< Counters' values, in bytes 0121 Standard_Boolean myActiveCounters[MemCounter_NB]; //!< container of active state for a counter 0122 0123 }; 0124 0125 #endif // _OSD_MemInfo_H__
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |