7. /proc/stat の定義
cpu 10132153 290696 3084719 46828483 16683 0 25195 0 175628 0
cpu0 1393280 32966 572056 13343292 6130 0 17875 0 23933 0
The amount of time, measured in units of USER_HZ
(1/100ths of a second on most architectures, use
sysconf(_SC_CLK_TCK) to obtain the right value), that
the system ("cpu" line) or the specific CPU ("cpuN"
line) spent in various states:
user (1) Time spent in user mode.
nice (2) Time spent in user mode with low priority
(nice).
(中略)
procs_running 6
Number of processes in runnable state. (Linux 2.5.45
onward.)
procs_blocked 2
Number of processes blocked waiting for I/O to com‐
plete. (Linux 2.5.45 onward.)
CPU時間の累積値
run queue に入っているプロセス
の数(TASK_INTERRUPTIBLE)
I/O待ちのプロセスの数
(TASK_UNINTERRUPTIBLE)
http://man7.org/linux/man-pages/man5/proc.5.html
11. vmstat のソースを読むと
void getstat(jiff *restrict cuse, jiff *restrict cice, jiff *restrict csys, jiff *restrict cide, jiff *restrict ciow, jiff
*restrict cxxx, jiff *restrict cyyy, jiff *restrict czzz,
unsigned long *restrict pin, unsigned long *restrict pout, unsigned long *restrict s_in, unsigned long
*restrict sout,
unsigned *restrict intr, unsigned *restrict ctxt,
unsigned int *restrict running, unsigned int *restrict blocked,
unsigned int *restrict btime, unsigned int *restrict processes) {
static int fd;
unsigned long long llbuf = 0;
int need_vmstat_file = 0;
int need_proc_scan = 0;
const char* b;
buff[BUFFSIZE-1] = 0; /* ensure null termination in buffer */
if(fd){
lseek(fd, 0L, SEEK_SET);
}else{
fd = open("/proc/stat", O_RDONLY, 0);
if(fd == -1) crash("/proc/stat");
}
read(fd,buff,BUFFSIZE-1);
http://procps.sourceforge.net/procps-3.2.8.tar.gz
• proc/sysinfo.c
/proc/stat を読んでいる
12. dstat は Python で書かれている
$ dstat -V
Dstat 0.7.0
(以降略)
$ file /usr/bin/dstat
/usr/bin/dstat: Python script, ASCII text executable
$ head -5 /usr/bin/dstat
#!/usr/bin/python2.7
### This program is free software; you can redistribute it and/or modify
### it under the terms of the GNU Library General Public License as published by
### the Free Software Foundation; version 2 only
https://github.com/dagwieers/dstat
• dstat