The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
Memory.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#include "ProcessDescriptor.h"
12#include <GaudiKernel/Memory.h>
13#include <libgen.h>
14#include <limits.h>
15#include <sys/times.h>
16#include <unistd.h>
17
19long System::adjustMemory( MemoryUnit unit, long value ) {
20 if ( value != -1 ) {
21 switch ( unit ) {
22 case Byte:
23 break;
24 case kByte:
25 value = value / 1024;
26 break;
27 case MByte:
28 value = ( value / 1024 ) / 1024;
29 break;
30 case GByte:
31 value = ( ( value / 1024 ) / 1024 ) / 1024;
32 break;
33 case TByte:
34 value = ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024;
35 break;
36 case PByte:
37 value = ( ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024;
38 break;
39 case EByte:
40 value = ( ( ( ( ( value / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024 ) / 1024;
41 break;
42 default:
43 value = -1;
44 break;
45 }
46 }
47 return value;
48}
49
51long System::basePriority( InfoType fetch, long pid ) {
53 if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.BasePriority;
54 return 0;
55}
56
59 static const long s_pid = ::getpid();
60 return s_pid;
61}
62
64long System::parentID( InfoType fetch, long pid ) {
66 if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.InheritedFromUniqueProcessId;
67 return 0;
68}
69
71long System::affinityMask( InfoType fetch, long pid ) {
73 if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.AffinityMask;
74 return 0;
75}
76
78long System::exitStatus( InfoType fetch, long pid ) {
80 if ( fetch != NoFetch && getProcess()->query( pid, ProcessBasics, &info ) ) return info.ExitStatus;
81 return -2;
82}
83
85long System::priorityBoost( InfoType fetch, long pid ) {
86 long info;
87 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return info;
88 return -2;
89}
90
92long System::nonPagedMemoryPeak( MemoryUnit unit, InfoType fetch, long pid ) {
93 VM_COUNTERS info;
94 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
95 return adjustMemory( unit, info.QuotaPeakNonPagedPoolUsage );
96 return -2;
97}
98
100long System::nonPagedMemory( MemoryUnit unit, InfoType fetch, long pid ) {
101 VM_COUNTERS info;
102 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
103 return adjustMemory( unit, info.QuotaNonPagedPoolUsage );
104 return -2;
105}
106
108long System::nonPagedMemoryLimit( MemoryUnit unit, InfoType fetch, long pid ) {
110 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
111 return adjustMemory( unit, quota.NonPagedPoolLimit );
112 return 0;
113}
114
116long System::pagedMemory( MemoryUnit unit, InfoType fetch, long pid ) {
117 VM_COUNTERS info;
118 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
119 return adjustMemory( unit, info.QuotaPagedPoolUsage );
120 return -2;
121}
122
124long System::pagedMemoryPeak( MemoryUnit unit, InfoType fetch, long pid ) {
125 VM_COUNTERS info;
126 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
127 return adjustMemory( unit, info.QuotaPeakPagedPoolUsage );
128 return -2;
129}
130
132long System::pagedMemoryLimit( MemoryUnit unit, InfoType fetch, long pid ) {
134 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
135 return adjustMemory( unit, quota.PagedPoolLimit );
136 return 0;
137}
138
140long System::numPageFault( InfoType fetch, long pid ) {
141 VM_COUNTERS info;
142 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return info.PageFaultCount;
143 return -2;
144}
145
147long System::pagefileUsage( MemoryUnit unit, InfoType fetch, long pid ) {
148 VM_COUNTERS info;
149 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.PagefileUsage );
150 return -2;
151}
152
154long System::pagefileUsagePeak( MemoryUnit unit, InfoType fetch, long pid ) {
155 VM_COUNTERS info;
156 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
157 return adjustMemory( unit, info.PeakPagefileUsage );
158 return -2;
159}
160
162long System::pagefileUsageLimit( MemoryUnit unit, InfoType fetch, long pid ) {
164 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
165 if ( long( quota.PagefileLimit ) < 0 ) return -1; // LONG_MAX;
166 return adjustMemory( unit, quota.PagefileLimit );
167 }
168 return -2;
169}
170
172long System::mappedMemory( MemoryUnit unit, InfoType fetch, long pid ) {
173 VM_COUNTERS info;
174 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.WorkingSetSize );
175 return -2;
176}
177
179long System::mappedMemoryPeak( MemoryUnit unit, InfoType fetch, long pid ) {
180 VM_COUNTERS info;
181 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) )
182 return adjustMemory( unit, info.PeakWorkingSetSize );
183 return -2;
184}
185
187long System::minMemoryLimit( MemoryUnit unit, InfoType fetch, long pid ) {
188 QUOTA_LIMITS quota;
189 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
190 return adjustMemory( unit, quota.MinimumWorkingSetSize );
191 return 0;
192}
193
195long System::maxMemoryLimit( MemoryUnit unit, InfoType fetch, long pid ) {
196 QUOTA_LIMITS quota;
197 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) )
198 return adjustMemory( unit, quota.MaximumWorkingSetSize );
199 return 0;
200}
201
203long System::virtualMemory( MemoryUnit unit, InfoType fetch, long pid ) {
204 VM_COUNTERS info;
205 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.VirtualSize );
206 return -2;
207}
208
210long System::virtualMemoryPeak( MemoryUnit unit, InfoType fetch, long pid ) {
211 VM_COUNTERS info;
212 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) return adjustMemory( unit, info.PeakVirtualSize );
213 return -2;
214}
215
217long System::virtualMemoryLimit( MemoryUnit unit, InfoType fetch, long pid ) {
218 QUOTA_LIMITS quota;
219 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
220 if ( long( quota.PagefileLimit ) == -1 ) return -1; // LONG_MAX;
221 return adjustMemory( unit, quota.PagefileLimit );
222 }
223 return 0;
224}
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:132
GAUDI_API long affinityMask(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Affinity mask.
Definition Memory.cpp:71
GAUDI_API long procID()
Basic Process Information: Process ID.
Definition Memory.cpp:58
GAUDI_API long pagefileUsage(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Current page file usage.
Definition Memory.cpp:147
GAUDI_API long adjustMemory(MemoryUnit typ, long value)
Convert time from kByte to requested representation (Experts only)
Definition Memory.cpp:19
GAUDI_API long pagefileUsagePeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: Peak usage of page file.
Definition Memory.cpp:154
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:195
GAUDI_API long parentID(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Parent's process ID.
Definition Memory.cpp:64
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:116
GAUDI_API long mappedMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition Memory.cpp:172
GAUDI_API long virtualMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition Memory.cpp:210
GAUDI_API long numPageFault(InfoType fetch=Memory, long pid=-1)
Basic Process Information: Number of page faults.
Definition Memory.cpp:140
InfoType
Enumeration for fetching information.
Definition SystemBase.h:15
@ NoFetch
Definition SystemBase.h:15
@ ProcessBasics
Definition SystemBase.h:15
GAUDI_API long pagefileUsageLimit(MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
Basic Process Information: Peak usage of page file.
Definition Memory.cpp:162
MemoryUnit
Unit of memory.
Definition Memory.h:50
@ kByte
Definition Memory.h:50
@ MByte
Definition Memory.h:50
@ TByte
Definition Memory.h:50
@ GByte
Definition Memory.h:50
@ PByte
Definition Memory.h:50
@ EByte
Definition Memory.h:50
@ Byte
Definition Memory.h:50
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:124
GAUDI_API long priorityBoost(InfoType fetch=PriorityBoost, long pid=-1)
Basic Process Information: priority boost.
Definition Memory.cpp:85
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:217
GAUDI_API long basePriority(InfoType fetch=ProcessBasics, long pid=-1)
Basic Process Information: Base priority.
Definition Memory.cpp:51
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:187
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:92
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:100
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:108
GAUDI_API long mappedMemoryPeak(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition Memory.cpp:179
ProcessDescriptor * getProcess()
Retrieve Process structure.
GAUDI_API long virtualMemory(MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
Basic Process Information: priority boost.
Definition Memory.cpp:203
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:78
Process Pooled Quota Usage and Limits NtQueryInformationProcess using ProcessPooledUsageAndLimits.
Process Quotas NtQueryInformationProcess using ProcessQuotaLimits NtQueryInformationProcess using Pro...
unsigned long MaximumWorkingSetSize
unsigned long MinimumWorkingSetSize
unsigned long PagefileLimit
Process Virtual Memory Counters NtQueryInformationProcess using ProcessVmCounters.
unsigned long PeakPagefileUsage
unsigned long QuotaPeakNonPagedPoolUsage
unsigned long QuotaNonPagedPoolUsage
unsigned long PeakWorkingSetSize
unsigned long QuotaPagedPoolUsage
unsigned long VirtualSize
unsigned long PagefileUsage
unsigned long WorkingSetSize
unsigned long PageFaultCount
unsigned long PeakVirtualSize
unsigned long QuotaPeakPagedPoolUsage