Warnings on vc14 were eliminated
[occt.git] / src / OSD / OSD_MemInfo.hxx
1 // Created on: 2011-10-05
2 // Created by: Kirill GAVRILOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _OSD_MemInfo_H__
17 #define _OSD_MemInfo_H__
18
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.
49 class OSD_MemInfo
50 {
51
52 public:
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
62     MemHeapUsage,      //!< Total space allocated from the heap
63     MemCounter_NB      //!< Indicates total counters number
64   };
65
66 public:
67
68   //! Create and initialize
69   Standard_EXPORT OSD_MemInfo();
70
71   //! Update counters
72   Standard_EXPORT void Update();
73
74   //! Return the string representation for all available counter.
75   Standard_EXPORT TCollection_AsciiString ToString() const;
76
77   //! Return value or specified counter in bytes.
78   //! Notice that NOT all counters are available on various systems.
79   //! Standard_Size(-1) means invalid (unavailable) value.
80   Standard_EXPORT Standard_Size Value (const OSD_MemInfo::Counter theCounter) const;
81
82   //! Return value or specified counter in MiB.
83   //! Notice that NOT all counters are available on various systems.
84   //! Standard_Size(-1) means invalid (unavailable) value.
85   Standard_EXPORT Standard_Size ValueMiB (const OSD_MemInfo::Counter theCounter) const;
86
87 public:
88
89   //! Return the string representation for all available counter.
90   Standard_EXPORT static TCollection_AsciiString PrintInfo();
91
92 private:
93
94   Standard_Size myCounters[MemCounter_NB]; //!< Counters' values, in bytes
95
96 };
97
98 #endif // _OSD_MemInfo_H__