Gaudi Framework, version v23r9

Home   Generated: Thu Jul 18 2013
 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 
35 long System::adjustMemory( MemoryUnit unit, long value ) {
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 

Generated at Thu Jul 18 2013 12:18:04 for Gaudi Framework, version v23r9 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004