| The Gaudi Framework v30r0 (c919700c)

- 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 "libgen.h"
21 #include "sys/times.h"
22 #include "unistd.h"
23 #include <cstdio>
24 #include <errno.h>
25 #include <string.h>
26 #endif
27
28 // Framework include files
29 #include "GaudiKernel/Memory.h"
30 #include "ProcessDescriptor.h"
31 #include <limits.h>
32
34 long System::adjustMemory( MemoryUnit unit, long value )
35 {
36 if ( value != -1 ) {
37 switch ( unit ) {
38 case Byte:
39 break;
40 case kByte:
41 value = value / 1024;
42 break;
43 case MByte:
44 value = ( value / 1024 ) / 1024;
45 break;
46 case GByte:
47 value = ( ( value / 1024 ) / 1024 ) / 1024;
48 break;
49 case TByte:
50 value = ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024;
51 break;
52 case PByte:
53 value = ( ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024;
54 break;
55 case EByte:
56 value = ( ( ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024;
57 break;
58 default:
59 value = -1;
60 break;
61 }
62 }
63 return value;
64 }
65
67 long System::basePriority( InfoType fetch, long pid )
68 {
69 PROCESS_BASIC_INFORMATION info;
70 if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.BasePriority;
71 return 0;
72 }
73
75 long System::procID()
76 {
77 static const long s_pid = ::getpid();
78 return s_pid;
79 }
80
82 long System::parentID( InfoType fetch, long pid )
83 {
84 PROCESS_BASIC_INFORMATION info;
85 if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.InheritedFromUniqueProcessId;
86 return 0;
87 }
88
90 long System::affinityMask( InfoType fetch, long pid )
91 {
92 PROCESS_BASIC_INFORMATION info;
93 if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.AffinityMask;
94 return 0;
95 }
96
98 long System::exitStatus( InfoType fetch, long pid )
99 {
100 PROCESS_BASIC_INFORMATION info;
101 if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.ExitStatus;
102 return -2;
103 }
104
106 long System::priorityBoost( InfoType fetch, long pid )
107 {
108 long info;
109 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return info;
110 return -2;
111 }
112
114 long System::nonPagedMemoryPeak( MemoryUnit unit, InfoType fetch, long pid )
115 {
116 VM_COUNTERS info;
117 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
118 return adjustMemory( unit, info.QuotaPeakNonPagedPoolUsage );
119 return -2;
120 }
121
123 long System::nonPagedMemory( MemoryUnit unit, InfoType fetch, long pid )
124 {
125 VM_COUNTERS info;
126 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
127 return adjustMemory( unit, info.QuotaNonPagedPoolUsage );
128 return -2;
129 }
130
132 long System::nonPagedMemoryLimit( MemoryUnit unit, InfoType fetch, long pid )
133 {
134 POOLED_USAGE_AND_LIMITS quota;
135 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
136 return adjustMemory( unit, quota.NonPagedPoolLimit );
137 return 0;
138 }
139
141 long System::pagedMemory( MemoryUnit unit, InfoType fetch, long pid )
142 {
143 VM_COUNTERS info;
144 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
145 return adjustMemory( unit, info.QuotaPagedPoolUsage );
146 return -2;
147 }
148
150 long System::pagedMemoryPeak( MemoryUnit unit, InfoType fetch, long pid )
151 {
152 VM_COUNTERS info;
153 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
154 return adjustMemory( unit, info.QuotaPeakPagedPoolUsage );
155 return -2;
156 }
157
159 long System::pagedMemoryLimit( MemoryUnit unit, InfoType fetch, long pid )
160 {
161 POOLED_USAGE_AND_LIMITS quota;
162 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
163 return adjustMemory( unit, quota.PagedPoolLimit );
164 return 0;
165 }
166
168 long System::numPageFault( InfoType fetch, long pid )
169 {
170 VM_COUNTERS info;
171 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return info.PageFaultCount;
172 return -2;
173 }
174
176 long System::pagefileUsage( MemoryUnit unit, InfoType fetch, long pid )
177 {
178 VM_COUNTERS info;
179 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.PagefileUsage );
180 return -2;
181 }
182
184 long System::pagefileUsagePeak( MemoryUnit unit, InfoType fetch, long pid )
185 {
186 VM_COUNTERS info;
187 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
188 return adjustMemory( unit, info.PeakPagefileUsage );
189 return -2;
190 }
191
193 long System::pagefileUsageLimit( MemoryUnit unit, InfoType fetch, long pid )
194 {
195 POOLED_USAGE_AND_LIMITS quota;
196 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
197 if ( long( quota.PagefileLimit ) < 0 ) return -1; // LONG_MAX;
198 return adjustMemory( unit, quota.PagefileLimit );
199 }
200 return -2;
201 }
202
204 long System::mappedMemory( MemoryUnit unit, InfoType fetch, long pid )
205 {
206 VM_COUNTERS info;
207 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.WorkingSetSize );
208 return -2;
209 }
210
212 long System::mappedMemoryPeak( MemoryUnit unit, InfoType fetch, long pid )
213 {
214 VM_COUNTERS info;
215 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
216 return adjustMemory( unit, info.PeakWorkingSetSize );
217 return -2;
218 }
219
221 long System::minMemoryLimit( MemoryUnit unit, InfoType fetch, long pid )
222 {
223 QUOTA_LIMITS quota;
224 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
225 return adjustMemory( unit, quota.MinimumWorkingSetSize );
226 return 0;
227 }
228
230 long System::maxMemoryLimit( MemoryUnit unit, InfoType fetch, long pid )
231 {
232 QUOTA_LIMITS quota;
233 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
234 return adjustMemory( unit, quota.MaximumWorkingSetSize );
235 return 0;
236 }
237
239 long System::virtualMemory( MemoryUnit unit, InfoType fetch, long pid )
240 {
241 VM_COUNTERS info;
242 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.VirtualSize );
243 return -2;
244 }
245
247 long System::virtualMemoryPeak( MemoryUnit unit, InfoType fetch, long pid )
248 {
249 VM_COUNTERS info;
250 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.PeakVirtualSize );
251 return -2;
252 }
253
255 long System::virtualMemoryLimit( MemoryUnit unit, InfoType fetch, long pid )
256 {
257 QUOTA_LIMITS quota;
258 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
259 if ( long( quota.PagefileLimit ) == -1 ) return -1; // LONG_MAX;
260 return adjustMemory( unit, quota.PagefileLimit );
261 }
262 return 0;
263 }
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:230
System::mappedMemoryPeak
GAUDI_API long mappedMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:212
System::VM_COUNTERS::QuotaPeakPagedPoolUsage
unsigned long QuotaPeakPagedPoolUsage
Definition: ProcessDescriptor.h:66
System::parentID
GAUDI_API long parentID(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Parent&#39;s process ID.
Definition: Memory.cpp:82
System::VM_COUNTERS::PagefileUsage
unsigned long PagefileUsage
Definition: ProcessDescriptor.h:70
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:98
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:123
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:37
System::VM_COUNTERS::PeakPagefileUsage
unsigned long PeakPagefileUsage
Definition: ProcessDescriptor.h:71
System::QUOTA_LIMITS::PagefileLimit
unsigned long PagefileLimit
Definition: ProcessDescriptor.h:38
System::priorityBoost
GAUDI_API long priorityBoost(InfoType fetch=PriorityBoost, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:106
System::VM_COUNTERS::WorkingSetSize
unsigned long WorkingSetSize
Definition: ProcessDescriptor.h:65
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:150
System::GByte
Definition: Memory.h:56
System::VM_COUNTERS::PeakWorkingSetSize
unsigned long PeakWorkingSetSize
Definition: ProcessDescriptor.h:64
System::VM_COUNTERS::VirtualSize
unsigned long VirtualSize
Definition: ProcessDescriptor.h:62
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:114
System::PROCESS_BASIC_INFORMATION
Definition: ProcessDescriptor.h:19
System::VM_COUNTERS::PageFaultCount
unsigned long PageFaultCount
Definition: ProcessDescriptor.h:63
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:132
System::PROCESS_BASIC_INFORMATION::AffinityMask
unsigned long AffinityMask
Definition: ProcessDescriptor.h:22
System::affinityMask
GAUDI_API long affinityMask(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Affinity mask.
Definition: Memory.cpp:90
System::VM_COUNTERS::QuotaNonPagedPoolUsage
unsigned long QuotaNonPagedPoolUsage
Definition: ProcessDescriptor.h:69
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:255
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:159
System::NoFetch
Definition: SystemBase.h:19
System::VM_COUNTERS::PeakVirtualSize
unsigned long PeakVirtualSize
Definition: ProcessDescriptor.h:61
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:193
System::PROCESS_BASIC_INFORMATION::BasePriority
long BasePriority
Definition: ProcessDescriptor.h:23
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:204
System::PROCESS_BASIC_INFORMATION::InheritedFromUniqueProcessId
unsigned long InheritedFromUniqueProcessId
Definition: ProcessDescriptor.h:25
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:184
System::QUOTA_LIMITS
Process Quotas NtQueryInformationProcess using ProcessQuotaLimits NtQueryInformationProcess using Pro...
Definition: ProcessDescriptor.h:33
System::numPageFault
GAUDI_API long numPageFault(InfoType fetch=Memory, long pid=-1)
Basic Process Information: Number of page faults.
Definition: Memory.cpp:168
System::VM_COUNTERS
Process Virtual Memory Counters NtQueryInformationProcess using ProcessVmCounters.
Definition: ProcessDescriptor.h:60
System::virtualMemory
GAUDI_API long virtualMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:239
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:221
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:75
System::ProcessBasics
Definition: SystemBase.h:19
System::basePriority
GAUDI_API long basePriority(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Base priority.
Definition: Memory.cpp:67
System::virtualMemoryPeak
GAUDI_API long virtualMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:247
System::QUOTA_LIMITS::MinimumWorkingSetSize
unsigned long MinimumWorkingSetSize
Definition: ProcessDescriptor.h:36
System::VM_COUNTERS::QuotaPeakNonPagedPoolUsage
unsigned long QuotaPeakNonPagedPoolUsage
Definition: ProcessDescriptor.h:68
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:176
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:141
System::InfoType
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:19
System::PROCESS_BASIC_INFORMATION::ExitStatus
long ExitStatus
Definition: ProcessDescriptor.h:20
System::VM_COUNTERS::QuotaPagedPoolUsage
unsigned long QuotaPagedPoolUsage
Definition: ProcessDescriptor.h:67