The Gaudi Framework  v40r0 (475e45c1)
ProcessDescriptor.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 #ifndef __APPLE__
12 static const long TICK_TO_100NSEC = 100000;
13 #endif // not __APPLE__
14 
15 namespace System {
30  ProcessIoPortHandlers, // Note: this is kernel mode only
42  };
43 }
44 #ifdef _WIN32
45 # define strcasecmp _stricmp
46 # define strncasecmp _strnicmp
47 # define NOMSG
48 # define NOGDI
49 # include <process.h>
50 # include <windows.h>
51 # define getpid _getpid
52 namespace NtApi {
53  //__declspec(dllimport) long __stdcall NtQueryInformationProcess(
54  // typedef __declspec(dllimport) long __stdcall (*__NtQueryInformationProcess)(
55  // extern "C" long __cdecl NtQueryInformationProcess(
56 
57  typedef long( WINAPI* __NtQueryInformationProcess )(
58 
59  void* ProcessHandle, long ProcessInformationClass, void* ProcessInformation,
60  unsigned long ProcessInformationLength, unsigned long* ReturnLength );
61  __NtQueryInformationProcess NtQueryInformationProcess;
62 }; // namespace NtApi
63 #else // UNIX...: first the EGCS stuff, then the OS dependent includes
64 # define WINVER 0
65 # include <cstdio>
66 # include <errno.h>
67 # include <fcntl.h>
68 # include <iostream>
69 # include <libgen.h>
70 # include <sstream>
71 # include <string>
72 # include <sys/signal.h>
73 # include <sys/syscall.h>
74 # include <sys/times.h>
75 # include <sys/types.h>
76 # include <unistd.h>
77 # ifndef __APPLE__
78 # include <sys/procfs.h>
79 # endif
80 # include <cstdio>
81 # include <sys/resource.h>
82 # include <sys/time.h>
83 
84 /* Format of the Linux proc/stat (man 5 proc, kernel 2.6.35):
85  pid %d The process ID.
86 
87  comm %s The filename of the executable, in parentheses. This is visible
88  whether or not the executable is swapped out.
89 
90  state %c One character from the string "RSDZTW" where R is running, S is
91  sleeping in an interruptible wait, D is waiting in uninterruptible
92  disk sleep, Z is zombie, T is traced or stopped (on a signal), and
93  W is paging.
94 
95  ppid %d The PID of the parent.
96 
97  pgrp %d The process group ID of the process.
98 
99  session %d The session ID of the process.
100 
101  tty_nr %d The controlling terminal of the process. (The minor device number
102  is contained in the combination of bits 31 to 20 and 7 to 0; the
103  major device number is in bits 15 t0 8.)
104 
105  tpgid %d The ID of the foreground process group of the controlling terminal
106  of the process.
107 
108  flags %u (%lu before Linux 2.6.22)
109  The kernel flags word of the process. For bit meanings, see the
110  PF_* defines in <linux/sched.h>. Details depend on the kernel
111  version.
112 
113  minflt %lu The number of minor faults the process has made which have not
114  required loading a memory page from disk.
115 
116  cminflt %lu The number of minor faults that the process's waited-for children
117  have made.
118 
119  majflt %lu The number of major faults the process has made which have
120  required loading a memory page from disk.
121 
122  cmajflt %lu The number of major faults that the process's waited-for children
123  have made.
124 
125  utime %lu Amount of time that this process has been scheduled in user mode,
126  measured in clock ticks (divide by sysconf(_SC_CLK_TCK). This
127  includes guest time, guest_time (time spent running a virtual CPU,
128  see below), so that applications that are not aware of the guest
129  time field do not lose that time from their calculations.
130 
131  stime %lu Amount of time that this process has been scheduled in kernel
132  mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK).
133 
134  cutime %ld Amount of time that this process's waited-for children have been
135  scheduled in user mode, measured in clock ticks (divide by
136  sysconf(_SC_CLK_TCK). (See also times(2).) This includes guest
137  time, cguest_time (time spent running a virtual CPU, see below).
138 
139  cstime %ld Amount of time that this process's waited-for children have been
140  scheduled in kernel mode, measured in clock ticks (divide by
141  sysconf(_SC_CLK_TCK).
142 
143  priority %ld
144  (Explanation for Linux 2.6) For processes running a real-time
145  scheduling policy (policy below; see sched_setscheduler(2)), this
146  is the negated scheduling priority, minus one; that is, a number
147  in the range -2 to -100, corresponding to real-time priorities 1
148  to 99. For processes running under a non-real-time scheduling
149  policy, this is the raw nice value (setpriority(2)) as represented
150  in the kernel. The kernel stores nice values as numbers in the
151  range 0 (high) to 39 (low), corresponding to the user-visible nice
152  range of -20 to 19.
153 
154  Before Linux 2.6, this was a scaled value based on the scheduler
155  weighting given to this process.
156 
157  nice %ld The nice value (see setpriority(2)), a value in the range 19 (low
158  priority) to -20 (high priority).
159 
160  num_threads %ld
161  Number of threads in this process (since Linux 2.6). Before ker‐
162  nel 2.6, this field was hard coded to 0 as a placeholder for an
163  earlier removed field.
164 
165  itrealvalue %ld
166  The time in jiffies before the next SIGALRM is sent to the process
167  due to an interval timer. Since kernel 2.6.17, this field is no
168  longer maintained, and is hard coded as 0.
169 
170  starttime %llu (was %lu before Linux 2.6)
171  The time in jiffies the process started after system boot.
172 
173  vsize %lu Virtual memory size in bytes.
174 
175  rss %ld Resident Set Size: number of pages the process has in real memory.
176  This is just the pages which count towards text, data, or stack
177  space. This does not include pages which have not been demand-
178  loaded in, or which are swapped out.
179 
180  rsslim %lu Current soft limit in bytes on the rss of the process; see the
181  description of RLIMIT_RSS in getpriority(2).
182 
183  startcode %lu
184  The address above which program text can run.
185 
186  endcode %lu The address below which program text can run.
187 
188  startstack %lu
189  The address of the start (i.e., bottom) of the stack.
190 
191  kstkesp %lu The current value of ESP (stack pointer), as found in the kernel
192  stack page for the process.
193 
194  kstkeip %lu The current EIP (instruction pointer).
195 
196  signal %lu The bitmap of pending signals, displayed as a decimal number.
197  Obsolete, because it does not provide information on real-time
198  signals; use /proc/[pid]/status instead.
199 
200  blocked %lu The bitmap of blocked signals, displayed as a decimal number.
201  Obsolete, because it does not provide information on real-time
202  signals; use /proc/[pid]/status instead.
203 
204  sigignore %lu
205  The bitmap of ignored signals, displayed as a decimal number.
206  Obsolete, because it does not provide information on real-time
207  signals; use /proc/[pid]/status instead.
208 
209  sigcatch %lu
210  The bitmap of caught signals, displayed as a decimal number.
211  Obsolete, because it does not provide information on real-time
212  signals; use /proc/[pid]/status instead.
213 
214  wchan %lu This is the "channel" in which the process is waiting. It is the
215  address of a system call, and can be looked up in a namelist if
216  you need a textual name. (If you have an up-to-date
217  /etc/psdatabase, then try ps -l to see the WCHAN field in action.)
218 
219  nswap %lu Number of pages swapped (not maintained).
220 
221  cnswap %lu Cumulative nswap for child processes (not maintained).
222 
223  exit_signal %d (since Linux 2.1.22)
224  Signal to be sent to parent when we die.
225 
226  processor %d (since Linux 2.2.8)
227  CPU number last executed on.
228 
229  rt_priority %u (since Linux 2.5.19; was %lu before Linux 2.6.22)
230  Real-time scheduling priority, a number in the range 1 to 99 for
231  processes scheduled under a real-time policy, or 0, for non-real-
232  time processes (see sched_setscheduler(2)).
233 
234  policy %u (since Linux 2.5.19; was %lu before Linux 2.6.22)
235  Scheduling policy (see sched_setscheduler(2)). Decode using the
236  SCHED_* constants in linux/sched.h.
237 
238  delayacct_blkio_ticks %llu (since Linux 2.6.18)
239  Aggregated block I/O delays, measured in clock ticks (centisec‐
240  onds).
241 
242  guest_time %lu (since Linux 2.6.24)
243  Guest time of the process (time spent running a virtual CPU for a
244  guest operating system), measured in clock ticks (divide by
245  sysconf(_SC_CLK_TCK).
246 
247  cguest_time %ld (since Linux 2.6.24)
248  Guest time of the process's children, measured in clock ticks
249  (divide by sysconf(_SC_CLK_TCK).
250 */
251 struct linux_proc {
252  int pid;
253  char comm[400];
254  char state;
255  int ppid;
256  int pgrp;
257  int session;
258  int tty;
259  int tpgid;
260  unsigned long flags;
261  unsigned long minflt;
262  unsigned long cminflt;
263  unsigned long majflt;
264  unsigned long cmajflt;
265  unsigned long utime;
266  unsigned long stime;
267  long cutime;
268  long cstime;
269  long priority;
270  long nice;
273  unsigned long long starttime;
274  unsigned long vsize;
275  long rss;
276  unsigned long rlim;
277  unsigned long startcode;
278  unsigned long endcode;
279  unsigned long startstack;
280  unsigned long kstkesp;
281  unsigned long kstkeip;
282  unsigned long signal;
283  unsigned long blocked;
284  unsigned long sigignore;
285  unsigned long sigcatch;
286  unsigned long wchan;
287 };
288 
289 # ifdef __APPLE__
290 // static long pg_size = 0;
291 # else
292 static long pg_size = sysconf( _SC_PAGESIZE ); // getpagesize();
293 # endif
294 void readProcStat( long pid, linux_proc& pinfo ) {
295 
296  ssize_t cnt;
297  int fd;
298  char buf[512];
299 
300  std::ostringstream ost;
301 
302  ost << "/proc/" << pid << "/stat";
303  std::string fname = ost.str();
304  if ( ( fd = open( fname.c_str(), O_RDONLY ) ) < 0 ) {
305  std::cerr << "Failed to open " << ost.str() << std::endl;
306  return;
307  }
308 
309  lseek( fd, 0, SEEK_SET );
310  if ( ( cnt = read( fd, buf, sizeof( buf ) - 1 ) ) < 0 ) {
311  std::cout << "LINUX Read of Proc file failed:" << std::endl;
312  close( fd );
313  return;
314  }
315 
316  // Format
317  if ( cnt > 0 ) {
318  buf[cnt] = '\0';
319  sscanf(
320  buf,
321  // 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 20 1 2 3 4 5 6 7 8 9
322  // 30 1 2 3 4 5
323  "%d %400s %c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %llu %lu %ld %lu %lu %lu %lu "
324  "%lu %lu %lu %lu %lu %lu %lu",
325  &pinfo.pid, pinfo.comm, &pinfo.state, &pinfo.ppid, &pinfo.pgrp, &pinfo.session, &pinfo.tty, &pinfo.tpgid,
326  &pinfo.flags, &pinfo.minflt, &pinfo.cminflt, &pinfo.majflt, &pinfo.cmajflt, &pinfo.utime, &pinfo.stime,
327  &pinfo.cutime, &pinfo.cstime, &pinfo.priority, &pinfo.nice, &pinfo.num_threads, &pinfo.itrealvalue,
328  &pinfo.starttime, &pinfo.vsize, &pinfo.rss, &pinfo.rlim, &pinfo.startcode, &pinfo.endcode, &pinfo.startstack,
329  &pinfo.kstkesp, &pinfo.kstkeip, &pinfo.signal, &pinfo.blocked, &pinfo.sigignore, &pinfo.sigcatch,
330  &pinfo.wchan );
331  }
332  close( fd );
333 }
334 #endif
335 
336 // static long s_myPid = ::getpid();
337 // In order to properly support e.g. fork() calls, we cannot keep a copy of the pid!
338 
339 #ifndef __APPLE__
340 static inline long processID( long pid ) { return ( pid > 0 ) ? pid : ( ::getpid() ); }
341 #endif // not __APPLE__
342 
343 #include "ProcessDescriptor.h"
344 #include <GaudiKernel/ModuleInfo.h>
345 #include <GaudiKernel/System.h>
346 
348  if ( pid > 0 ) {
349  if ( pid != ::getpid() ) {
350 #ifdef _WIN32
351  m_handle = ::OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid );
352 #else
353  // Note: the return type of getpid is pid_t, which is int on 64bit machines too
354  m_handle = reinterpret_cast<void*>( static_cast<long>( ::getpid() ) );
355 #endif
356  m_needRelease = true;
357  return;
358  }
359  }
361  m_needRelease = false;
362 }
363 
365  if ( m_needRelease ) {
366 #ifdef _WIN32
367  ::CloseHandle( m_handle );
368 #else
369  m_handle = nullptr;
370 #endif
371  }
372 }
373 
375 #ifdef _WIN32
376  static bool first = true;
377  if ( first ) {
378  first = false;
379  void* mh = ::LoadLibrary( "NTDll.dll" );
380  if ( mh ) {
381  NtApi::NtQueryInformationProcess =
382  ( NtApi::__NtQueryInformationProcess )::GetProcAddress( (HINSTANCE)mh, "NtQueryInformationProcess" );
383  }
384  }
385 #endif
386 }
387 
389 
391  if ( info == 0 ) return 0;
392  long status = 1;
393 
394  if ( fetch == IO ) {
395 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
396  ProcessHandle h( pid );
397  status = NtApi::NtQueryInformationProcess( h.handle(), ProcessIoCounters, info, sizeof( IO_COUNTERS ), 0 );
398  status = ( status == 0 ) ? 1 : 0;
399 #elif defined( _WIN32 ) // Windows 95,98...
400 #elif defined( __linux )
401  linux_proc prc;
402  readProcStat( processID( pid ), prc );
403  rusage usage;
404  getrusage( RUSAGE_SELF, &usage );
405  info->ReadOperationCount = usage.ru_inblock;
406  info->WriteOperationCount = usage.ru_oublock;
407  info->OtherOperationCount = 0;
408  info->ReadTransferCount = usage.ru_inblock;
409  info->WriteTransferCount = usage.ru_oublock;
410  info->OtherTransferCount = 0;
411 #else // All Other
412  if ( pid ) {}
413 #endif // End ALL OS
414  }
415  return status;
416 }
417 
419  if ( info == 0 ) return 0;
420  long status = 1;
421 
422  if ( fetch == Quota ) {
423 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
424  ProcessHandle h( pid );
425  status = NtApi::NtQueryInformationProcess( h.handle(), ProcessPooledUsageAndLimits, info,
426  sizeof( POOLED_USAGE_AND_LIMITS ), 0 );
427  status = ( status == 0 ) ? 1 : 0;
428 #elif defined( _WIN32 ) // Windows 95,98...
429 #elif defined( __linux ) // Linux
430  // rusage usage;
431  // getrusage(RUSAGE_SELF, &usage);
432  rlimit lim;
433 
434  getrlimit( RLIMIT_DATA, &lim );
435  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
436  info->PeakPagedPoolUsage = lim.rlim_cur;
437  info->PagedPoolUsage = lim.rlim_cur;
438  info->PagedPoolLimit = lim.rlim_max;
439 
440  getrlimit( RLIMIT_STACK, &lim );
441  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
442  info->PeakNonPagedPoolUsage = lim.rlim_cur;
443  info->NonPagedPoolUsage = lim.rlim_cur;
444  info->NonPagedPoolLimit = lim.rlim_max;
445 
446  linux_proc prc;
447  readProcStat( processID( pid ), prc );
448  info->PeakPagefileUsage = prc.rss * pg_size;
449  info->PagefileUsage = prc.rss * pg_size;
450  info->PagefileLimit = 0xFFFFFFFF;
451 #elif defined( __APPLE__ )
452  if ( pid ) {}
453 #else // All Other
454  if ( pid ) {}
455 #endif // End ALL OS
456  }
457 
458  return status;
459 }
460 
461 long System::ProcessDescriptor::query( long pid, InfoType fetch, long* info ) {
462 
463  if ( info == 0 ) return 0;
464  long status = 1;
465 
466  switch ( fetch ) {
467  case PriorityBoost:
468 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
469  ProcessHandle h( pid );
470  status = NtApi::NtQueryInformationProcess( h.handle(), ProcessPriorityBoost, info, sizeof( long ), 0 );
471 #elif defined( _WIN32 ) // Windows 95,98...
472  if ( pid ) {}
473 #else
474  // Not applicable
475  if ( pid > 0 ) status = 0; // to avoid compiler warning
476  status = 0;
477  *info = 0;
478 #endif // End ALL OS
479  status = ( status == 0 ) ? 1 : 0;
480  break;
481  default:
482  status = -1;
483  *info = -1;
484  break;
485  }
486  return status;
487 }
488 
490  if ( info == 0 ) return 0;
491  long status = 1;
492 
493  if ( fetch == Memory ) {
494 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
495  ProcessHandle h( pid );
496  status = NtApi::NtQueryInformationProcess( h.handle(), ProcessVmCounters, info, sizeof( VM_COUNTERS ), 0 );
497  status = ( status == 0 ) ? 1 : 0;
498 #elif defined( _WIN32 ) // Windows 95,98...
499 #elif defined( __linux ) // Linux
500  const ssize_t bufsize = 1024;
501  char buf[bufsize];
502  pid = processID( pid );
503  sprintf( buf, "/proc/%ld/statm", pid );
504  long size, resident, share, trs, lrs, drs, dt;
505  int fd = open( buf, O_RDONLY );
506  ssize_t nread = read( fd, buf, bufsize );
507  close( fd );
508  if ( nread < bufsize && nread >= 0 ) buf[nread] = '\0';
509  fd = sscanf( buf, "%ld %ld %ld %ld %ld %ld %ld", &size, &resident, &share, &trs, &drs, &lrs, &dt );
510  linux_proc prc;
511  readProcStat( pid, prc );
512  info->PeakVirtualSize = prc.vsize;
513  info->VirtualSize = prc.vsize;
514  info->PeakWorkingSetSize = resident * pg_size;
515  info->WorkingSetSize = resident * pg_size;
516  info->QuotaPeakPagedPoolUsage = share * pg_size;
517  info->QuotaPagedPoolUsage = share * pg_size;
518  info->QuotaNonPagedPoolUsage = ( trs + drs ) * pg_size; // drs = data/stack size
519  info->QuotaPeakNonPagedPoolUsage = ( trs + drs ) * pg_size; // trs = VmExe size
520  info->PageFaultCount = prc.majflt + prc.minflt;
521  info->PagefileUsage = prc.vsize - resident * pg_size;
522  info->PeakPagefileUsage = prc.vsize - resident * pg_size;
523 #elif defined( __APPLE__ )
524  if ( pid ) {}
525 #else // All Other
526  if ( pid ) {}
527 #endif // End ALL OS
528  }
529  return status;
530 }
531 
533  if ( info == 0 ) return 0;
534  long status = 1;
535 
536  if ( fetch == Quota ) {
537 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
538  ProcessHandle h( pid );
539  status = NtApi::NtQueryInformationProcess( h.handle(), ProcessQuotaLimits, info, sizeof( QUOTA_LIMITS ), 0 );
540  status = ( status == 0 ) ? 1 : 0;
541 #elif defined( _WIN32 ) // Windows 95,98...
542 #elif defined( __linux ) // Linux
543  // On linux all this stuff typically is not set
544  // (ie. rlim_max=RLIM_INFINITY...)
545 
546  if ( pid > 0 && pid != ::getpid() ) return 0; // only possible for myself
547 
548  rlimit lim;
549  getrlimit( RLIMIT_DATA, &lim );
550  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
551  info->PagedPoolLimit = lim.rlim_max;
552 
553  getrlimit( RLIMIT_STACK, &lim );
554  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
555  info->NonPagedPoolLimit = lim.rlim_max;
556  info->MinimumWorkingSetSize = 0;
557 
558  getrlimit( RLIMIT_RSS, &lim );
559  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
560  info->MaximumWorkingSetSize = lim.rlim_max;
561 
562  getrlimit( RLIMIT_AS, &lim );
563  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
564  info->PagefileLimit = lim.rlim_max;
565 
566  getrlimit( RLIMIT_CPU, &lim );
567  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
568  info->TimeLimit = lim.rlim_max;
569 #elif defined( __APPLE__ )
570  if ( pid ) {}
571 #else // All Other
572  if ( pid ) {}
573 #endif // End ALL OS
574  }
575  return status;
576 }
577 
579  if ( info == 0 ) return 0;
580  long status = 1;
581 
582  if ( fetch == ProcessBasics ) {
583 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
584  ProcessHandle h( pid );
585  status = NtApi::NtQueryInformationProcess( h.handle(), ProcessBasicInformation, info,
586  sizeof( PROCESS_BASIC_INFORMATION ), 0 );
587  status = ( status == 0 ) ? 1 : 0;
588 #elif defined( _WIN32 ) // Windows 95,98...
589 #elif defined( __linux ) // Linux
590  linux_proc prc;
591  pid = processID( pid );
592  readProcStat( pid, prc );
593  info->ExitStatus = 0;
594  info->PebBaseAddress = (PPEB)prc.startcode;
595  info->BasePriority = 2 * 15 - prc.priority;
596  // std::cout << "Base Priority=" << info->BasePriority << "|"
597  // << prc.priority << std::endl;
598  info->AffinityMask = prc.flags;
599  // std::cout << "Flags =" << info->AffinityMask << "|"
600  // << prc.flags << std::endl;
601  info->UniqueProcessId = pid;
603 #else // All Other
604  if ( pid ) {}
605 #endif // End ALL OS
606  }
607  return status;
608 }
609 
611  if ( info == 0 ) return 0;
612  long status = 1;
613 
614  if ( fetch == Times ) {
615 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
616  ProcessHandle h( pid );
617  status = NtApi::NtQueryInformationProcess( h.handle(), ProcessTimes, info, sizeof( KERNEL_USER_TIMES ), 0 );
618  status = ( status == 0 ) ? 1 : 0;
619 #elif defined( _WIN32 ) // Windows 95,98...
620 #elif defined( __linux ) // Linux
621  static long long prc_start = 0;
622  bool myself = pid <= 0 || pid == ::getpid(); // avoid unnecessary calls to getpid if pid<0
623  if ( myself && prc_start == 0 ) { // called only once to set prc_start
624  linux_proc prc;
625  readProcStat( processID( pid ), prc );
626  // prc.startup is in ticks since system start, need to offset for absolute time
627  tms tmsb;
628  static long long offset =
629  100 * static_cast<long long>( time( nullptr ) ) - static_cast<long long>( times( &tmsb ) );
630  prc_start = ( prc.starttime + offset ) * TICK_TO_100NSEC;
631  }
632 
633  if ( myself ) { // myself
634  tms tmsb;
635  times( &tmsb );
636  info->UserTime = tmsb.tms_utime * TICK_TO_100NSEC;
637  info->KernelTime = tmsb.tms_stime * TICK_TO_100NSEC;
638  info->CreateTime = prc_start;
639  } else { // other process
640  linux_proc prc;
641  readProcStat( processID( pid ), prc );
642  tms tmsb;
643  static long long offset =
644  100 * static_cast<long long>( time( nullptr ) ) - static_cast<long long>( times( &tmsb ) );
645 
646  tms t;
647  times( &t );
648  info->UserTime = t.tms_utime * TICK_TO_100NSEC;
649  info->KernelTime = t.tms_stime * TICK_TO_100NSEC;
650  info->CreateTime = ( prc.starttime + offset ) * TICK_TO_100NSEC;
651  }
652  info->ExitTime = 0;
653 
654  status = 1;
655 
656 #elif defined( __APPLE__ )
657  if ( pid ) {}
658 // FIXME (MCl): Make an alternative function get timing on OSX
659 // times() seems to cause a segmentation fault
660 #else // no /proc file system: assume sys_start for the first call
661  tms tmsb;
662  static clock_t sys_start = times( 0 );
663  static long long offset = 100 * long long( time( 0 ) ) - sys_start;
664  clock_t now = times( &tmsb );
665  info->CreateTime = offset + now;
666  info->UserTime = tmsb.tms_utime;
667  info->KernelTime = tmsb.tms_stime;
668  info->CreateTime *= TICK_TO_100NSEC;
669  info->UserTime *= TICK_TO_100NSEC;
670  info->KernelTime *= TICK_TO_100NSEC;
671  info->ExitTime = 0;
672  status = 1;
673 #endif
674  }
675 
676  return status;
677 }
System::ProcessLdtInformation
@ ProcessLdtInformation
Definition: ProcessDescriptor.cpp:27
System::VM_COUNTERS::QuotaPeakPagedPoolUsage
unsigned long QuotaPeakPagedPoolUsage
Definition: ProcessDescriptor.h:74
linux_proc::blocked
unsigned long blocked
Definition: ProcessDescriptor.cpp:283
linux_proc::vsize
unsigned long vsize
Definition: ProcessDescriptor.cpp:274
System::ProcessInfoCommand
ProcessInfoCommand
Definition: ProcessDescriptor.cpp:16
System::VM_COUNTERS::PeakPagefileUsage
unsigned long PeakPagefileUsage
Definition: ProcessDescriptor.h:79
linux_proc::rss
long rss
Definition: ProcessDescriptor.cpp:275
System::VM_COUNTERS::QuotaPagedPoolUsage
unsigned long QuotaPagedPoolUsage
Definition: ProcessDescriptor.h:75
System::KERNEL_USER_TIMES
Process/Thread System and User Time NtQueryInformationProcess using ProcessTimes NtQueryInformationTh...
Definition: ProcessDescriptor.h:101
System::VM_COUNTERS::WorkingSetSize
unsigned long WorkingSetSize
Definition: ProcessDescriptor.h:73
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:23
System::InfoType
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:15
linux_proc::endcode
unsigned long endcode
Definition: ProcessDescriptor.cpp:278
System::ProcessDescriptor::ProcessHandle::m_needRelease
bool m_needRelease
Definition: ProcessDescriptor.h:120
System::VM_COUNTERS::PagefileUsage
unsigned long PagefileUsage
Definition: ProcessDescriptor.h:78
System::POOLED_USAGE_AND_LIMITS::PagefileLimit
unsigned long PagefileLimit
Definition: ProcessDescriptor.h:94
System::ProcessBasicInformation
@ ProcessBasicInformation
Definition: ProcessDescriptor.cpp:17
linux_proc::comm
char comm[400]
Definition: ProcessDescriptor.cpp:253
System::POOLED_USAGE_AND_LIMITS::PeakNonPagedPoolUsage
unsigned long PeakNonPagedPoolUsage
Definition: ProcessDescriptor.h:89
linux_proc::starttime
unsigned long long starttime
Definition: ProcessDescriptor.cpp:273
System::POOLED_USAGE_AND_LIMITS::PagedPoolUsage
unsigned long PagedPoolUsage
Definition: ProcessDescriptor.h:87
System::ProcessAffinityMask
@ ProcessAffinityMask
Definition: ProcessDescriptor.cpp:38
System::POOLED_USAGE_AND_LIMITS::NonPagedPoolLimit
unsigned long NonPagedPoolLimit
Definition: ProcessDescriptor.h:91
System::QUOTA_LIMITS::TimeLimit
long long TimeLimit
Definition: ProcessDescriptor.h:47
linux_proc::tty
int tty
Definition: ProcessDescriptor.cpp:258
System.h
gaudirun.fd
fd
Definition: gaudirun.py:630
linux_proc::startcode
unsigned long startcode
Definition: ProcessDescriptor.cpp:277
System::ProcessWx86Information
@ ProcessWx86Information
Definition: ProcessDescriptor.cpp:36
linux_proc::itrealvalue
long itrealvalue
Definition: ProcessDescriptor.cpp:272
System::KERNEL_USER_TIMES::UserTime
long long UserTime
Definition: ProcessDescriptor.h:105
System::PROCESS_BASIC_INFORMATION::AffinityMask
unsigned long AffinityMask
Definition: ProcessDescriptor.h:30
System::VM_COUNTERS::PeakWorkingSetSize
unsigned long PeakWorkingSetSize
Definition: ProcessDescriptor.h:72
System::VM_COUNTERS::VirtualSize
unsigned long VirtualSize
Definition: ProcessDescriptor.h:70
System::ProcessVmCounters
@ ProcessVmCounters
Definition: ProcessDescriptor.cpp:20
NewInputWrite.fetch
fetch
Definition: NewInputWrite.py:45
linux_proc::wchan
unsigned long wchan
Definition: ProcessDescriptor.cpp:286
System::PROCESS_BASIC_INFORMATION::BasePriority
long BasePriority
Definition: ProcessDescriptor.h:31
System::processHandle
GAUDI_API ProcessHandle processHandle()
Handle to running process.
Definition: ModuleInfo.cpp:116
System::ProcessDescriptor::query
long query(long pid, InfoType fetch, PROCESS_BASIC_INFORMATION *info)
Definition: ProcessDescriptor.cpp:578
System::PROCESS_BASIC_INFORMATION::InheritedFromUniqueProcessId
unsigned long InheritedFromUniqueProcessId
Definition: ProcessDescriptor.h:33
linux_proc::ppid
int ppid
Definition: ProcessDescriptor.cpp:255
System::QUOTA_LIMITS::PagedPoolLimit
unsigned long PagedPoolLimit
Definition: ProcessDescriptor.h:42
System::VM_COUNTERS::PageFaultCount
unsigned long PageFaultCount
Definition: ProcessDescriptor.h:71
readProcStat
void readProcStat(long pid, linux_proc &pinfo)
Definition: ProcessDescriptor.cpp:294
linux_proc::tpgid
int tpgid
Definition: ProcessDescriptor.cpp:259
linux_proc::priority
long priority
Definition: ProcessDescriptor.cpp:269
System::ProcessAccessToken
@ ProcessAccessToken
Definition: ProcessDescriptor.cpp:26
linux_proc::majflt
unsigned long majflt
Definition: ProcessDescriptor.cpp:263
linux_proc::flags
unsigned long flags
Definition: ProcessDescriptor.cpp:260
linux_proc::stime
unsigned long stime
Definition: ProcessDescriptor.cpp:266
System::PriorityBoost
@ PriorityBoost
Definition: SystemBase.h:15
System::MaxProcessInfoClass
@ MaxProcessInfoClass
Definition: ProcessDescriptor.cpp:40
System::ProcessDescriptor::ProcessHandle::ProcessHandle
ProcessHandle(long pid)
Definition: ProcessDescriptor.cpp:347
System::ProcessDescriptor::ProcessDescriptor
ProcessDescriptor()
Definition: ProcessDescriptor.cpp:374
System::IO_COUNTERS::WriteOperationCount
unsigned long WriteOperationCount
Definition: ProcessDescriptor.h:55
linux_proc::num_threads
long num_threads
Definition: ProcessDescriptor.cpp:271
ModuleInfo.h
System::ProcessEllapsedTime
@ ProcessEllapsedTime
Definition: ProcessDescriptor.cpp:41
System::PROCESS_BASIC_INFORMATION::UniqueProcessId
unsigned long UniqueProcessId
Definition: ProcessDescriptor.h:32
bug_34121.t
t
Definition: bug_34121.py:31
System::ProcessDescriptor::~ProcessDescriptor
virtual ~ProcessDescriptor()
Definition: ProcessDescriptor.cpp:388
System::POOLED_USAGE_AND_LIMITS::PagefileUsage
unsigned long PagefileUsage
Definition: ProcessDescriptor.h:93
System::ProcessEnableAlignmentFaultFixup
@ ProcessEnableAlignmentFaultFixup
Definition: ProcessDescriptor.cpp:34
System::ProcessTimes
@ ProcessTimes
Definition: ProcessDescriptor.cpp:21
System::VM_COUNTERS::QuotaNonPagedPoolUsage
unsigned long QuotaNonPagedPoolUsage
Definition: ProcessDescriptor.h:77
System::ProcessDescriptor::ProcessHandle
Definition: ProcessDescriptor.h:118
System::VM_COUNTERS::PeakVirtualSize
unsigned long PeakVirtualSize
Definition: ProcessDescriptor.h:69
linux_proc::rlim
unsigned long rlim
Definition: ProcessDescriptor.cpp:276
System::Memory
@ Memory
Definition: SystemBase.h:15
System::ProcessDescriptor::ProcessHandle::m_handle
void * m_handle
Definition: ProcessDescriptor.h:119
System::PROCESS_BASIC_INFORMATION
Definition: ProcessDescriptor.h:27
System::POOLED_USAGE_AND_LIMITS
Process Pooled Quota Usage and Limits NtQueryInformationProcess using ProcessPooledUsageAndLimits.
Definition: ProcessDescriptor.h:85
System::PROCESS_BASIC_INFORMATION::ExitStatus
long ExitStatus
Definition: ProcessDescriptor.h:28
System::ProcessRaisePriority
@ ProcessRaisePriority
Definition: ProcessDescriptor.cpp:23
AlgSequencer.h
h
Definition: AlgSequencer.py:31
linux_proc::startstack
unsigned long startstack
Definition: ProcessDescriptor.cpp:279
linux_proc
Definition: ProcessDescriptor.cpp:251
System::QUOTA_LIMITS
Process Quotas NtQueryInformationProcess using ProcessQuotaLimits NtQueryInformationProcess using Pro...
Definition: ProcessDescriptor.h:41
System::ProcessDefaultHardErrorMode
@ ProcessDefaultHardErrorMode
Definition: ProcessDescriptor.cpp:29
System::IO_COUNTERS::ReadTransferCount
long long ReadTransferCount
Definition: ProcessDescriptor.h:60
System::ProcessUserModeIOPL
@ ProcessUserModeIOPL
Definition: ProcessDescriptor.cpp:33
System::ProcessDebugPort
@ ProcessDebugPort
Definition: ProcessDescriptor.cpp:24
linux_proc::cminflt
unsigned long cminflt
Definition: ProcessDescriptor.cpp:262
System::ProcessLdtSize
@ ProcessLdtSize
Definition: ProcessDescriptor.cpp:28
System::ProcessPriorityClass
@ ProcessPriorityClass
Definition: ProcessDescriptor.cpp:35
linux_proc::signal
unsigned long signal
Definition: ProcessDescriptor.cpp:282
linux_proc::minflt
unsigned long minflt
Definition: ProcessDescriptor.cpp:261
linux_proc::pgrp
int pgrp
Definition: ProcessDescriptor.cpp:256
linux_proc::kstkesp
unsigned long kstkesp
Definition: ProcessDescriptor.cpp:280
linux_proc::sigcatch
unsigned long sigcatch
Definition: ProcessDescriptor.cpp:285
System::IO_COUNTERS
Process I/O Counters NtQueryInformationProcess using ProcessIoCounters.
Definition: ProcessDescriptor.h:53
plotSpeedupsPyRoot.time
time
Definition: plotSpeedupsPyRoot.py:180
linux_proc::pid
int pid
Definition: ProcessDescriptor.cpp:252
System::KERNEL_USER_TIMES::KernelTime
long long KernelTime
Definition: ProcessDescriptor.h:104
System::ProcessDescriptor::ProcessHandle::~ProcessHandle
virtual ~ProcessHandle()
Definition: ProcessDescriptor.cpp:364
hivetimeline.read
def read(f, regex=".*", skipevents=0)
Definition: hivetimeline.py:32
System::KERNEL_USER_TIMES::CreateTime
long long CreateTime
Definition: ProcessDescriptor.h:102
System::ProcessBasics
@ ProcessBasics
Definition: SystemBase.h:15
System::Times
@ Times
Definition: SystemBase.h:15
System::Quota
@ Quota
Definition: SystemBase.h:15
System::POOLED_USAGE_AND_LIMITS::NonPagedPoolUsage
unsigned long NonPagedPoolUsage
Definition: ProcessDescriptor.h:90
System::ProcessPooledUsageAndLimits
@ ProcessPooledUsageAndLimits
Definition: ProcessDescriptor.cpp:31
System::ProcessWorkingSetWatch
@ ProcessWorkingSetWatch
Definition: ProcessDescriptor.cpp:32
linux_proc::state
char state
Definition: ProcessDescriptor.cpp:254
usage
void usage(const std::string &argv0)
Definition: listcomponents.cpp:40
System::POOLED_USAGE_AND_LIMITS::PeakPagedPoolUsage
unsigned long PeakPagedPoolUsage
Definition: ProcessDescriptor.h:86
System::QUOTA_LIMITS::MaximumWorkingSetSize
unsigned long MaximumWorkingSetSize
Definition: ProcessDescriptor.h:45
linux_proc::sigignore
unsigned long sigignore
Definition: ProcessDescriptor.cpp:284
System
Note: OS specific details for environment resolution.
Definition: Debugger.h:15
System::ProcessQuotaLimits
@ ProcessQuotaLimits
Definition: ProcessDescriptor.cpp:18
System::IO_COUNTERS::OtherTransferCount
long long OtherTransferCount
Definition: ProcessDescriptor.h:62
System::ProcessIoPortHandlers
@ ProcessIoPortHandlers
Definition: ProcessDescriptor.cpp:30
System::VM_COUNTERS
Process Virtual Memory Counters NtQueryInformationProcess using ProcessVmCounters.
Definition: ProcessDescriptor.h:68
System::KERNEL_USER_TIMES::ExitTime
long long ExitTime
Definition: ProcessDescriptor.h:103
System::ProcessExceptionPort
@ ProcessExceptionPort
Definition: ProcessDescriptor.cpp:25
System::PROCESS_BASIC_INFORMATION::PebBaseAddress
PPEB PebBaseAddress
Definition: ProcessDescriptor.h:29
linux_proc::session
int session
Definition: ProcessDescriptor.cpp:257
System::POOLED_USAGE_AND_LIMITS::PagedPoolLimit
unsigned long PagedPoolLimit
Definition: ProcessDescriptor.h:88
System::ProcessHandle
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:27
System::IO_COUNTERS::OtherOperationCount
unsigned long OtherOperationCount
Definition: ProcessDescriptor.h:56
linux_proc::cmajflt
unsigned long cmajflt
Definition: ProcessDescriptor.cpp:264
ProcessDescriptor.h
System::QUOTA_LIMITS::MinimumWorkingSetSize
unsigned long MinimumWorkingSetSize
Definition: ProcessDescriptor.h:44
System::QUOTA_LIMITS::PagefileLimit
unsigned long PagefileLimit
Definition: ProcessDescriptor.h:46
linux_proc::kstkeip
unsigned long kstkeip
Definition: ProcessDescriptor.cpp:281
System::IO_COUNTERS::ReadOperationCount
unsigned long ReadOperationCount
Definition: ProcessDescriptor.h:54
System::ProcessIoCounters
@ ProcessIoCounters
Definition: ProcessDescriptor.cpp:19
System::ProcessPriorityBoost
@ ProcessPriorityBoost
Definition: ProcessDescriptor.cpp:39
System::PPEB
struct _PEB * PPEB
Basic Process Information NtQueryInformationProcess using ProcessBasicInfo.
Definition: ProcessDescriptor.h:26
linux_proc::utime
unsigned long utime
Definition: ProcessDescriptor.cpp:265
linux_proc::nice
long nice
Definition: ProcessDescriptor.cpp:270
System::IO_COUNTERS::WriteTransferCount
long long WriteTransferCount
Definition: ProcessDescriptor.h:61
linux_proc::cstime
long cstime
Definition: ProcessDescriptor.cpp:268
System::VM_COUNTERS::QuotaPeakNonPagedPoolUsage
unsigned long QuotaPeakNonPagedPoolUsage
Definition: ProcessDescriptor.h:76
GaudiKernel.Constants.FALSE
FALSE
Definition: Constants.py:38
System::ProcessBasePriority
@ ProcessBasePriority
Definition: ProcessDescriptor.cpp:22
System::ProcessHandleCount
@ ProcessHandleCount
Definition: ProcessDescriptor.cpp:37
System::QUOTA_LIMITS::NonPagedPoolLimit
unsigned long NonPagedPoolLimit
Definition: ProcessDescriptor.h:43
linux_proc::cutime
long cutime
Definition: ProcessDescriptor.cpp:267
System::POOLED_USAGE_AND_LIMITS::PeakPagefileUsage
unsigned long PeakPagefileUsage
Definition: ProcessDescriptor.h:92
System::IO
@ IO
Definition: SystemBase.h:15