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 <Standard_Transient.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.
50 class OSD_MemInfo : public Standard_Transient
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
70 Standard_EXPORT OSD_MemInfo();
73 Standard_EXPORT void Update();
75 //! Return the string representation for all available counter.
76 Standard_EXPORT TCollection_AsciiString ToString() const;
78 //! Return value or specified counter in bytes.
79 //! Notice that NOT all counters are available on various systems.
80 //! Standard_Size(-1) means invalid (unavailable) value.
81 Standard_EXPORT Standard_Size Value (const OSD_MemInfo::Counter theCounter) const;
83 //! Return value or specified counter in MiB.
84 //! Notice that NOT all counters are available on various systems.
85 //! Standard_Size(-1) means invalid (unavailable) value.
86 Standard_EXPORT Standard_Size ValueMiB (const OSD_MemInfo::Counter theCounter) const;
90 //! Return the string representation for all available counter.
91 Standard_EXPORT static TCollection_AsciiString PrintInfo();
95 Standard_Size myCounters[MemCounter_NB]; //!< Counters' values, in bytes
99 #endif // _OSD_MemInfo_H__