The Gaudi Framework  master (37c0b60a)
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(
336  buf,
337  // 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
338  // 30 1 2 3 4 5
339  "%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 "
340  "%lu %lu %lu %lu %lu %lu %lu",
341  &pinfo.pid, pinfo.comm, &pinfo.state, &pinfo.ppid, &pinfo.pgrp, &pinfo.session, &pinfo.tty, &pinfo.tpgid,
342  &pinfo.flags, &pinfo.minflt, &pinfo.cminflt, &pinfo.majflt, &pinfo.cmajflt, &pinfo.utime, &pinfo.stime,
343  &pinfo.cutime, &pinfo.cstime, &pinfo.priority, &pinfo.nice, &pinfo.num_threads, &pinfo.itrealvalue,
344  &pinfo.starttime, &pinfo.vsize, &pinfo.rss, &pinfo.rlim, &pinfo.startcode, &pinfo.endcode, &pinfo.startstack,
345  &pinfo.kstkesp, &pinfo.kstkeip, &pinfo.signal, &pinfo.blocked, &pinfo.sigignore, &pinfo.sigcatch,
346  &pinfo.wchan );
347  }
348  close( fd );
349 }
350 #endif
351 
352 // static long s_myPid = ::getpid();
353 // In order to properly support e.g. fork() calls, we cannot keep a copy of the pid!
354 
355 #ifndef __APPLE__
356 static inline long processID( long pid ) { return ( pid > 0 ) ? pid : ( ::getpid() ); }
357 #endif // not __APPLE__
358 
359 // Framework include files
360 #include "ProcessDescriptor.h"
361 #include <GaudiKernel/ModuleInfo.h>
362 #include <GaudiKernel/System.h>
363 
365  if ( pid > 0 ) {
366  if ( pid != ::getpid() ) {
367 #ifdef _WIN32
368  m_handle = ::OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid );
369 #else
370  // Note: the return type of getpid is pid_t, which is int on 64bit machines too
371  m_handle = reinterpret_cast<void*>( static_cast<long>( ::getpid() ) );
372 #endif
373  m_needRelease = true;
374  return;
375  }
376  }
378  m_needRelease = false;
379 }
380 
382  if ( m_needRelease ) {
383 #ifdef _WIN32
384  ::CloseHandle( m_handle );
385 #else
386  m_handle = nullptr;
387 #endif
388  }
389 }
390 
392 #ifdef _WIN32
393  static bool first = true;
394  if ( first ) {
395  first = false;
396  void* mh = ::LoadLibrary( "NTDll.dll" );
397  if ( mh ) {
398  NtApi::NtQueryInformationProcess =
399  ( NtApi::__NtQueryInformationProcess )::GetProcAddress( (HINSTANCE)mh, "NtQueryInformationProcess" );
400  }
401  }
402 #endif
403 }
404 
406 
408  if ( info == 0 ) return 0;
409  long status = 1;
410 
411  if ( fetch == IO ) {
412 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
413  ProcessHandle h( pid );
414  status = NtApi::NtQueryInformationProcess( h.handle(), ProcessIoCounters, info, sizeof( IO_COUNTERS ), 0 );
415  status = ( status == 0 ) ? 1 : 0;
416 #elif defined( _WIN32 ) // Windows 95,98...
417 #elif defined( __linux )
418  linux_proc prc;
419  readProcStat( processID( pid ), prc );
420  rusage usage;
421  getrusage( RUSAGE_SELF, &usage );
422  info->ReadOperationCount = usage.ru_inblock;
423  info->WriteOperationCount = usage.ru_oublock;
424  info->OtherOperationCount = 0;
425  info->ReadTransferCount = usage.ru_inblock;
426  info->WriteTransferCount = usage.ru_oublock;
427  info->OtherTransferCount = 0;
428 #else // All Other
429  if ( pid ) {}
430 #endif // End ALL OS
431  }
432  return status;
433 }
434 
436  if ( info == 0 ) return 0;
437  long status = 1;
438 
439  if ( fetch == Quota ) {
440 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
441  ProcessHandle h( pid );
442  status = NtApi::NtQueryInformationProcess( h.handle(), ProcessPooledUsageAndLimits, info,
443  sizeof( POOLED_USAGE_AND_LIMITS ), 0 );
444  status = ( status == 0 ) ? 1 : 0;
445 #elif defined( _WIN32 ) // Windows 95,98...
446 #elif defined( __linux ) // Linux
447  // rusage usage;
448  // getrusage(RUSAGE_SELF, &usage);
449  rlimit lim;
450 
451  getrlimit( RLIMIT_DATA, &lim );
452  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
453  info->PeakPagedPoolUsage = lim.rlim_cur;
454  info->PagedPoolUsage = lim.rlim_cur;
455  info->PagedPoolLimit = lim.rlim_max;
456 
457  getrlimit( RLIMIT_STACK, &lim );
458  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
459  info->PeakNonPagedPoolUsage = lim.rlim_cur;
460  info->NonPagedPoolUsage = lim.rlim_cur;
461  info->NonPagedPoolLimit = lim.rlim_max;
462 
463  linux_proc prc;
464  readProcStat( processID( pid ), prc );
465  info->PeakPagefileUsage = prc.rss * pg_size;
466  info->PagefileUsage = prc.rss * pg_size;
467  info->PagefileLimit = 0xFFFFFFFF;
468 #elif defined( __APPLE__ )
469  if ( pid ) {}
470 #else // All Other
471  if ( pid ) {}
472 #endif // End ALL OS
473  }
474 
475  return status;
476 }
477 
478 long System::ProcessDescriptor::query( long pid, InfoType fetch, long* info ) {
479 
480  if ( info == 0 ) return 0;
481  long status = 1;
482 
483  switch ( fetch ) {
484  case PriorityBoost:
485 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
486  ProcessHandle h( pid );
487  status = NtApi::NtQueryInformationProcess( h.handle(), ProcessPriorityBoost, info, sizeof( long ), 0 );
488 #elif defined( _WIN32 ) // Windows 95,98...
489  if ( pid ) {}
490 #else
491  // Not applicable
492  if ( pid > 0 ) status = 0; // to avoid compiler warning
493  status = 0;
494  *info = 0;
495 #endif // End ALL OS
496  status = ( status == 0 ) ? 1 : 0;
497  break;
498  default:
499  status = -1;
500  *info = -1;
501  break;
502  }
503  return status;
504 }
505 
507  if ( info == 0 ) return 0;
508  long status = 1;
509 
510  if ( fetch == Memory ) {
511 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
512  ProcessHandle h( pid );
513  status = NtApi::NtQueryInformationProcess( h.handle(), ProcessVmCounters, info, sizeof( VM_COUNTERS ), 0 );
514  status = ( status == 0 ) ? 1 : 0;
515 #elif defined( _WIN32 ) // Windows 95,98...
516 #elif defined( __linux ) // Linux
517  const ssize_t bufsize = 1024;
518  char buf[bufsize];
519  pid = processID( pid );
520  sprintf( buf, "/proc/%ld/statm", pid );
521  long size, resident, share, trs, lrs, drs, dt;
522  int fd = open( buf, O_RDONLY );
523  ssize_t nread = read( fd, buf, bufsize );
524  close( fd );
525  if ( nread < bufsize && nread >= 0 ) buf[nread] = '\0';
526  fd = sscanf( buf, "%ld %ld %ld %ld %ld %ld %ld", &size, &resident, &share, &trs, &drs, &lrs, &dt );
527  linux_proc prc;
528  readProcStat( pid, prc );
529  info->PeakVirtualSize = prc.vsize;
530  info->VirtualSize = prc.vsize;
531  info->PeakWorkingSetSize = resident * pg_size;
532  info->WorkingSetSize = resident * pg_size;
533  info->QuotaPeakPagedPoolUsage = share * pg_size;
534  info->QuotaPagedPoolUsage = share * pg_size;
535  info->QuotaNonPagedPoolUsage = ( trs + drs ) * pg_size; // drs = data/stack size
536  info->QuotaPeakNonPagedPoolUsage = ( trs + drs ) * pg_size; // trs = VmExe size
537  info->PageFaultCount = prc.majflt + prc.minflt;
538  info->PagefileUsage = prc.vsize - resident * pg_size;
539  info->PeakPagefileUsage = prc.vsize - resident * pg_size;
540 #elif defined( __APPLE__ )
541  if ( pid ) {}
542 #else // All Other
543  if ( pid ) {}
544 #endif // End ALL OS
545  }
546  return status;
547 }
548 
550  if ( info == 0 ) return 0;
551  long status = 1;
552 
553  if ( fetch == Quota ) {
554 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
555  ProcessHandle h( pid );
556  status = NtApi::NtQueryInformationProcess( h.handle(), ProcessQuotaLimits, info, sizeof( QUOTA_LIMITS ), 0 );
557  status = ( status == 0 ) ? 1 : 0;
558 #elif defined( _WIN32 ) // Windows 95,98...
559 #elif defined( __linux ) // Linux
560  // On linux all this stuff typically is not set
561  // (ie. rlim_max=RLIM_INFINITY...)
562 
563  if ( pid > 0 && pid != ::getpid() ) return 0; // only possible for myself
564 
565  rlimit lim;
566  getrlimit( RLIMIT_DATA, &lim );
567  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
568  info->PagedPoolLimit = lim.rlim_max;
569 
570  getrlimit( RLIMIT_STACK, &lim );
571  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
572  info->NonPagedPoolLimit = lim.rlim_max;
573  info->MinimumWorkingSetSize = 0;
574 
575  getrlimit( RLIMIT_RSS, &lim );
576  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
577  info->MaximumWorkingSetSize = lim.rlim_max;
578 
579  getrlimit( RLIMIT_AS, &lim );
580  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
581  info->PagefileLimit = lim.rlim_max;
582 
583  getrlimit( RLIMIT_CPU, &lim );
584  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
585  info->TimeLimit = lim.rlim_max;
586 #elif defined( __APPLE__ )
587  if ( pid ) {}
588 #else // All Other
589  if ( pid ) {}
590 #endif // End ALL OS
591  }
592  return status;
593 }
594 
596  if ( info == 0 ) return 0;
597  long status = 1;
598 
599  if ( fetch == ProcessBasics ) {
600 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
601  ProcessHandle h( pid );
602  status = NtApi::NtQueryInformationProcess( h.handle(), ProcessBasicInformation, info,
603  sizeof( PROCESS_BASIC_INFORMATION ), 0 );
604  status = ( status == 0 ) ? 1 : 0;
605 #elif defined( _WIN32 ) // Windows 95,98...
606 #elif defined( __linux ) // Linux
607  linux_proc prc;
608  pid = processID( pid );
609  readProcStat( pid, prc );
610  info->ExitStatus = 0;
611  info->PebBaseAddress = (PPEB)prc.startcode;
612  info->BasePriority = 2 * 15 - prc.priority;
613  // std::cout << "Base Priority=" << info->BasePriority << "|"
614  // << prc.priority << std::endl;
615  info->AffinityMask = prc.flags;
616  // std::cout << "Flags =" << info->AffinityMask << "|"
617  // << prc.flags << std::endl;
618  info->UniqueProcessId = pid;
620 #else // All Other
621  if ( pid ) {}
622 #endif // End ALL OS
623  }
624  return status;
625 }
626 
628  if ( info == 0 ) return 0;
629  long status = 1;
630 
631  if ( fetch == Times ) {
632 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
633  ProcessHandle h( pid );
634  status = NtApi::NtQueryInformationProcess( h.handle(), ProcessTimes, info, sizeof( KERNEL_USER_TIMES ), 0 );
635  status = ( status == 0 ) ? 1 : 0;
636 #elif defined( _WIN32 ) // Windows 95,98...
637 #elif defined( __linux ) // Linux
638  static long long prc_start = 0;
639  bool myself = pid <= 0 || pid == ::getpid(); // avoid unnecessary calls to getpid if pid<0
640  if ( myself && prc_start == 0 ) { // called only once to set prc_start
641  linux_proc prc;
642  readProcStat( processID( pid ), prc );
643  // prc.startup is in ticks since system start, need to offset for absolute time
644  tms tmsb;
645  static long long offset =
646  100 * static_cast<long long>( time( nullptr ) ) - static_cast<long long>( times( &tmsb ) );
647  prc_start = ( prc.starttime + offset ) * TICK_TO_100NSEC;
648  }
649 
650  if ( myself ) { // myself
651  tms tmsb;
652  times( &tmsb );
653  info->UserTime = tmsb.tms_utime * TICK_TO_100NSEC;
654  info->KernelTime = tmsb.tms_stime * TICK_TO_100NSEC;
655  info->CreateTime = prc_start;
656  } else { // other process
657  linux_proc prc;
658  readProcStat( processID( pid ), prc );
659  tms tmsb;
660  static long long offset =
661  100 * static_cast<long long>( time( nullptr ) ) - static_cast<long long>( times( &tmsb ) );
662 
663  tms t;
664  times( &t );
665  info->UserTime = t.tms_utime * TICK_TO_100NSEC;
666  info->KernelTime = t.tms_stime * TICK_TO_100NSEC;
667  info->CreateTime = ( prc.starttime + offset ) * TICK_TO_100NSEC;
668  }
669  info->ExitTime = 0;
670 
671  status = 1;
672 
673 #elif defined( __APPLE__ )
674  if ( pid ) {}
675 // FIXME (MCl): Make an alternative function get timing on OSX
676 // times() seems to cause a segmentation fault
677 #else // no /proc file system: assume sys_start for the first call
678  tms tmsb;
679  static clock_t sys_start = times( 0 );
680  static long long offset = 100 * long long( time( 0 ) ) - sys_start;
681  clock_t now = times( &tmsb );
682  info->CreateTime = offset + now;
683  info->UserTime = tmsb.tms_utime;
684  info->KernelTime = tmsb.tms_stime;
685  info->CreateTime *= TICK_TO_100NSEC;
686  info->UserTime *= TICK_TO_100NSEC;
687  info->KernelTime *= TICK_TO_100NSEC;
688  info->ExitTime = 0;
689  status = 1;
690 #endif
691  }
692 
693  return status;
694 }
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:595
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:364
System::ProcessDescriptor::ProcessDescriptor
ProcessDescriptor()
Definition: ProcessDescriptor.cpp:391
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:405
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:381
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
usage
void usage(const std::string &argv0)
Definition: listcomponents.cpp:40
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
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