keep better track of /proc/*/stat fields

This commit is contained in:
Doug MacEachern 2005-11-28 18:24:11 +00:00
parent 543412434a
commit 547a30b20b
1 changed files with 63 additions and 62 deletions

View File

@ -43,31 +43,31 @@
* 12 - majflt * 12 - majflt
* 13 - cmajflt * 13 - cmajflt
* 14 - utime * 14 - utime
* 14 - stime * 15 - stime
* 15 - cutime * 16 - cutime
* 16 - cstime * 17 - cstime
* 17 - priority * 18 - priority
* 18 - nice * 19 - nice
* 19 - 0 (removed field) * 20 - 0 (removed field)
* 20 - itrealvalue * 21 - itrealvalue
* 21 - starttime * 22 - starttime
* 22 - vsize * 23 - vsize
* 23 - rss * 24 - rss
* 24 - rlim * 25 - rlim
* 25 - startcode * 26 - startcode
* 26 - endcode * 27 - endcode
* 27 - startstack * 28 - startstack
* 28 - kstkesp * 29 - kstkesp
* 29 - kstkeip * 30 - kstkeip
* 30 - signal * 31 - signal
* 31 - blocked * 32 - blocked
* 32 - sigignore * 33 - sigignore
* 33 - sigcache * 34 - sigcache
* 34 - wchan * 35 - wchan
* 35 - nswap * 36 - nswap
* 36 - cnswap * 37 - cnswap
* 37 - exit_signal <-- looking for this. * 38 - exit_signal <-- looking for this.
* 38 - processor * 39 - processor
* ... more for newer RH * ... more for newer RH
*/ */
@ -587,62 +587,63 @@ static int proc_stat_read(sigar_t *sigar, sigar_pid_t pid)
len = sizeof(pstat->name)-1; len = sizeof(pstat->name)-1;
} }
/* (1,2) */
memcpy(pstat->name, ptr, len); memcpy(pstat->name, ptr, len);
pstat->name[len] = '\0'; pstat->name[len] = '\0';
ptr = tmp+1; ptr = tmp+1;
SIGAR_SKIP_SPACE(ptr); SIGAR_SKIP_SPACE(ptr);
pstat->state = *ptr++; pstat->state = *ptr++; /* (3) */
SIGAR_SKIP_SPACE(ptr); SIGAR_SKIP_SPACE(ptr);
pstat->ppid = sigar_strtoul(ptr); pstat->ppid = sigar_strtoul(ptr); /* (4) */
ptr = sigar_skip_token(ptr); /* pgrp */ ptr = sigar_skip_token(ptr); /* (5) pgrp */
ptr = sigar_skip_token(ptr); /* session */ ptr = sigar_skip_token(ptr); /* (6) session */
pstat->tty = sigar_strtoul(ptr); pstat->tty = sigar_strtoul(ptr); /* (7) */
ptr = sigar_skip_token(ptr); /* tty pgrp */ ptr = sigar_skip_token(ptr); /* (8) tty pgrp */
ptr = sigar_skip_token(ptr); /* flags */ ptr = sigar_skip_token(ptr); /* (9) flags */
pstat->minor_faults = sigar_strtoul(ptr); pstat->minor_faults = sigar_strtoul(ptr); /* (10) */
ptr = sigar_skip_token(ptr); /* cmin flt */ ptr = sigar_skip_token(ptr); /* (11) cmin flt */
pstat->major_faults = sigar_strtoul(ptr); pstat->major_faults = sigar_strtoul(ptr); /* (12) */
ptr = sigar_skip_token(ptr); /* cmaj flt */ ptr = sigar_skip_token(ptr); /* (13) cmaj flt */
pstat->utime = sigar_strtoul(ptr) / sigar->ticks; pstat->utime = sigar_strtoul(ptr) / sigar->ticks; /* (14) */
pstat->stime = sigar_strtoul(ptr) / sigar->ticks; pstat->stime = sigar_strtoul(ptr) / sigar->ticks; /* (15) */
ptr = sigar_skip_token(ptr); /* cutime */ ptr = sigar_skip_token(ptr); /* (16) cutime */
ptr = sigar_skip_token(ptr); /* cstime */ ptr = sigar_skip_token(ptr); /* (17) cstime */
pstat->priority = sigar_strtoul(ptr); pstat->priority = sigar_strtoul(ptr); /* (18) */
pstat->nice = sigar_strtoul(ptr); pstat->nice = sigar_strtoul(ptr); /* (19) */
ptr = sigar_skip_token(ptr); /* timeout */ ptr = sigar_skip_token(ptr); /* (20) timeout */
ptr = sigar_skip_token(ptr); /* it_real_value */ ptr = sigar_skip_token(ptr); /* (21) it_real_value */
pstat->start_time = sigar_strtoul(ptr); pstat->start_time = sigar_strtoul(ptr); /* (22) */
pstat->start_time /= sigar->ticks; pstat->start_time /= sigar->ticks;
pstat->start_time += sigar->boot_time; /* seconds */ pstat->start_time += sigar->boot_time; /* seconds */
pstat->start_time *= 1000; /* milliseconds */ pstat->start_time *= 1000; /* milliseconds */
pstat->vsize = sigar_strtoul(ptr); pstat->vsize = sigar_strtoul(ptr); /* (23) */
pstat->rss = pageshift(sigar_strtoul(ptr)); pstat->rss = pageshift(sigar_strtoul(ptr)); /* (24) */
ptr = sigar_skip_token(ptr); /* startcode */ ptr = sigar_skip_token(ptr); /* (25) rlim */
ptr = sigar_skip_token(ptr); /* endcode */ ptr = sigar_skip_token(ptr); /* (26) startcode */
ptr = sigar_skip_token(ptr); /* startstack */ ptr = sigar_skip_token(ptr); /* (27) endcode */
ptr = sigar_skip_token(ptr); /* kstkesp */ ptr = sigar_skip_token(ptr); /* (28) startstack */
ptr = sigar_skip_token(ptr); /* kstkeip */ ptr = sigar_skip_token(ptr); /* (29) kstkesp */
ptr = sigar_skip_token(ptr); /* signal */ ptr = sigar_skip_token(ptr); /* (30) kstkeip */
ptr = sigar_skip_token(ptr); /* blocked */ ptr = sigar_skip_token(ptr); /* (31) signal */
ptr = sigar_skip_token(ptr); /* sigignore */ ptr = sigar_skip_token(ptr); /* (32) blocked */
ptr = sigar_skip_token(ptr); /* sigcache */ ptr = sigar_skip_token(ptr); /* (33) sigignore */
ptr = sigar_skip_token(ptr); /* wchan */ ptr = sigar_skip_token(ptr); /* (34) sigcache */
ptr = sigar_skip_token(ptr); /* nswap */ ptr = sigar_skip_token(ptr); /* (35) wchan */
ptr = sigar_skip_token(ptr); /* cnswap */ ptr = sigar_skip_token(ptr); /* (36) nswap */
ptr = sigar_skip_token(ptr); /* exit_signal */ ptr = sigar_skip_token(ptr); /* (37) cnswap */
ptr = sigar_skip_token(ptr); /* (38) exit_signal */
ptr = sigar_skip_token(ptr); pstat->processor = sigar_strtoul(ptr); /* (39) */
pstat->processor = sigar_strtoul(ptr);
return SIGAR_OK; return SIGAR_OK;
} }