| The Gaudi Framework v32r1 (f65d50dc)

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 if ( value != -1 ) {
36 switch ( unit ) {
37 case Byte:
38 break;
39 case kByte:
40 value = value / 1024;
41 break;
42 case MByte:
43 value = ( value / 1024 ) / 1024;
44 break;
45 case GByte:
46 value = ( ( value / 1024 ) / 1024 ) / 1024;
47 break;
48 case TByte:
49 value = ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024;
50 break;
51 case PByte:
52 value = ( ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024;
53 break;
54 case EByte:
55 value = ( ( ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024;
56 break;
57 default:
58 value = -1;
59 break;
60 }
61 }
62 return value;
63 }
64
66 long System::basePriority( InfoType fetch, long pid ) {
67 PROCESS_BASIC_INFORMATION info;
68 if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.BasePriority;
69 return 0;
70 }
71
73 long System::procID() {
74 static const long s_pid = ::getpid();
75 return s_pid;
76 }
77
79 long System::parentID( InfoType fetch, long pid ) {
80 PROCESS_BASIC_INFORMATION info;
81 if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.InheritedFromUniqueProcessId;
82 return 0;
83 }
84
86 long System::affinityMask( InfoType fetch, long pid ) {
87 PROCESS_BASIC_INFORMATION info;
88 if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.AffinityMask;
89 return 0;
90 }
91
93 long System::exitStatus( InfoType fetch, long pid ) {
94 PROCESS_BASIC_INFORMATION info;
95 if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.ExitStatus;
96 return -2;
97 }
98
100 long System::priorityBoost( InfoType fetch, long pid ) {
101 long info;
102 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return info;
103 return -2;
104 }
105
107 long System::nonPagedMemoryPeak( MemoryUnit unit, InfoType fetch, long pid ) {
108 VM_COUNTERS info;
109 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
110 return adjustMemory( unit, info.QuotaPeakNonPagedPoolUsage );
111 return -2;
112 }
113
115 long System::nonPagedMemory( MemoryUnit unit, InfoType fetch, long pid ) {
116 VM_COUNTERS info;
117 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
118 return adjustMemory( unit, info.QuotaNonPagedPoolUsage );
119 return -2;
120 }
121
123 long System::nonPagedMemoryLimit( MemoryUnit unit, InfoType fetch, long pid ) {
124 POOLED_USAGE_AND_LIMITS quota;
125 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
126 return adjustMemory( unit, quota.NonPagedPoolLimit );
127 return 0;
128 }
129
131 long System::pagedMemory( MemoryUnit unit, InfoType fetch, long pid ) {
132 VM_COUNTERS info;
133 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
134 return adjustMemory( unit, info.QuotaPagedPoolUsage );
135 return -2;
136 }
137
139 long System::pagedMemoryPeak( MemoryUnit unit, InfoType fetch, long pid ) {
140 VM_COUNTERS info;
141 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
142 return adjustMemory( unit, info.QuotaPeakPagedPoolUsage );
143 return -2;
144 }
145
147 long System::pagedMemoryLimit( MemoryUnit unit, InfoType fetch, long pid ) {
148 POOLED_USAGE_AND_LIMITS quota;
149 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
150 return adjustMemory( unit, quota.PagedPoolLimit );
151 return 0;
152 }
153
155 long System::numPageFault( InfoType fetch, long pid ) {
156 VM_COUNTERS info;
157 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return info.PageFaultCount;
158 return -2;
159 }
160
162 long System::pagefileUsage( MemoryUnit unit, InfoType fetch, long pid ) {
163 VM_COUNTERS info;
164 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.PagefileUsage );
165 return -2;
166 }
167
169 long System::pagefileUsagePeak( MemoryUnit unit, InfoType fetch, long pid ) {
170 VM_COUNTERS info;
171 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
172 return adjustMemory( unit, info.PeakPagefileUsage );
173 return -2;
174 }
175
177 long System::pagefileUsageLimit( MemoryUnit unit, InfoType fetch, long pid ) {
178 POOLED_USAGE_AND_LIMITS quota;
179 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
180 if ( long( quota.PagefileLimit ) < 0 ) return -1; // LONG_MAX;
181 return adjustMemory( unit, quota.PagefileLimit );
182 }
183 return -2;
184 }
185
187 long System::mappedMemory( MemoryUnit unit, InfoType fetch, long pid ) {
188 VM_COUNTERS info;
189 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.WorkingSetSize );
190 return -2;
191 }
192
194 long System::mappedMemoryPeak( MemoryUnit unit, InfoType fetch, long pid ) {
195 VM_COUNTERS info;
196 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
197 return adjustMemory( unit, info.PeakWorkingSetSize );
198 return -2;
199 }
200
202 long System::minMemoryLimit( MemoryUnit unit, InfoType fetch, long pid ) {
203 QUOTA_LIMITS quota;
204 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
205 return adjustMemory( unit, quota.MinimumWorkingSetSize );
206 return 0;
207 }
208
210 long System::maxMemoryLimit( MemoryUnit unit, InfoType fetch, long pid ) {
211 QUOTA_LIMITS quota;
212 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
213 return adjustMemory( unit, quota.MaximumWorkingSetSize );
214 return 0;
215 }
216
218 long System::virtualMemory( MemoryUnit unit, InfoType fetch, long pid ) {
219 VM_COUNTERS info;
220 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.VirtualSize );
221 return -2;
222 }
223
225 long System::virtualMemoryPeak( MemoryUnit unit, InfoType fetch, long pid ) {
226 VM_COUNTERS info;
227 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.PeakVirtualSize );
228 return -2;
229 }
230
232 long System::virtualMemoryLimit( MemoryUnit unit, InfoType fetch, long pid ) {
233 QUOTA_LIMITS quota;
234 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
235 if ( long( quota.PagefileLimit ) == -1 ) return -1; // LONG_MAX;
236 return adjustMemory( unit, quota.PagefileLimit );
237 }
238 return 0;
239 }
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:210
System::mappedMemoryPeak
GAUDI_API long mappedMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:194
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's process ID.
Definition: Memory.cpp:79
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:93
System::TByte
Definition: Memory.h:55
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:115
System::PByte
Definition: Memory.h:55
System::MByte
Definition: Memory.h:55
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:100
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 'pid'.
Definition: Memory.cpp:139
System::GByte
Definition: Memory.h:55
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:55
System::POOLED_USAGE_AND_LIMITS::PagedPoolLimit
unsigned long PagedPoolLimit
Definition: ProcessDescriptor.h:79
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:107
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:123
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:86
System::VM_COUNTERS::QuotaNonPagedPoolUsage
unsigned long QuotaNonPagedPoolUsage
Definition: ProcessDescriptor.h:68
System::POOLED_USAGE_AND_LIMITS::PagefileLimit
unsigned long PagefileLimit
Definition: ProcessDescriptor.h:85
System::Byte
Definition: Memory.h:55
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:232
System::POOLED_USAGE_AND_LIMITS::NonPagedPoolLimit
unsigned long NonPagedPoolLimit
Definition: ProcessDescriptor.h:82
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 'pid'.
Definition: Memory.cpp:147
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:177
System::PROCESS_BASIC_INFORMATION::BasePriority
long BasePriority
Definition: ProcessDescriptor.h:22
System::MemoryUnit
MemoryUnit
Unit of memory.
Definition: Memory.h:55
System::mappedMemory
GAUDI_API long mappedMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:187
System::PROCESS_BASIC_INFORMATION::InheritedFromUniqueProcessId
unsigned long InheritedFromUniqueProcessId
Definition: ProcessDescriptor.h:24
Memory.h
System::getProcess
ProcessDescriptor * getProcess()
Retrieve Process structure.
Definition: ProcessDescriptor.h:132
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:169
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:155
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:218
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:202
System::EByte
Definition: Memory.h:55
System::POOLED_USAGE_AND_LIMITS
Process Pooled Quota Usage and Limits NtQueryInformationProcess using ProcessPooledUsageAndLimits.
Definition: ProcessDescriptor.h:76
System::procID
GAUDI_API long procID()
Basic Process Information: Process ID.
Definition: Memory.cpp:73
System::ProcessBasics
Definition: SystemBase.h:18
System::basePriority
GAUDI_API long basePriority(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Base priority.
Definition: Memory.cpp:66
System::virtualMemoryPeak
GAUDI_API long virtualMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:225
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:162
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 'pid'.
Definition: Memory.cpp:131
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