All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Memory.cpp
Go to the documentation of this file.
1 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/src/Lib/Memory.cpp,v 1.1 2001/03/14 15:30:16 mato Exp $
2 //====================================================================
3 // Memory.cpp
4 //--------------------------------------------------------------------
5 //
6 // Package : System (The LHCb System service)
7 //
8 // Description: Information of memory usage from a given process
9 //
10 // Author : M.Frank
11 // Created : 13/11/00
12 // Changes :
13 //
14 //====================================================================
15 #define GAUDIKERNEL_MEMORY_CPP
16 
17 #ifdef _WIN32
18 #include "process.h"
19  #define getpid _getpid
20 #else
21  #include <errno.h>
22  #include <string.h>
23  #include "sys/times.h"
24  #include "unistd.h"
25  #include "libgen.h"
26  #include <cstdio>
27 #endif
28 
29 // Framework include files
30 #include <limits.h>
31 #include "GaudiKernel/Memory.h"
32 #include "ProcessDescriptor.h"
33 
36  if ( value != -1 ) {
37  switch ( unit ) {
38  case Byte: break;
39  case kByte: value = value/1024; break;
40  case MByte: value = (value/1024)/1024; break;
41  case GByte: value = ((value/1024)/1024)/1024; break;
42  case TByte: value = (((value/1024)/1024)/1024)/1024; break;
43  case PByte: value = ((((value/1024)/1024)/1024)/1024)/1024; break;
44  case EByte: value = (((((value/1024)/1024)/1024)/1024)/1024)/1024; break;
45  default: value = -1; break;
46  }
47  }
48  return value;
49 }
50 
52 long System::basePriority(InfoType fetch, long pid) {
54  if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
55  return info.BasePriority;
56  return 0;
57 }
58 
61  static long s_pid = ::getpid();
62  return s_pid;
63 }
64 
66 long System::parentID(InfoType fetch, long pid) {
68  if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
69  return info.InheritedFromUniqueProcessId;
70  return 0;
71 }
72 
74 long System::affinityMask(InfoType fetch, long pid) {
76  if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
77  return info.AffinityMask;
78  return 0;
79 }
80 
82 long System::exitStatus(InfoType fetch, long pid) {
84  if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
85  return info.ExitStatus;
86  return -2;
87 }
88 
90 long System::priorityBoost(InfoType fetch, long pid) {
91  long info;
92  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
93  return info;
94  return -2;
95 }
96 
98 long System::nonPagedMemoryPeak(MemoryUnit unit, InfoType fetch, long pid) {
99  VM_COUNTERS info;
100  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
101  return adjustMemory(unit, info.QuotaPeakNonPagedPoolUsage);
102  return -2;
103 }
104 
106 long System::nonPagedMemory(MemoryUnit unit, InfoType fetch, long pid) {
107  VM_COUNTERS info;
108  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
109  return adjustMemory(unit, info.QuotaNonPagedPoolUsage);
110  return -2;
111 }
112 
114 long System::nonPagedMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) {
116  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
117  return adjustMemory(unit, quota.NonPagedPoolLimit);
118  return 0;
119 }
120 
122 long System::pagedMemory(MemoryUnit unit, InfoType fetch, long pid) {
123  VM_COUNTERS info;
124  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
125  return adjustMemory(unit, info.QuotaPagedPoolUsage);
126  return -2;
127 }
128 
130 long System::pagedMemoryPeak(MemoryUnit unit, InfoType fetch, long pid) {
131  VM_COUNTERS info;
132  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
133  return adjustMemory(unit, info.QuotaPeakPagedPoolUsage);
134  return -2;
135 }
136 
138 long System::pagedMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) {
140  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
141  return adjustMemory(unit, quota.PagedPoolLimit);
142  return 0;
143 }
144 
146 long System::numPageFault(InfoType fetch, long pid) {
147  VM_COUNTERS info;
148  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
149  return info.PageFaultCount;
150  return -2;
151 }
152 
154 long System::pagefileUsage(MemoryUnit unit, InfoType fetch, long pid) {
155  VM_COUNTERS info;
156  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
157  return adjustMemory(unit, info.PagefileUsage);
158  return -2;
159 }
160 
162 long System::pagefileUsagePeak(MemoryUnit unit, InfoType fetch, long pid) {
163  VM_COUNTERS info;
164  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
165  return adjustMemory(unit, info.PeakPagefileUsage);
166  return -2;
167 }
168 
170 long System::pagefileUsageLimit(MemoryUnit unit, InfoType fetch, long pid) {
172  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) ) {
173  if ( long(quota.PagefileLimit) < 0 )
174  return -1;//LONG_MAX;
175  return adjustMemory(unit, quota.PagefileLimit);
176  }
177  return -2;
178 }
179 
181 long System::mappedMemory(MemoryUnit unit, InfoType fetch, long pid) {
182  VM_COUNTERS info;
183  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
184  return adjustMemory(unit, info.WorkingSetSize);
185  return -2;
186 }
187 
189 long System::mappedMemoryPeak(MemoryUnit unit, InfoType fetch, long pid) {
190  VM_COUNTERS info;
191  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
192  return adjustMemory(unit, info.PeakWorkingSetSize);
193  return -2;
194 }
195 
197 long System::minMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) {
198  QUOTA_LIMITS quota;
199  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
200  return adjustMemory(unit, quota.MinimumWorkingSetSize);
201  return 0;
202 }
203 
205 long System::maxMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) {
206  QUOTA_LIMITS quota;
207  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
208  return adjustMemory(unit, quota.MaximumWorkingSetSize);
209  return 0;
210 }
211 
213 long System::virtualMemory(MemoryUnit unit, InfoType fetch, long pid) {
214  VM_COUNTERS info;
215  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
216  return adjustMemory(unit, info.VirtualSize);
217  return -2;
218 }
219 
221 long System::virtualMemoryPeak(MemoryUnit unit, InfoType fetch, long pid) {
222  VM_COUNTERS info;
223  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
224  return adjustMemory(unit, info.PeakVirtualSize);
225  return -2;
226 }
227 
229 long System::virtualMemoryLimit(MemoryUnit unit, InfoType fetch, long pid) {
230  QUOTA_LIMITS quota;
231  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) ) {
232  if ( long(quota.PagefileLimit) == -1 )
233  return -1;//LONG_MAX;
234  return adjustMemory(unit, quota.PagefileLimit);
235  }
236  return 0;
237 }
238 
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:205
GAUDI_API long mappedMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:189
unsigned long QuotaPeakPagedPoolUsage
GAUDI_API long parentID(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Parent's process ID.
Definition: Memory.cpp:66
ProcessDescriptor * getProcess()
Retrieve Process structure.
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:82
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:106
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition: Memory.cpp:35
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:90
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 'pid'. ...
Definition: Memory.cpp:130
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:98
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:114
GAUDI_API long affinityMask(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Affinity mask.
Definition: Memory.cpp:74
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:229
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:138
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:170
MemoryUnit
Unit of memory.
Definition: Memory.h:57
GAUDI_API long mappedMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:181
GAUDI_API long pagefileUsagePeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Peak usage of page file.
Definition: Memory.cpp:162
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:146
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:213
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:197
Process Pooled Quota Usage and Limits NtQueryInformationProcess using ProcessPooledUsageAndLimits.
GAUDI_API long procID()
Basic Process Information: Process ID.
Definition: Memory.cpp:60
GAUDI_API long basePriority(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Base priority.
Definition: Memory.cpp:52
GAUDI_API long virtualMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition: Memory.cpp:221
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:154
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:122
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:18
unsigned long QuotaPagedPoolUsage