| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Memory.cpp
Go to the documentation of this file.
1 //====================================================================
2 // Memory.cpp
3 //--------------------------------------------------------------------
4 //
5 // Package : System (The LHCb System service)
6 //
7 // Description: Information of memory usage from a given process
8 //
9 // Author : M.Frank
10 // Created : 13/11/00
11 // Changes :
12 //
13 //====================================================================
14 #define GAUDIKERNEL_MEMORY_CPP
15
16 #ifdef _WIN32
17 #include "process.h"
18 #define getpid _getpid
19 #else
20 #include <errno.h>
21 #include <string.h>
22 #include "sys/times.h"
23 #include "unistd.h"
24 #include "libgen.h"
25 #include <cstdio>
26 #endif
27
28 // Framework include files
29 #include <limits.h>
30 #include "GaudiKernel/Memory.h"
31 #include "ProcessDescriptor.h"
32
34 long System::adjustMemory( MemoryUnit unit, long value ) {
35 if ( value != -1 ) {
36 switch ( unit ) {
37 case Byte: break;
38 case kByte: value = value/1024; break;
39 case MByte: value = (value/1024)/1024; break;
40 case GByte: value = ((value/1024)/1024)/1024; break;
41 case TByte: value = (((value/1024)/1024)/1024)/1024; break;
42 case PByte: value = ((((value/1024)/1024)/1024)/1024)/1024; break;
43 case EByte: value = (((((value/1024)/1024)/1024)/1024)/1024)/1024; break;
44 default: value = -1; break;
45 }
46 }
47 return value;
48 }
49
51 long System::basePriority(InfoType fetch, long pid) {
52 PROCESS_BASIC_INFORMATION info;
53 if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
54 return info.BasePriority;
55 return 0;
56 }
57
59 long System::procID() {
60 static const long s_pid = ::getpid();
61 return s_pid;
62 }
63
65 long System::parentID(InfoType fetch, long pid) {
66 PROCESS_BASIC_INFORMATION info;
67 if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
68 return info.InheritedFromUniqueProcessId;
69 return 0;
70 }
71
73 long System::affinityMask(InfoType fetch, long pid) {
74 PROCESS_BASIC_INFORMATION info;
75 if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
76 return info.AffinityMask;
77 return 0;
78 }
79
81 long System::exitStatus(InfoType fetch, long pid) {
82 PROCESS_BASIC_INFORMATION info;
83 if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
84 return info.ExitStatus;
85 return -2;
86 }
87
89 long System::priorityBoost(InfoType fetch, long pid) {
90 long info;
91 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
92 return info;
93 return -2;
94 }
95
97 long System::nonPagedMemoryPeak(MemoryUnit unit, InfoType fetch, long pid) {
98 VM_COUNTERS info;
99 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
100 return adjustMemory(unit, info.QuotaPeakNonPagedPoolUsage);
101 return -2;
102 }
103
105 long System::nonPagedMemory(MemoryUnit unit, InfoType fetch, long pid) {
106 VM_COUNTERS info;
107 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
108 return adjustMemory(unit, info.QuotaNonPagedPoolUsage);
109 return -2;
110 }
111
113 long System::nonPagedMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) {
114 POOLED_USAGE_AND_LIMITS quota;
115 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
116 return adjustMemory(unit, quota.NonPagedPoolLimit);
117 return 0;
118 }
119
121 long System::pagedMemory(MemoryUnit unit, InfoType fetch, long pid) {
122 VM_COUNTERS info;
123 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
124 return adjustMemory(unit, info.QuotaPagedPoolUsage);
125 return -2;
126 }
127
129 long System::pagedMemoryPeak(MemoryUnit unit, InfoType fetch, long pid) {
130 VM_COUNTERS info;
131 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
132 return adjustMemory(unit, info.QuotaPeakPagedPoolUsage);
133 return -2;
134 }
135
137 long System::pagedMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) {
138 POOLED_USAGE_AND_LIMITS quota;
139 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
140 return adjustMemory(unit, quota.PagedPoolLimit);
141 return 0;
142 }
143
145 long System::numPageFault(InfoType fetch, long pid) {
146 VM_COUNTERS info;
147 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
148 return info.PageFaultCount;
149 return -2;
150 }
151
153 long System::pagefileUsage(MemoryUnit unit, InfoType fetch, long pid) {
154 VM_COUNTERS info;
155 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
156 return adjustMemory(unit, info.PagefileUsage);
157 return -2;
158 }
159
161 long System::pagefileUsagePeak(MemoryUnit unit, InfoType fetch, long pid) {
162 VM_COUNTERS info;
163 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
164 return adjustMemory(unit, info.PeakPagefileUsage);
165 return -2;
166 }
167
169 long System::pagefileUsageLimit(MemoryUnit unit, InfoType fetch, long pid) {
170 POOLED_USAGE_AND_LIMITS quota;
171 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) ) {
172 if ( long(quota.PagefileLimit) < 0 )
173 return -1;//LONG_MAX;
174 return adjustMemory(unit, quota.PagefileLimit);
175 }
176 return -2;
177 }
178
180 long System::mappedMemory(MemoryUnit unit, InfoType fetch, long pid) {
181 VM_COUNTERS info;
182 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
183 return adjustMemory(unit, info.WorkingSetSize);
184 return -2;
185 }
186
188 long System::mappedMemoryPeak(MemoryUnit unit, InfoType fetch, long pid) {
189 VM_COUNTERS info;
190 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
191 return adjustMemory(unit, info.PeakWorkingSetSize);
192 return -2;
193 }
194
196 long System::minMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) {
197 QUOTA_LIMITS quota;
198 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
199 return adjustMemory(unit, quota.MinimumWorkingSetSize);
200 return 0;
201 }
202
204 long System::maxMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) {
205 QUOTA_LIMITS quota;
206 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
207 return adjustMemory(unit, quota.MaximumWorkingSetSize);
208 return 0;
209 }
210
212 long System::virtualMemory(MemoryUnit unit, InfoType fetch, long pid) {
213 VM_COUNTERS info;
214 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
215 return adjustMemory(unit, info.VirtualSize);
216 return -2;
217 }
218
220 long System::virtualMemoryPeak(MemoryUnit unit, InfoType fetch, long pid) {
221 VM_COUNTERS info;
222 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
223 return adjustMemory(unit, info.PeakVirtualSize);
224 return -2;
225 }
226
228 long System::virtualMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) {
229 QUOTA_LIMITS quota;
230 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) ) {
231 if ( long(quota.PagefileLimit) == -1 )
232 return -1;//LONG_MAX;
233 return adjustMemory(unit, quota.PagefileLimit);
234 }
235 return 0;
236 }
237
System::maxMemoryLimit
GAUDI_API long maxMemoryLimit(MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
System Process Limits: Maximum amount of virtual memory this process is allowed to use...
Definition: Memory.cpp:204
System::mappedMemoryPeak
GAUDI_API long mappedMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:188
System::VM_COUNTERS::QuotaPeakPagedPoolUsage
unsigned long QuotaPeakPagedPoolUsage
Definition: ProcessDescriptor.h:65
System::parentID
GAUDI_API long parentID(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Parent&#39;s process ID.
Definition: Memory.cpp:65
System::VM_COUNTERS::PagefileUsage
unsigned long PagefileUsage
Definition: ProcessDescriptor.h:69
System::exitStatus
GAUDI_API long exitStatus(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Exit status (does not really make sense for the running process...
Definition: Memory.cpp:81
System::TByte
Definition: Memory.h:56
System::nonPagedMemory
GAUDI_API long nonPagedMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Current usage of non paged memory.
Definition: Memory.cpp:105
System::PByte
Definition: Memory.h:56
System::MByte
Definition: Memory.h:56
System::adjustMemory
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
ProcessDescriptor.h
System::QUOTA_LIMITS::MaximumWorkingSetSize
unsigned long MaximumWorkingSetSize
Definition: ProcessDescriptor.h:36
System::VM_COUNTERS::PeakPagefileUsage
unsigned long PeakPagefileUsage
Definition: ProcessDescriptor.h:70
System::QUOTA_LIMITS::PagefileLimit
unsigned long PagefileLimit
Definition: ProcessDescriptor.h:37
System::priorityBoost
GAUDI_API long priorityBoost(InfoType fetch=PriorityBoost, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:89
System::VM_COUNTERS::WorkingSetSize
unsigned long WorkingSetSize
Definition: ProcessDescriptor.h:64
System::pagedMemoryPeak
GAUDI_API long pagedMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Maximum of paged memory occupied by the process &#39;pid&#39;. ...
Definition: Memory.cpp:129
System::GByte
Definition: Memory.h:56
System::VM_COUNTERS::PeakWorkingSetSize
unsigned long PeakWorkingSetSize
Definition: ProcessDescriptor.h:63
System::VM_COUNTERS::VirtualSize
unsigned long VirtualSize
Definition: ProcessDescriptor.h:61
System::kByte
Definition: Memory.h:56
System::POOLED_USAGE_AND_LIMITS::PagedPoolLimit
unsigned long PagedPoolLimit
Definition: ProcessDescriptor.h:80
System::nonPagedMemoryPeak
GAUDI_API long nonPagedMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Peak usage of non paged memory.
Definition: Memory.cpp:97
System::PROCESS_BASIC_INFORMATION
Definition: ProcessDescriptor.h:18
System::VM_COUNTERS::PageFaultCount
unsigned long PageFaultCount
Definition: ProcessDescriptor.h:62
System::nonPagedMemoryLimit
GAUDI_API long nonPagedMemoryLimit(MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
System Process Limits: Maximum amount of non-paged memory this process is allowed to use...
Definition: Memory.cpp:113
System::PROCESS_BASIC_INFORMATION::AffinityMask
unsigned long AffinityMask
Definition: ProcessDescriptor.h:21
System::affinityMask
GAUDI_API long affinityMask(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Affinity mask.
Definition: Memory.cpp:73
System::VM_COUNTERS::QuotaNonPagedPoolUsage
unsigned long QuotaNonPagedPoolUsage
Definition: ProcessDescriptor.h:68
System::POOLED_USAGE_AND_LIMITS::PagefileLimit
unsigned long PagefileLimit
Definition: ProcessDescriptor.h:86
System::Byte
Definition: Memory.h:56
System::virtualMemoryLimit
GAUDI_API long virtualMemoryLimit(MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
System Process Limits: Maximum amount of the page file this process is allowed to use...
Definition: Memory.cpp:228
System::POOLED_USAGE_AND_LIMITS::NonPagedPoolLimit
unsigned long NonPagedPoolLimit
Definition: ProcessDescriptor.h:83
System::pagedMemoryLimit
GAUDI_API long pagedMemoryLimit(MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
Basic Process Information: Amount of paged memory that can be occupied by the process &#39;pid&#39;...
Definition: Memory.cpp:137
System::NoFetch
Definition: SystemBase.h:18
System::VM_COUNTERS::PeakVirtualSize
unsigned long PeakVirtualSize
Definition: ProcessDescriptor.h:60
System::pagefileUsageLimit
GAUDI_API long pagefileUsageLimit(MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
Basic Process Information: Peak usage of page file.
Definition: Memory.cpp:169
System::PROCESS_BASIC_INFORMATION::BasePriority
long BasePriority
Definition: ProcessDescriptor.h:22
System::MemoryUnit
MemoryUnit
Unit of memory.
Definition: Memory.h:56
System::mappedMemory
GAUDI_API long mappedMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:180
System::PROCESS_BASIC_INFORMATION::InheritedFromUniqueProcessId
unsigned long InheritedFromUniqueProcessId
Definition: ProcessDescriptor.h:24
Memory.h
System::getProcess
ProcessDescriptor * getProcess()
Retrieve Process structure.
Definition: ProcessDescriptor.h:135
System::pagefileUsagePeak
GAUDI_API long pagefileUsagePeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Peak usage of page file.
Definition: Memory.cpp:161
System::QUOTA_LIMITS
Process Quotas NtQueryInformationProcess using ProcessQuotaLimits NtQueryInformationProcess using Pro...
Definition: ProcessDescriptor.h:32
System::numPageFault
GAUDI_API long numPageFault(InfoType fetch=Memory, long pid=-1)
Basic Process Information: Number of page faults.
Definition: Memory.cpp:145
System::VM_COUNTERS
Process Virtual Memory Counters NtQueryInformationProcess using ProcessVmCounters.
Definition: ProcessDescriptor.h:59
System::virtualMemory
GAUDI_API long virtualMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:212
System::minMemoryLimit
GAUDI_API long minMemoryLimit(MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
System Process Limits: Minimum amount of virtual memory this process may use.
Definition: Memory.cpp:196
System::EByte
Definition: Memory.h:56
System::POOLED_USAGE_AND_LIMITS
Process Pooled Quota Usage and Limits NtQueryInformationProcess using ProcessPooledUsageAndLimits.
Definition: ProcessDescriptor.h:77
System::procID
GAUDI_API long procID()
Basic Process Information: Process ID.
Definition: Memory.cpp:59
System::ProcessBasics
Definition: SystemBase.h:21
System::basePriority
GAUDI_API long basePriority(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Base priority.
Definition: Memory.cpp:51
System::virtualMemoryPeak
GAUDI_API long virtualMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:220
System::QUOTA_LIMITS::MinimumWorkingSetSize
unsigned long MinimumWorkingSetSize
Definition: ProcessDescriptor.h:35
System::VM_COUNTERS::QuotaPeakNonPagedPoolUsage
unsigned long QuotaPeakNonPagedPoolUsage
Definition: ProcessDescriptor.h:67
System::pagefileUsage
GAUDI_API long pagefileUsage(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Current page file usage.
Definition: Memory.cpp:153
System::pagedMemory
GAUDI_API long pagedMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Amount of paged memory currently occupied by the process &#39;pid&#39;...
Definition: Memory.cpp:121
System::InfoType
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:18
System::PROCESS_BASIC_INFORMATION::ExitStatus
long ExitStatus
Definition: ProcessDescriptor.h:19
System::VM_COUNTERS::QuotaPagedPoolUsage
unsigned long QuotaPagedPoolUsage
Definition: ProcessDescriptor.h:66