| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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