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