1 // Created on: 2011-10-05
2 // Created by: Kirill GAVRILOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _OSD_MemInfo_H__
17 #define _OSD_MemInfo_H__
19 #include <NCollection_Map.hxx>
20 #include <TCollection_AsciiString.hxx>
22 //! This class provide information about memory utilized by current process.
23 //! This information includes:
24 //! - Private Memory - synthetic value that tries to filter out the memory
25 //! usage only by the process itself (allocated for data
26 //! and stack), excluding dynamic libraries.
27 //! These pages may be in RAM or in SWAP.
28 //! - Virtual Memory - amount of reserved and committed memory in the
29 //! user-mode portion of the virtual address space.
30 //! Notice that this counter includes reserved memory
31 //! (not yet in used) and shared between processes memory (libraries).
32 //! - Working Set - set of memory pages in the virtual address space of the process
33 //! that are currently resident in physical memory (RAM).
34 //! These pages are available for an application to use
35 //! without triggering a page fault.
36 //! - Pagefile Usage - space allocated for the pagefile, in bytes.
37 //! Those pages may or may not be in memory (RAM)
38 //! thus this counter couldn't be used to estimate
39 //! how many active pages doesn't present in RAM.
41 //! Notice that none of these counters can be used as absolute measure of
42 //! application memory consumption!
44 //! User should analyze all values in specific case to make correct decision
45 //! about memory (over)usage. This is also prefferred to use specialized
46 //! tools to detect memory leaks.
48 //! This also means that these values should not be used for intellectual
49 //! memory management by application itself.
57 MemPrivate = 0, //!< Virtual memory allocated for data and stack excluding libraries
58 MemVirtual, //!< Reserved and committed memory of the virtual address space
59 MemWorkingSet, //!< Memory pages that are currently resident in physical memory
60 MemWorkingSetPeak, //!< Peak working set size
61 MemSwapUsage, //!< Space allocated for the pagefile
62 MemSwapUsagePeak, //!< Peak space allocated for the pagefile
63 MemHeapUsage, //!< Total space allocated from the heap
64 MemCounter_NB //!< Indicates total counters number
69 //! Create and initialize. By default all countes are active
70 Standard_EXPORT OSD_MemInfo (const Standard_Boolean theImmediateUpdate = Standard_True);
72 //! Return true if the counter is active
73 Standard_Boolean IsActive (const OSD_MemInfo::Counter theCounter) const { return myActiveCounters[theCounter]; }
75 //! Set all counters active. The information is collected for active counters.
76 //! @param theActive state for counters
77 Standard_EXPORT void SetActive (const Standard_Boolean theActive);
79 //! Set the counter active. The information is collected for active counters.
80 //! @param theCounter type of counter
81 //! @param theActive state for the counter
82 void SetActive (const OSD_MemInfo::Counter theCounter, const Standard_Boolean theActive) { myActiveCounters[theCounter] = theActive; }
85 Standard_EXPORT void Clear();
88 Standard_EXPORT void Update();
90 //! Return the string representation for all available counter.
91 Standard_EXPORT TCollection_AsciiString ToString() const;
93 //! Return value of specified counter in bytes.
94 //! Notice that NOT all counters are available on various systems.
95 //! Standard_Size(-1) means invalid (unavailable) value.
96 Standard_EXPORT Standard_Size Value (const OSD_MemInfo::Counter theCounter) const;
98 //! Return value of specified counter in MiB.
99 //! Notice that NOT all counters are available on various systems.
100 //! Standard_Size(-1) means invalid (unavailable) value.
101 Standard_EXPORT Standard_Size ValueMiB (const OSD_MemInfo::Counter theCounter) const;
103 //! Return floating value of specified counter in MiB.
104 //! Notice that NOT all counters are available on various systems.
105 //! Standard_Real(-1) means invalid (unavailable) value.
106 Standard_EXPORT Standard_Real ValuePreciseMiB (const OSD_MemInfo::Counter theCounter) const;
110 //! Return the string representation for all available counter.
111 Standard_EXPORT static TCollection_AsciiString PrintInfo();
115 //! Return true if the counter is active and the value is valid
116 Standard_Boolean hasValue (const OSD_MemInfo::Counter theCounter) const
117 { return IsActive (theCounter) && myCounters[theCounter] != Standard_Size(-1); }
121 Standard_Size myCounters[MemCounter_NB]; //!< Counters' values, in bytes
122 Standard_Boolean myActiveCounters[MemCounter_NB]; //!< container of active state for a counter
126 #endif // _OSD_MemInfo_H__