0030901: Visualization - OSD_MemInfo moving memory computation out of the constructor
[occt.git] / src / OSD / OSD_MemInfo.hxx
CommitLineData
f0430952 1// Created on: 2011-10-05
2// Created by: Kirill GAVRILOV
d5f74e42 3// Copyright (c) 2013-2014 OPEN CASCADE SAS
f0430952 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
f0430952 6//
d5f74e42 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
973c2be1 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.
f0430952 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
f0430952 15
16#ifndef _OSD_MemInfo_H__
17#define _OSD_MemInfo_H__
18
f0430952 19#include <TCollection_AsciiString.hxx>
20
21//! This class provide information about memory utilized by current process.
22//! This information includes:
23//! - Private Memory - synthetic value that tries to filter out the memory
24//! usage only by the process itself (allocated for data
25//! and stack), excluding dynamic libraries.
26//! These pages may be in RAM or in SWAP.
27//! - Virtual Memory - amount of reserved and committed memory in the
28//! user-mode portion of the virtual address space.
29//! Notice that this counter includes reserved memory
30//! (not yet in used) and shared between processes memory (libraries).
31//! - Working Set - set of memory pages in the virtual address space of the process
32//! that are currently resident in physical memory (RAM).
33//! These pages are available for an application to use
34//! without triggering a page fault.
35//! - Pagefile Usage - space allocated for the pagefile, in bytes.
36//! Those pages may or may not be in memory (RAM)
37//! thus this counter couldn't be used to estimate
38//! how many active pages doesn't present in RAM.
39//!
40//! Notice that none of these counters can be used as absolute measure of
41//! application memory consumption!
42//!
43//! User should analyze all values in specific case to make correct decision
44//! about memory (over)usage. This is also prefferred to use specialized
45//! tools to detect memory leaks.
46//!
47//! This also means that these values should not be used for intellectual
48//! memory management by application itself.
30194ce3 49class OSD_MemInfo
f0430952 50{
51
52public:
53
54 enum Counter
55 {
56 MemPrivate = 0, //!< Virtual memory allocated for data and stack excluding libraries
57 MemVirtual, //!< Reserved and committed memory of the virtual address space
58 MemWorkingSet, //!< Memory pages that are currently resident in physical memory
59 MemWorkingSetPeak, //!< Peak working set size
60 MemSwapUsage, //!< Space allocated for the pagefile
61 MemSwapUsagePeak, //!< Peak space allocated for the pagefile
67a1064e 62 MemHeapUsage, //!< Total space allocated from the heap
f0430952 63 MemCounter_NB //!< Indicates total counters number
64 };
65
66public:
67
68 //! Create and initialize
0be11733 69 Standard_EXPORT OSD_MemInfo (const Standard_Boolean theImmediateUpdate = Standard_True);
70
71 //! Clear counters
72 Standard_EXPORT void Clear();
f0430952 73
74 //! Update counters
75 Standard_EXPORT void Update();
76
77 //! Return the string representation for all available counter.
78 Standard_EXPORT TCollection_AsciiString ToString() const;
79
0be11733 80 //! Return value of specified counter in bytes.
f0430952 81 //! Notice that NOT all counters are available on various systems.
82 //! Standard_Size(-1) means invalid (unavailable) value.
83 Standard_EXPORT Standard_Size Value (const OSD_MemInfo::Counter theCounter) const;
84
0be11733 85 //! Return value of specified counter in MiB.
f0430952 86 //! Notice that NOT all counters are available on various systems.
87 //! Standard_Size(-1) means invalid (unavailable) value.
88 Standard_EXPORT Standard_Size ValueMiB (const OSD_MemInfo::Counter theCounter) const;
89
0be11733 90 //! Return floating value of specified counter in MiB.
91 //! Notice that NOT all counters are available on various systems.
92 //! Standard_Real(-1) means invalid (unavailable) value.
93 Standard_EXPORT Standard_Real ValuePreciseMiB (const OSD_MemInfo::Counter theCounter) const;
94
f0430952 95public:
96
97 //! Return the string representation for all available counter.
98 Standard_EXPORT static TCollection_AsciiString PrintInfo();
99
100private:
101
102 Standard_Size myCounters[MemCounter_NB]; //!< Counters' values, in bytes
103
104};
105
106#endif // _OSD_MemInfo_H__