Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 ) {
68  if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.BasePriority;
69  return 0;
70 }
71 
74  static const long s_pid = ::getpid();
75  return s_pid;
76 }
77 
79 long System::parentID( InfoType fetch, long pid ) {
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 ) {
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 ) {
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 ) {
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 ) {
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 ) {
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 }
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
GAUDI_API long mappedMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:194
unsigned long QuotaPeakPagedPoolUsage
GAUDI_API long parentID(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Parent&#39;s process ID.
Definition: Memory.cpp:79
unsigned long PagefileUsage
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
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
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:34
unsigned long MaximumWorkingSetSize
unsigned long PeakPagefileUsage
unsigned long PagefileLimit
GAUDI_API long priorityBoost(InfoType fetch=PriorityBoost, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:100
unsigned long WorkingSetSize
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:139
unsigned long PeakWorkingSetSize
unsigned long VirtualSize
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
unsigned long PageFaultCount
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
GAUDI_API long affinityMask(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Affinity mask.
Definition: Memory.cpp:86
unsigned long QuotaNonPagedPoolUsage
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
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:147
unsigned long PeakVirtualSize
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
MemoryUnit
Unit of memory.
Definition: Memory.h:55
GAUDI_API long mappedMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:187
ProcessDescriptor * getProcess()
Retrieve Process structure.
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
Process Quotas NtQueryInformationProcess using ProcessQuotaLimits NtQueryInformationProcess using Pro...
GAUDI_API long numPageFault(InfoType fetch=Memory, long pid=-1)
Basic Process Information: Number of page faults.
Definition: Memory.cpp:155
Process Virtual Memory Counters NtQueryInformationProcess using ProcessVmCounters.
GAUDI_API long virtualMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:218
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
Process Pooled Quota Usage and Limits NtQueryInformationProcess using ProcessPooledUsageAndLimits.
GAUDI_API long procID()
Basic Process Information: Process ID.
Definition: Memory.cpp:73
GAUDI_API long basePriority(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Base priority.
Definition: Memory.cpp:66
GAUDI_API long virtualMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:225
unsigned long MinimumWorkingSetSize
unsigned long QuotaPeakNonPagedPoolUsage
GAUDI_API long pagefileUsage(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Current page file usage.
Definition: Memory.cpp:162
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:131
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:18
unsigned long QuotaPagedPoolUsage