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