getstat
source
sysinfo.c
line
346 - 416
概要
void getstat(
jiff *restrict cuse,
jiff *restrict cice,
jiff *restrict csys,
jiff *restrict cide,
jiff *restrict ciow,
jiff *restrict cxxx,
jiff *restrict cyyy,
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
)
処理の流れ
351 static int fd;
352 unsigned long long llbuf = 0;
353 int need_vmstat_file = 0;
354 int need_proc_scan = 0;
355 const char* b;
356 buff[BUFFSIZE-1] = 0; /* ensure null termination in buffer */
358 if(fd){
359 lseek(fd, 0L, SEEK_SET);
360 }else{
361 fd = open("/proc/stat", O_RDONLY, 0);
362 if(fd == -1) crash("/proc/stat");
363 }
364 read(fd,buff,BUFFSIZE-1);
365 *intr = 0;
366 *ciow = 0; /* not separated out until the 2.5.41 kernel */
367 *cxxx = 0; /* not separated out until the 2.6.0-test4 kernel */
368 *cyyy = 0; /* not separated out until the 2.6.0-test4 kernel */
369
370 b = strstr(buff, "cpu ");
371 if(b) sscanf(b, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", cuse, cice, csys, cide, ciow, cxxx, c
371 yyy);
372
373 b = strstr(buff, "page ");
374 if(b) sscanf(b, "page %lu %lu", pin, pout);
375 else need_vmstat_file = 1;
376
377 b = strstr(buff, "swap ");
378 if(b) sscanf(b, "swap %lu %lu", s_in, sout);
379 else need_vmstat_file = 1;
380
381 b = strstr(buff, "intr ");
382 if(b) sscanf(b, "intr %Lu", &llbuf);
383 *intr = llbuf;
384
385 b = strstr(buff, "ctxt ");
386 if(b) sscanf(b, "ctxt %Lu", &llbuf);
387 *ctxt = llbuf;
388
389 b = strstr(buff, "btime ");
390 if(b) sscanf(b, "btime %u", btime);
391
392 b = strstr(buff, "processes ");
393 if(b) sscanf(b, "processes %u", processes);
394
395 b = strstr(buff, "procs_running ");
396 if(b) sscanf(b, "procs_running %u", running);
397 else need_proc_scan = 1;
398
399 b = strstr(buff, "procs_blocked ");
400 if(b) sscanf(b, "procs_blocked %u", blocked);
401 else need_proc_scan = 1;
402
403 if(need_proc_scan){ /* Linux 2.5.46 (approximately) and below */
404 getrunners(running, blocked);
405 }
406
407 (*running)--; // exclude vmstat itself
408
409 if(need_vmstat_file){ /* Linux 2.5.40-bk4 and above */
410 vminfo();
411 *pin = vm_pgpgin;
412 *pout = vm_pgpgout;
413 *s_in = vm_pswpin;
414 *sout = vm_pswpout;
415 }
416 }
function
346 void getstat(jiff *restrict cuse, jiff *restrict cice, jiff *restrict csys, jiff *restrict c
346 ide, jiff *restrict ciow, jiff *restrict cxxx, jiff *restrict cyyy,
347 unsigned long *restrict pin, unsigned long *restrict pout, unsigned long *restr
347 ict s_in, unsigned long *restrict sout,
348 unsigned *restrict intr, unsigned *restrict ctxt,
349 unsigned int *restrict running, unsigned int *restrict blocked,
350 unsigned int *restrict btime, unsigned int *restrict processes) {
351 static int fd;
352 unsigned long long llbuf = 0;
353 int need_vmstat_file = 0;
354 int need_proc_scan = 0;
355 const char* b;
356 buff[BUFFSIZE-1] = 0; /* ensure null termination in buffer */
357
358 if(fd){
359 lseek(fd, 0L, SEEK_SET);
360 }else{
361 fd = open("/proc/stat", O_RDONLY, 0);
362 if(fd == -1) crash("/proc/stat");
363 }
364 read(fd,buff,BUFFSIZE-1);
365 *intr = 0;
366 *ciow = 0; /* not separated out until the 2.5.41 kernel */
367 *cxxx = 0; /* not separated out until the 2.6.0-test4 kernel */
368 *cyyy = 0; /* not separated out until the 2.6.0-test4 kernel */
369
370 b = strstr(buff, "cpu ");
371 if(b) sscanf(b, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", cuse, cice, csys, cide, ciow, cxxx, c
371 yyy);
372
373 b = strstr(buff, "page ");
374 if(b) sscanf(b, "page %lu %lu", pin, pout);
375 else need_vmstat_file = 1;
376
377 b = strstr(buff, "swap ");
378 if(b) sscanf(b, "swap %lu %lu", s_in, sout);
379 else need_vmstat_file = 1;
380
381 b = strstr(buff, "intr ");
382 if(b) sscanf(b, "intr %Lu", &llbuf);
383 *intr = llbuf;
384
385 b = strstr(buff, "ctxt ");
386 if(b) sscanf(b, "ctxt %Lu", &llbuf);
387 *ctxt = llbuf;
388
389 b = strstr(buff, "btime ");
390 if(b) sscanf(b, "btime %u", btime);
391
392 b = strstr(buff, "processes ");
393 if(b) sscanf(b, "processes %u", processes);
394
395 b = strstr(buff, "procs_running ");
396 if(b) sscanf(b, "procs_running %u", running);
397 else need_proc_scan = 1;
398
399 b = strstr(buff, "procs_blocked ");
400 if(b) sscanf(b, "procs_blocked %u", blocked);
401 else need_proc_scan = 1;
402
403 if(need_proc_scan){ /* Linux 2.5.46 (approximately) and below */
404 getrunners(running, blocked);
405 }
406
407 (*running)--; // exclude vmstat itself
408
409 if(need_vmstat_file){ /* Linux 2.5.40-bk4 and above */
410 vminfo();
411 *pin = vm_pgpgin;
412 *pout = vm_pgpgout;
413 *s_in = vm_pswpin;
414 *sout = vm_pswpout;
415 }
416 }
最終更新:2009年02月22日 16:58