library: cleanup unused old functions
The old getstat and meminfo functions and their globals are removed. Also page_size is now a function, procps_pagesize_get()
This commit is contained in:
parent
c3e85cef73
commit
161e06465b
@ -16,28 +16,9 @@ global:
|
||||
getdiskstat;
|
||||
getpartitions_num;
|
||||
getslabinfo;
|
||||
getstat;
|
||||
kb_active;
|
||||
kb_high_free;
|
||||
kb_high_total;
|
||||
kb_inactive;
|
||||
kb_low_free;
|
||||
kb_low_total;
|
||||
kb_main_available;
|
||||
kb_main_buffers;
|
||||
kb_main_cached;
|
||||
kb_main_free;
|
||||
kb_main_shared;
|
||||
kb_main_total;
|
||||
kb_main_used;
|
||||
kb_swap_free;
|
||||
kb_swap_total;
|
||||
kb_swap_used;
|
||||
look_up_our_self;
|
||||
lookup_wchan;
|
||||
meminfo;
|
||||
openproc;
|
||||
page_bytes;
|
||||
put_slabinfo;
|
||||
readeither;
|
||||
readproc;
|
||||
@ -57,6 +38,7 @@ global:
|
||||
procps_meminfo_unref;
|
||||
procps_meminfo_get;
|
||||
procps_meminfo_get_chain;
|
||||
procps_pagesize_get;
|
||||
procps_stat_new;
|
||||
procps_stat_read;
|
||||
procps_stat_read_jiffs;
|
||||
|
580
proc/sysinfo.c
580
proc/sysinfo.c
@ -35,8 +35,6 @@
|
||||
#include "procps-private.h"
|
||||
|
||||
|
||||
long page_bytes; /* this architecture's page size */
|
||||
|
||||
#define BAD_OPEN_MESSAGE \
|
||||
"Error: /proc must be mounted\n" \
|
||||
" To mount /proc at boot you need an /etc/fstab line like:\n" \
|
||||
@ -86,41 +84,6 @@ static char buf[8192];
|
||||
/* return minimum of two values */
|
||||
#define MIN(x,y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
unsigned long getbtime(void) {
|
||||
static unsigned long btime = 0;
|
||||
bool found_btime = false;
|
||||
FILE *f;
|
||||
|
||||
if (btime)
|
||||
return btime;
|
||||
|
||||
/* /proc/stat can get very large on multi-CPU systems so we
|
||||
can't use FILE_TO_BUF */
|
||||
if (!(f = fopen(STAT_FILE, "r"))) {
|
||||
fputs(BAD_OPEN_MESSAGE, stderr);
|
||||
fflush(NULL);
|
||||
_exit(102);
|
||||
}
|
||||
|
||||
while ((fgets(buf, sizeof buf, f))) {
|
||||
if (sscanf(buf, "btime %lu", &btime) == 1) {
|
||||
found_btime = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
if (!found_btime) {
|
||||
fputs("missing btime in " STAT_FILE "\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return btime;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* procps_hertz_get:
|
||||
*
|
||||
@ -141,7 +104,7 @@ PROCPS_EXPORT long procps_hertz_get(void)
|
||||
|
||||
#ifdef _SC_CLK_TCK
|
||||
if ((hz = sysconf(_SC_CLK_TCK)) > 0)
|
||||
return hz;
|
||||
return hz;
|
||||
#endif
|
||||
#ifdef HZ
|
||||
return(HZ);
|
||||
@ -150,16 +113,20 @@ PROCPS_EXPORT long procps_hertz_get(void)
|
||||
return 100;
|
||||
}
|
||||
|
||||
// same as: euid != uid || egid != gid
|
||||
#ifndef AT_SECURE
|
||||
#define AT_SECURE 23 // secure mode boolean (true if setuid, etc.)
|
||||
#endif
|
||||
/*
|
||||
* procps_pagesize_get:
|
||||
*
|
||||
* Return the size of pages in bytes
|
||||
*
|
||||
* Returns: size of pages in bytes
|
||||
*/
|
||||
PROCPS_EXPORT long procps_pagesize_get(void)
|
||||
{
|
||||
long psiz;
|
||||
|
||||
|
||||
static void init_libproc(void) __attribute__((constructor));
|
||||
static void init_libproc(void){
|
||||
|
||||
page_bytes = sysconf(_SC_PAGESIZE);
|
||||
if ((psiz = sysconf(_SC_PAGESIZE)) > 0)
|
||||
return psiz;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -203,525 +170,6 @@ static void crash(const char *filename) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
static void getrunners(unsigned int *restrict running, unsigned int *restrict blocked) {
|
||||
struct dirent *ent;
|
||||
DIR *proc;
|
||||
|
||||
*running=0;
|
||||
*blocked=0;
|
||||
|
||||
if((proc=opendir("/proc"))==NULL) crash("/proc");
|
||||
|
||||
while(( ent=readdir(proc) )) {
|
||||
char tbuf[32];
|
||||
char *cp;
|
||||
int fd;
|
||||
char c;
|
||||
|
||||
if (!isdigit(ent->d_name[0])) continue;
|
||||
sprintf(tbuf, "/proc/%s/stat", ent->d_name);
|
||||
|
||||
fd = open(tbuf, O_RDONLY, 0);
|
||||
if (fd == -1) continue;
|
||||
memset(tbuf, '\0', sizeof tbuf); // didn't feel like checking read()
|
||||
read(fd, tbuf, sizeof tbuf - 1); // need 32 byte buffer at most
|
||||
close(fd);
|
||||
|
||||
cp = strrchr(tbuf, ')');
|
||||
if(!cp) continue;
|
||||
c = cp[2];
|
||||
|
||||
if (c=='R') {
|
||||
(*running)++;
|
||||
continue;
|
||||
}
|
||||
if (c=='D') {
|
||||
(*blocked)++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
closedir(proc);
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
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);
|
||||
*intr = 0;
|
||||
*ciow = 0; /* not separated out until the 2.5.41 kernel */
|
||||
*cxxx = 0; /* not separated out until the 2.6.0-test4 kernel */
|
||||
*cyyy = 0; /* not separated out until the 2.6.0-test4 kernel */
|
||||
*czzz = 0; /* not separated out until the 2.6.11 kernel */
|
||||
|
||||
b = strstr(buff, "cpu ");
|
||||
if(b) sscanf(b, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", cuse, cice, csys, cide, ciow, cxxx, cyyy, czzz);
|
||||
|
||||
b = strstr(buff, "page ");
|
||||
if(b) sscanf(b, "page %lu %lu", pin, pout);
|
||||
else need_vmstat_file = 1;
|
||||
|
||||
b = strstr(buff, "swap ");
|
||||
if(b) sscanf(b, "swap %lu %lu", s_in, sout);
|
||||
else need_vmstat_file = 1;
|
||||
|
||||
b = strstr(buff, "intr ");
|
||||
if(b) sscanf(b, "intr %Lu", &llbuf);
|
||||
*intr = llbuf;
|
||||
|
||||
b = strstr(buff, "ctxt ");
|
||||
if(b) sscanf(b, "ctxt %Lu", &llbuf);
|
||||
*ctxt = llbuf;
|
||||
|
||||
b = strstr(buff, "btime ");
|
||||
if(b) sscanf(b, "btime %u", btime);
|
||||
|
||||
b = strstr(buff, "processes ");
|
||||
if(b) sscanf(b, "processes %u", processes);
|
||||
|
||||
b = strstr(buff, "procs_running ");
|
||||
if(b) sscanf(b, "procs_running %u", running);
|
||||
else need_proc_scan = 1;
|
||||
|
||||
b = strstr(buff, "procs_blocked ");
|
||||
if(b) sscanf(b, "procs_blocked %u", blocked);
|
||||
else need_proc_scan = 1;
|
||||
|
||||
if(need_proc_scan){ /* Linux 2.5.46 (approximately) and below */
|
||||
getrunners(running, blocked);
|
||||
}
|
||||
|
||||
if(*running)
|
||||
(*running)--; // exclude vmstat itself
|
||||
|
||||
if(need_vmstat_file){ /* Linux 2.5.40-bk4 and above */
|
||||
vminfo();
|
||||
*pin = vm_pgpgin;
|
||||
*pout = vm_pgpgout;
|
||||
*s_in = vm_pswpin;
|
||||
*sout = vm_pswpout;
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
/*
|
||||
* Copyright 1999 by Albert Cahalan; all rights reserved.
|
||||
* This file may be used subject to the terms and conditions of the
|
||||
* GNU Library General Public License Version 2, or any later version
|
||||
* at your option, as published by the Free Software Foundation.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library General Public License for more details.
|
||||
*/
|
||||
|
||||
typedef struct mem_table_struct {
|
||||
const char *name; /* memory type name */
|
||||
unsigned long *slot; /* slot in return struct */
|
||||
} mem_table_struct;
|
||||
|
||||
static int compare_mem_table_structs(const void *a, const void *b){
|
||||
return strcmp(((const mem_table_struct*)a)->name,((const mem_table_struct*)b)->name);
|
||||
}
|
||||
|
||||
/* example data, following junk, with comments added:
|
||||
*
|
||||
* MemTotal: 61768 kB old
|
||||
* MemFree: 1436 kB old
|
||||
* Buffers: 1312 kB old
|
||||
* Cached: 20932 kB old
|
||||
* Active: 12464 kB new
|
||||
* Inact_dirty: 7772 kB new
|
||||
* Inact_clean: 2008 kB new
|
||||
* Inact_target: 0 kB new
|
||||
* Inact_laundry: 0 kB new, and might be missing too
|
||||
* HighTotal: 0 kB
|
||||
* HighFree: 0 kB
|
||||
* LowTotal: 61768 kB
|
||||
* LowFree: 1436 kB
|
||||
* SwapTotal: 122580 kB old
|
||||
* SwapFree: 60352 kB old
|
||||
* Inactive: 20420 kB 2.5.41+
|
||||
* Dirty: 0 kB 2.5.41+
|
||||
* Writeback: 0 kB 2.5.41+
|
||||
* Mapped: 9792 kB 2.5.41+
|
||||
* Shmem: 28 kB 2.6.32+
|
||||
* Slab: 4564 kB 2.5.41+
|
||||
* Committed_AS: 8440 kB 2.5.41+
|
||||
* PageTables: 304 kB 2.5.41+
|
||||
* ReverseMaps: 5738 2.5.41+
|
||||
* SwapCached: 0 kB 2.5.??+
|
||||
* HugePages_Total: 220 2.5.??+
|
||||
* HugePages_Free: 138 2.5.??+
|
||||
* Hugepagesize: 4096 kB 2.5.??+
|
||||
*/
|
||||
|
||||
/* Shmem in 2.6.32+ */
|
||||
unsigned long kb_main_shared;
|
||||
/* old but still kicking -- the important stuff */
|
||||
static unsigned long kb_page_cache;
|
||||
unsigned long kb_main_buffers;
|
||||
unsigned long kb_main_free;
|
||||
unsigned long kb_main_total;
|
||||
unsigned long kb_swap_free;
|
||||
unsigned long kb_swap_total;
|
||||
/* recently introduced */
|
||||
unsigned long kb_high_free;
|
||||
unsigned long kb_high_total;
|
||||
unsigned long kb_low_free;
|
||||
unsigned long kb_low_total;
|
||||
unsigned long kb_main_available;
|
||||
/* 2.4.xx era */
|
||||
unsigned long kb_active;
|
||||
unsigned long kb_inact_laundry;
|
||||
unsigned long kb_inact_dirty;
|
||||
unsigned long kb_inact_clean;
|
||||
unsigned long kb_inact_target;
|
||||
unsigned long kb_swap_cached; /* late 2.4 and 2.6+ only */
|
||||
/* derived values */
|
||||
unsigned long kb_main_cached;
|
||||
unsigned long kb_swap_used;
|
||||
unsigned long kb_main_used;
|
||||
/* 2.5.41+ */
|
||||
unsigned long kb_writeback;
|
||||
unsigned long kb_slab;
|
||||
unsigned long nr_reversemaps;
|
||||
unsigned long kb_committed_as;
|
||||
unsigned long kb_dirty;
|
||||
unsigned long kb_inactive;
|
||||
unsigned long kb_mapped;
|
||||
unsigned long kb_pagetables;
|
||||
// seen on a 2.6.x kernel:
|
||||
static unsigned long kb_vmalloc_chunk;
|
||||
static unsigned long kb_vmalloc_total;
|
||||
static unsigned long kb_vmalloc_used;
|
||||
// seen on 2.6.24-rc6-git12
|
||||
static unsigned long kb_anon_pages;
|
||||
static unsigned long kb_bounce;
|
||||
static unsigned long kb_commit_limit;
|
||||
static unsigned long kb_nfs_unstable;
|
||||
// seen on 2.6.18
|
||||
static unsigned long kb_min_free;
|
||||
// 2.6.19+
|
||||
static unsigned long kb_slab_reclaimable;
|
||||
static unsigned long kb_slab_unreclaimable;
|
||||
// 2.6.27+
|
||||
static unsigned long kb_active_file;
|
||||
static unsigned long kb_inactive_file;
|
||||
|
||||
|
||||
void meminfo(void){
|
||||
char namebuf[32]; /* big enough to hold any row name */
|
||||
int linux_version_code = procps_linux_version();
|
||||
mem_table_struct findme = { namebuf, NULL};
|
||||
mem_table_struct *found;
|
||||
char *head;
|
||||
char *tail;
|
||||
static const mem_table_struct mem_table[] = {
|
||||
{"Active", &kb_active}, // important
|
||||
{"Active(file)", &kb_active_file},
|
||||
{"AnonPages", &kb_anon_pages},
|
||||
{"Bounce", &kb_bounce},
|
||||
{"Buffers", &kb_main_buffers}, // important
|
||||
{"Cached", &kb_page_cache}, // important
|
||||
{"CommitLimit", &kb_commit_limit},
|
||||
{"Committed_AS", &kb_committed_as},
|
||||
{"Dirty", &kb_dirty}, // kB version of vmstat nr_dirty
|
||||
{"HighFree", &kb_high_free},
|
||||
{"HighTotal", &kb_high_total},
|
||||
{"Inact_clean", &kb_inact_clean},
|
||||
{"Inact_dirty", &kb_inact_dirty},
|
||||
{"Inact_laundry",&kb_inact_laundry},
|
||||
{"Inact_target", &kb_inact_target},
|
||||
{"Inactive", &kb_inactive}, // important
|
||||
{"Inactive(file)",&kb_inactive_file},
|
||||
{"LowFree", &kb_low_free},
|
||||
{"LowTotal", &kb_low_total},
|
||||
{"Mapped", &kb_mapped}, // kB version of vmstat nr_mapped
|
||||
{"MemAvailable", &kb_main_available}, // important
|
||||
{"MemFree", &kb_main_free}, // important
|
||||
{"MemTotal", &kb_main_total}, // important
|
||||
{"NFS_Unstable", &kb_nfs_unstable},
|
||||
{"PageTables", &kb_pagetables}, // kB version of vmstat nr_page_table_pages
|
||||
{"ReverseMaps", &nr_reversemaps}, // same as vmstat nr_page_table_pages
|
||||
{"SReclaimable", &kb_slab_reclaimable}, // "slab reclaimable" (dentry and inode structures)
|
||||
{"SUnreclaim", &kb_slab_unreclaimable},
|
||||
{"Shmem", &kb_main_shared}, // kernel 2.6.32 and later
|
||||
{"Slab", &kb_slab}, // kB version of vmstat nr_slab
|
||||
{"SwapCached", &kb_swap_cached},
|
||||
{"SwapFree", &kb_swap_free}, // important
|
||||
{"SwapTotal", &kb_swap_total}, // important
|
||||
{"VmallocChunk", &kb_vmalloc_chunk},
|
||||
{"VmallocTotal", &kb_vmalloc_total},
|
||||
{"VmallocUsed", &kb_vmalloc_used},
|
||||
{"Writeback", &kb_writeback}, // kB version of vmstat nr_writeback
|
||||
};
|
||||
const int mem_table_count = sizeof(mem_table)/sizeof(mem_table_struct);
|
||||
unsigned long watermark_low;
|
||||
signed long mem_available, mem_used;
|
||||
|
||||
FILE_TO_BUF(MEMINFO_FILE,meminfo_fd);
|
||||
|
||||
kb_inactive = ~0UL;
|
||||
kb_low_total = kb_main_available = 0;
|
||||
|
||||
head = buf;
|
||||
for(;;){
|
||||
tail = strchr(head, ':');
|
||||
if(!tail) break;
|
||||
*tail = '\0';
|
||||
if(strlen(head) >= sizeof(namebuf)){
|
||||
head = tail+1;
|
||||
goto nextline;
|
||||
}
|
||||
strcpy(namebuf,head);
|
||||
found = bsearch(&findme, mem_table, mem_table_count,
|
||||
sizeof(mem_table_struct), compare_mem_table_structs
|
||||
);
|
||||
head = tail+1;
|
||||
if(!found) goto nextline;
|
||||
*(found->slot) = (unsigned long)strtoull(head,&tail,10);
|
||||
nextline:
|
||||
tail = strchr(head, '\n');
|
||||
if(!tail) break;
|
||||
head = tail+1;
|
||||
}
|
||||
if(!kb_low_total){ /* low==main except with large-memory support */
|
||||
kb_low_total = kb_main_total;
|
||||
kb_low_free = kb_main_free;
|
||||
}
|
||||
if(kb_inactive==~0UL){
|
||||
kb_inactive = kb_inact_dirty + kb_inact_clean + kb_inact_laundry;
|
||||
}
|
||||
kb_main_cached = kb_page_cache + kb_slab;
|
||||
kb_swap_used = kb_swap_total - kb_swap_free;
|
||||
|
||||
/* if kb_main_available is greater than kb_main_total or our calculation of
|
||||
mem_used overflows, that's symptomatic of running within a lxc container
|
||||
where such values will be dramatically distorted over those of the host. */
|
||||
if (kb_main_available > kb_main_total)
|
||||
kb_main_available = kb_main_free;
|
||||
mem_used = kb_main_total - kb_main_free - kb_main_cached - kb_main_buffers;
|
||||
if (mem_used < 0)
|
||||
mem_used = kb_main_total - kb_main_free;
|
||||
kb_main_used = (unsigned long)mem_used;
|
||||
|
||||
/* zero? might need fallback for 2.6.27 <= kernel <? 3.14 */
|
||||
if (!kb_main_available) {
|
||||
if (linux_version_code < LINUX_VERSION(2, 6, 27))
|
||||
kb_main_available = kb_main_free;
|
||||
else {
|
||||
FILE_TO_BUF(VM_MIN_FREE_FILE, vm_min_free_fd);
|
||||
kb_min_free = (unsigned long) strtoull(buf,&tail,10);
|
||||
|
||||
watermark_low = kb_min_free * 5 / 4; /* should be equal to sum of all 'low' fields in /proc/zoneinfo */
|
||||
|
||||
mem_available = (signed long)kb_main_free - watermark_low
|
||||
+ kb_inactive_file + kb_active_file - MIN((kb_inactive_file + kb_active_file) / 2, watermark_low)
|
||||
+ kb_slab_reclaimable - MIN(kb_slab_reclaimable / 2, watermark_low);
|
||||
|
||||
if (mem_available < 0) mem_available = 0;
|
||||
kb_main_available = (unsigned long)mem_available;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
/* read /proc/vminfo only for 2.5.41 and above */
|
||||
|
||||
typedef struct vm_table_struct {
|
||||
const char *name; /* VM statistic name */
|
||||
unsigned long *slot; /* slot in return struct */
|
||||
} vm_table_struct;
|
||||
|
||||
static int compare_vm_table_structs(const void *a, const void *b){
|
||||
return strcmp(((const vm_table_struct*)a)->name,((const vm_table_struct*)b)->name);
|
||||
}
|
||||
|
||||
// see include/linux/page-flags.h and mm/page_alloc.c
|
||||
unsigned long vm_nr_dirty; // dirty writable pages
|
||||
unsigned long vm_nr_writeback; // pages under writeback
|
||||
unsigned long vm_nr_pagecache; // pages in pagecache -- gone in 2.5.66+ kernels
|
||||
unsigned long vm_nr_page_table_pages;// pages used for pagetables
|
||||
unsigned long vm_nr_reverse_maps; // includes PageDirect
|
||||
unsigned long vm_nr_mapped; // mapped into pagetables
|
||||
unsigned long vm_nr_slab; // in slab
|
||||
unsigned long vm_nr_slab_reclaimable; // 2.6.19+ kernels
|
||||
unsigned long vm_nr_slab_unreclaimable;// 2.6.19+ kernels
|
||||
unsigned long vm_nr_active_file; // 2.6.27+ kernels
|
||||
unsigned long vm_nr_inactive_file; // 2.6.27+ kernels
|
||||
unsigned long vm_nr_free_pages; // 2.6.21+ kernels
|
||||
unsigned long vm_pgpgin; // kB disk reads (same as 1st num on /proc/stat page line)
|
||||
unsigned long vm_pgpgout; // kB disk writes (same as 2nd num on /proc/stat page line)
|
||||
unsigned long vm_pswpin; // swap reads (same as 1st num on /proc/stat swap line)
|
||||
unsigned long vm_pswpout; // swap writes (same as 2nd num on /proc/stat swap line)
|
||||
unsigned long vm_pgalloc; // page allocations
|
||||
unsigned long vm_pgfree; // page freeings
|
||||
unsigned long vm_pgactivate; // pages moved inactive -> active
|
||||
unsigned long vm_pgdeactivate; // pages moved active -> inactive
|
||||
unsigned long vm_pgfault; // total faults (major+minor)
|
||||
unsigned long vm_pgmajfault; // major faults
|
||||
unsigned long vm_pgscan; // pages scanned by page reclaim
|
||||
unsigned long vm_pgrefill; // inspected by refill_inactive_zone
|
||||
unsigned long vm_pgsteal; // total pages reclaimed
|
||||
unsigned long vm_kswapd_steal; // pages reclaimed by kswapd
|
||||
// next 3 as defined by the 2.5.52 kernel
|
||||
unsigned long vm_pageoutrun; // times kswapd ran page reclaim
|
||||
unsigned long vm_allocstall; // times a page allocator ran direct reclaim
|
||||
unsigned long vm_pgrotated; // pages rotated to the tail of the LRU for immediate reclaim
|
||||
// seen on a 2.6.8-rc1 kernel, apparently replacing old fields
|
||||
static unsigned long vm_pgalloc_dma; //
|
||||
static unsigned long vm_pgalloc_high; //
|
||||
static unsigned long vm_pgalloc_normal; //
|
||||
static unsigned long vm_pgrefill_dma; //
|
||||
static unsigned long vm_pgrefill_high; //
|
||||
static unsigned long vm_pgrefill_normal; //
|
||||
static unsigned long vm_pgscan_direct_dma; //
|
||||
static unsigned long vm_pgscan_direct_high; //
|
||||
static unsigned long vm_pgscan_direct_normal; //
|
||||
static unsigned long vm_pgscan_kswapd_dma; //
|
||||
static unsigned long vm_pgscan_kswapd_high; //
|
||||
static unsigned long vm_pgscan_kswapd_normal; //
|
||||
static unsigned long vm_pgsteal_dma; //
|
||||
static unsigned long vm_pgsteal_high; //
|
||||
static unsigned long vm_pgsteal_normal; //
|
||||
// seen on a 2.6.8-rc1 kernel
|
||||
static unsigned long vm_kswapd_inodesteal; //
|
||||
static unsigned long vm_nr_unstable; //
|
||||
static unsigned long vm_pginodesteal; //
|
||||
static unsigned long vm_slabs_scanned; //
|
||||
|
||||
void vminfo(void){
|
||||
char namebuf[32]; /* big enough to hold any row name */
|
||||
vm_table_struct findme = { namebuf, NULL};
|
||||
vm_table_struct *found;
|
||||
char *head;
|
||||
char *tail;
|
||||
static const vm_table_struct vm_table[] = {
|
||||
{"allocstall", &vm_allocstall},
|
||||
{"kswapd_inodesteal", &vm_kswapd_inodesteal},
|
||||
{"kswapd_steal", &vm_kswapd_steal},
|
||||
{"nr_active_file", &vm_nr_active_file}, // 2.6.27+ kernels
|
||||
{"nr_dirty", &vm_nr_dirty}, // page version of meminfo Dirty
|
||||
{"nr_free_pages", &vm_nr_free_pages}, // 2.6.21+ kernels
|
||||
{"nr_inactive_file", &vm_nr_inactive_file}, // 2.6.27+ kernels
|
||||
{"nr_mapped", &vm_nr_mapped}, // page version of meminfo Mapped
|
||||
{"nr_page_table_pages", &vm_nr_page_table_pages},// same as meminfo PageTables
|
||||
{"nr_pagecache", &vm_nr_pagecache}, // gone in 2.5.66+ kernels
|
||||
{"nr_reverse_maps", &vm_nr_reverse_maps}, // page version of meminfo ReverseMaps GONE
|
||||
{"nr_slab", &vm_nr_slab}, // page version of meminfo Slab (gone in 2.6.19+)
|
||||
{"nr_slab_reclaimable", &vm_nr_slab_reclaimable},// 2.6.19+ kernels
|
||||
{"nr_slab_unreclaimable",&vm_nr_slab_unreclaimable},// 2.6.19+ kernels
|
||||
{"nr_unstable", &vm_nr_unstable},
|
||||
{"nr_writeback", &vm_nr_writeback}, // page version of meminfo Writeback
|
||||
{"pageoutrun", &vm_pageoutrun},
|
||||
{"pgactivate", &vm_pgactivate},
|
||||
{"pgalloc", &vm_pgalloc}, // GONE (now separate dma,high,normal)
|
||||
{"pgalloc_dma", &vm_pgalloc_dma},
|
||||
{"pgalloc_high", &vm_pgalloc_high},
|
||||
{"pgalloc_normal", &vm_pgalloc_normal},
|
||||
{"pgdeactivate", &vm_pgdeactivate},
|
||||
{"pgfault", &vm_pgfault},
|
||||
{"pgfree", &vm_pgfree},
|
||||
{"pginodesteal", &vm_pginodesteal},
|
||||
{"pgmajfault", &vm_pgmajfault},
|
||||
{"pgpgin", &vm_pgpgin}, // important
|
||||
{"pgpgout", &vm_pgpgout}, // important
|
||||
{"pgrefill", &vm_pgrefill}, // GONE (now separate dma,high,normal)
|
||||
{"pgrefill_dma", &vm_pgrefill_dma},
|
||||
{"pgrefill_high", &vm_pgrefill_high},
|
||||
{"pgrefill_normal", &vm_pgrefill_normal},
|
||||
{"pgrotated", &vm_pgrotated},
|
||||
{"pgscan", &vm_pgscan}, // GONE (now separate direct,kswapd and dma,high,normal)
|
||||
{"pgscan_direct_dma", &vm_pgscan_direct_dma},
|
||||
{"pgscan_direct_high", &vm_pgscan_direct_high},
|
||||
{"pgscan_direct_normal",&vm_pgscan_direct_normal},
|
||||
{"pgscan_kswapd_dma", &vm_pgscan_kswapd_dma},
|
||||
{"pgscan_kswapd_high", &vm_pgscan_kswapd_high},
|
||||
{"pgscan_kswapd_normal",&vm_pgscan_kswapd_normal},
|
||||
{"pgsteal", &vm_pgsteal}, // GONE (now separate dma,high,normal)
|
||||
{"pgsteal_dma", &vm_pgsteal_dma},
|
||||
{"pgsteal_high", &vm_pgsteal_high},
|
||||
{"pgsteal_normal", &vm_pgsteal_normal},
|
||||
{"pswpin", &vm_pswpin}, // important
|
||||
{"pswpout", &vm_pswpout}, // important
|
||||
{"slabs_scanned", &vm_slabs_scanned},
|
||||
};
|
||||
const int vm_table_count = sizeof(vm_table)/sizeof(vm_table_struct);
|
||||
|
||||
#if __SIZEOF_LONG__ == 4
|
||||
unsigned long long slotll;
|
||||
#endif
|
||||
|
||||
vm_pgalloc = 0;
|
||||
vm_pgrefill = 0;
|
||||
vm_pgscan = 0;
|
||||
vm_pgsteal = 0;
|
||||
|
||||
FILE_TO_BUF(VMINFO_FILE,vminfo_fd);
|
||||
|
||||
head = buf;
|
||||
for(;;){
|
||||
tail = strchr(head, ' ');
|
||||
if(!tail) break;
|
||||
*tail = '\0';
|
||||
if(strlen(head) >= sizeof(namebuf)){
|
||||
head = tail+1;
|
||||
goto nextline;
|
||||
}
|
||||
strcpy(namebuf,head);
|
||||
found = bsearch(&findme, vm_table, vm_table_count,
|
||||
sizeof(vm_table_struct), compare_vm_table_structs
|
||||
);
|
||||
head = tail+1;
|
||||
if(!found) goto nextline;
|
||||
#if __SIZEOF_LONG__ == 4
|
||||
// A 32 bit kernel would have already truncated the value, a 64 bit kernel
|
||||
// doesn't need to. Truncate here to let 32 bit programs to continue to get
|
||||
// truncated values. It's that or change the API for a larger data type.
|
||||
slotll = strtoull(head,&tail,10);
|
||||
*(found->slot) = (unsigned long)slotll;
|
||||
#else
|
||||
*(found->slot) = strtoul(head,&tail,10);
|
||||
#endif
|
||||
nextline:
|
||||
|
||||
//if(found) fprintf(stderr,"%s=%d\n",found->name,*(found->slot));
|
||||
//else fprintf(stderr,"%s not found\n",findme.name);
|
||||
|
||||
tail = strchr(head, '\n');
|
||||
if(!tail) break;
|
||||
head = tail+1;
|
||||
}
|
||||
if(!vm_pgalloc)
|
||||
vm_pgalloc = vm_pgalloc_dma + vm_pgalloc_high + vm_pgalloc_normal;
|
||||
if(!vm_pgrefill)
|
||||
vm_pgrefill = vm_pgrefill_dma + vm_pgrefill_high + vm_pgrefill_normal;
|
||||
if(!vm_pgscan)
|
||||
vm_pgscan = vm_pgscan_direct_dma + vm_pgscan_direct_high + vm_pgscan_direct_normal
|
||||
+ vm_pgscan_kswapd_dma + vm_pgscan_kswapd_high + vm_pgscan_kswapd_normal;
|
||||
if(!vm_pgsteal)
|
||||
vm_pgsteal = vm_pgsteal_dma + vm_pgsteal_high + vm_pgsteal_normal;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// based on Fabian Frederick's /proc/diskstats parser
|
||||
|
@ -7,90 +7,14 @@
|
||||
__BEGIN_DECLS
|
||||
|
||||
extern int have_privs; /* boolean, true if setuid or similar */
|
||||
extern long page_bytes; /* this architecture's bytes per page */
|
||||
|
||||
extern int uptime (double *uptime_secs, double *idle_secs);
|
||||
extern unsigned long getbtime(void);
|
||||
int procps_loadavg(double *av1, double *av5, double *av15);
|
||||
long procps_hertz_get(void);
|
||||
long procps_cpu_count(void);
|
||||
|
||||
/* Shmem in 2.6.32+ */
|
||||
extern unsigned long kb_main_shared;
|
||||
/* old but still kicking -- the important stuff */
|
||||
extern unsigned long kb_main_buffers;
|
||||
extern unsigned long kb_main_cached;
|
||||
extern unsigned long kb_main_free;
|
||||
extern unsigned long kb_main_total;
|
||||
extern unsigned long kb_swap_free;
|
||||
extern unsigned long kb_swap_total;
|
||||
/* recently introduced */
|
||||
extern unsigned long kb_high_free;
|
||||
extern unsigned long kb_high_total;
|
||||
extern unsigned long kb_low_free;
|
||||
extern unsigned long kb_low_total;
|
||||
extern unsigned long kb_main_available;
|
||||
/* 2.4.xx era */
|
||||
extern unsigned long kb_active;
|
||||
extern unsigned long kb_inact_laundry; // grrr...
|
||||
extern unsigned long kb_inact_dirty;
|
||||
extern unsigned long kb_inact_clean;
|
||||
extern unsigned long kb_inact_target;
|
||||
extern unsigned long kb_swap_cached; /* late 2.4+ */
|
||||
/* derived values */
|
||||
extern unsigned long kb_swap_used;
|
||||
extern unsigned long kb_main_used;
|
||||
/* 2.5.41+ */
|
||||
extern unsigned long kb_writeback;
|
||||
extern unsigned long kb_slab;
|
||||
extern unsigned long nr_reversemaps;
|
||||
extern unsigned long kb_committed_as;
|
||||
extern unsigned long kb_dirty;
|
||||
extern unsigned long kb_inactive;
|
||||
extern unsigned long kb_mapped;
|
||||
extern unsigned long kb_pagetables;
|
||||
long procps_hertz_get(void);
|
||||
int procps_loadavg(double *av1, double *av5, double *av15);
|
||||
long procps_pagesize_get(void);
|
||||
|
||||
#define BUFFSIZE (64*1024)
|
||||
typedef unsigned long long jiff;
|
||||
extern 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);
|
||||
|
||||
extern void meminfo(void);
|
||||
|
||||
|
||||
extern unsigned long vm_nr_dirty;
|
||||
extern unsigned long vm_nr_writeback;
|
||||
extern unsigned long vm_nr_pagecache;
|
||||
extern unsigned long vm_nr_page_table_pages;
|
||||
extern unsigned long vm_nr_reverse_maps;
|
||||
extern unsigned long vm_nr_mapped;
|
||||
extern unsigned long vm_nr_slab;
|
||||
extern unsigned long vm_nr_slab_reclaimable;
|
||||
extern unsigned long vm_nr_slab_unreclaimable;
|
||||
extern unsigned long vm_nr_active_file;
|
||||
extern unsigned long vm_nr_inactive_file;
|
||||
extern unsigned long vm_nr_free_pages;
|
||||
extern unsigned long vm_pgpgin;
|
||||
extern unsigned long vm_pgpgout;
|
||||
extern unsigned long vm_pswpin;
|
||||
extern unsigned long vm_pswpout;
|
||||
extern unsigned long vm_pgalloc;
|
||||
extern unsigned long vm_pgfree;
|
||||
extern unsigned long vm_pgactivate;
|
||||
extern unsigned long vm_pgdeactivate;
|
||||
extern unsigned long vm_pgfault;
|
||||
extern unsigned long vm_pgmajfault;
|
||||
extern unsigned long vm_pgscan;
|
||||
extern unsigned long vm_pgrefill;
|
||||
extern unsigned long vm_pgsteal;
|
||||
extern unsigned long vm_kswapd_steal;
|
||||
extern unsigned long vm_pageoutrun;
|
||||
extern unsigned long vm_allocstall;
|
||||
|
||||
extern void vminfo(void);
|
||||
|
||||
typedef struct disk_stat{
|
||||
unsigned long long reads_sectors;
|
||||
|
@ -67,6 +67,7 @@
|
||||
/*###### Miscellaneous global stuff ####################################*/
|
||||
|
||||
static long Hertz;
|
||||
static long Page_size;
|
||||
|
||||
/* The original and new terminal definitions
|
||||
(only set when not in 'Batch' mode) */
|
||||
@ -471,8 +472,8 @@ static void bye_bye (const char *str) {
|
||||
, __func__
|
||||
, PACKAGE_STRING
|
||||
, (unsigned)Hertz, (unsigned)sizeof(Hertz), (unsigned)sizeof(Hertz) * 8
|
||||
, (int)page_bytes, Cpu_faux_cnt, (int)Cpu_cnt
|
||||
, (unsigned)sizeof(HST_t), ((int)page_bytes / (int)sizeof(HST_t)), HHist_siz
|
||||
, (int)Page_size, Cpu_faux_cnt, (int)Cpu_cnt
|
||||
, (unsigned)sizeof(HST_t), ((int)Page_size / (int)sizeof(HST_t)), HHist_siz
|
||||
, (unsigned)sizeof(proc_t), (unsigned)sizeof(p->cmd), (unsigned)sizeof(proc_t*)
|
||||
, (unsigned)sizeof(struct procps_jiffs), (unsigned)sizeof(struct procps_jiffs_hist), (unsigned)sizeof(struct procps_sys_result)
|
||||
, (long)Frames_libflags
|
||||
@ -3252,6 +3253,7 @@ static void before (char *me) {
|
||||
// establish cpu particulars
|
||||
Hertz = procps_hertz_get();
|
||||
Cpu_cnt = procps_cpu_count();
|
||||
Page_size = procps_pagesize_get();
|
||||
#ifdef PRETEND8CPUS
|
||||
Cpu_cnt = 8;
|
||||
#endif
|
||||
@ -3265,7 +3267,7 @@ static void before (char *me) {
|
||||
Cpu_States_fmts = N_unq(STATE_lin2x7_fmt);
|
||||
|
||||
// get virtual page stuff
|
||||
i = page_bytes; // from sysinfo.c, at lib init
|
||||
i = Page_size;
|
||||
while (i > 1024) { i >>= 1; Pg2K_shft++; }
|
||||
|
||||
// prepare for new library API ...
|
||||
|
Loading…
x
Reference in New Issue
Block a user