5e2e3c824cc6de7cacf400e0a4acd8ec1035215d
[occt.git] / src / OSD / OSD_MemInfo.hxx
1 // Created on: 2011-10-05
2 // Created by: Kirill GAVRILOV
3 // Copyright (c) 2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20 #ifndef _OSD_MemInfo_H__
21 #define _OSD_MemInfo_H__
22
23 #include <Standard_Transient.hxx>
24 #include <TCollection_AsciiString.hxx>
25
26 //! This class provide information about memory utilized by current process.
27 //! This information includes:
28 //!  - Private Memory - synthetic value that tries to filter out the memory
29 //!                     usage only by the process itself (allocated for data
30 //!                     and stack), excluding dynamic libraries.
31 //!                     These pages may be in RAM or in SWAP.
32 //!  - Virtual Memory - amount of reserved and committed memory in the
33 //!                     user-mode portion of the virtual address space.
34 //!                     Notice that this counter includes reserved memory
35 //!                     (not yet in used) and shared between processes memory (libraries).
36 //!  - Working Set    - set of memory pages in the virtual address space of the process
37 //!                     that are currently resident in physical memory (RAM).
38 //!                     These pages are available for an application to use
39 //!                     without triggering a page fault.
40 //!  - Pagefile Usage - space allocated for the pagefile, in bytes.
41 //!                     Those pages may or may not be in memory (RAM)
42 //!                     thus this counter couldn't be used to estimate
43 //!                     how many active pages doesn't present in RAM.
44 //!
45 //! Notice that none of these counters can be used as absolute measure of
46 //! application memory consumption!
47 //!
48 //! User should analyze all values in specific case to make correct decision
49 //! about memory (over)usage. This is also prefferred to use specialized
50 //! tools to detect memory leaks.
51 //!
52 //! This also means that these values should not be used for intellectual
53 //! memory management by application itself.
54 class OSD_MemInfo : public Standard_Transient
55 {
56
57 public:
58
59   enum Counter
60   {
61     MemPrivate = 0,    //!< Virtual memory allocated for data and stack excluding libraries
62     MemVirtual,        //!< Reserved and committed memory of the virtual address space
63     MemWorkingSet,     //!< Memory pages that are currently resident in physical memory
64     MemWorkingSetPeak, //!< Peak working set size
65     MemSwapUsage,      //!< Space allocated for the pagefile
66     MemSwapUsagePeak,  //!< Peak space allocated for the pagefile
67     MemCounter_NB      //!< Indicates total counters number
68   };
69
70 public:
71
72   //! Create and initialize
73   Standard_EXPORT OSD_MemInfo();
74
75   //! Update counters
76   Standard_EXPORT void Update();
77
78   //! Return the string representation for all available counter.
79   Standard_EXPORT TCollection_AsciiString ToString() const;
80
81   //! Return value or specified counter in bytes.
82   //! Notice that NOT all counters are available on various systems.
83   //! Standard_Size(-1) means invalid (unavailable) value.
84   Standard_EXPORT Standard_Size Value (const OSD_MemInfo::Counter theCounter) const;
85
86   //! Return value or specified counter in MiB.
87   //! Notice that NOT all counters are available on various systems.
88   //! Standard_Size(-1) means invalid (unavailable) value.
89   Standard_EXPORT Standard_Size ValueMiB (const OSD_MemInfo::Counter theCounter) const;
90
91 public:
92
93   //! Return the string representation for all available counter.
94   Standard_EXPORT static TCollection_AsciiString PrintInfo();
95
96 private:
97
98   Standard_Size myCounters[MemCounter_NB]; //!< Counters' values, in bytes
99
100 };
101
102 #endif // _OSD_MemInfo_H__