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 <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) {
53  if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
54  return info.BasePriority;
55  return 0;
56 }
57 
60  static const long s_pid = ::getpid();
61  return s_pid;
62 }
63 
65 long System::parentID(InfoType fetch, long pid) {
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) {
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) {
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) {
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) {
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) {
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 
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
GAUDI_API long mappedMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:188
unsigned long QuotaPeakPagedPoolUsage
GAUDI_API long parentID(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Parent&#39;s process ID.
Definition: Memory.cpp:65
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:81
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
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:89
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:129
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:97
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:113
GAUDI_API long affinityMask(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Affinity mask.
Definition: Memory.cpp:73
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:228
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
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:169
MemoryUnit
Unit of memory.
Definition: Memory.h:56
GAUDI_API long mappedMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:180
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:161
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:145
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:212
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
Process Pooled Quota Usage and Limits NtQueryInformationProcess using ProcessPooledUsageAndLimits.
GAUDI_API long procID()
Basic Process Information: Process ID.
Definition: Memory.cpp:59
GAUDI_API long basePriority(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Base priority.
Definition: Memory.cpp:51
GAUDI_API long virtualMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:220
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:153
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
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:18
unsigned long QuotaPagedPoolUsage