_ RU.LINUX (2:5077/15.22) ___________________________________________ RU.LINUX _
From : Boris Tobotras 2:5020/510 15 May 97 06:29:44
Subj : 2.1.22+ slab allocator statistics tool
________________________________________________________________________________
/* Slabinfo - peek into the slab allocator - By Aaron Tiensivu *
* Version 0.1 - [05/08/97] - Under GPL, standard disclaimers apply *
* *
* Usage: slabinfo [-a] *
* -a will also show empty slab catagories *
* *
* Could this be a perl script? Sure. *
* Why did I write it? Hack value and curiosity *
* Limited amount of error checking since this is a QuickHack(tm) *
* *
* Compile *
* For pgcc: *
* gcc -o slabinfo -s -O6 -frisc -mpentium slabinfo.c *
* *
* For GCC 2.7.2: *
* gcc -o slabinfo -s -O2 -m486 -fomit-frame-pointer slabinfo.c */
struct slabinfo_stat {
char cache_name[20];
unsigned long active_objs;
unsigned long total_objs;
unsigned long active_slabs;
unsigned long total_slabs;
unsigned long pages_per_slab;
};
static inline char *
skip_token(const char *p)
{
while (isspace(*p)) p++;
while (*p && !isspace(*p)) p++;
return (char *)p;
}
register int count = -1;
int fd, len, i, show_all = 0;
char *p;
/* overall.cache_name is never used */
overall.active_objs = 0;
overall.total_objs = 0;
overall.active_slabs= 0;
overall.total_slabs = 0;
overall.pages_per_slab = 0;
while ((ch = getopt(argc, argv, "a")) != EOF)
switch(ch)
{
case 'a':
show_all = 1;
break;
default:
printf("nnslabinfo version 0.1 [05/08/97] - By Aaron Tiensivu n");
printf("usage: slabinfo [-a]n");
printf(" -a includes empty slabs in output nn");
exit(0);
}
/* Check to see that /proc is really there */
if (statfs(PROC, &sb) < 0 || sb.f_type != PROC_SUPER_MAGIC)
{
fprintf(stderr, "slabinfo: proc not mounted on " PROC "n");
exit(-1);
}
/* Relative filename lookups are faster than absolute. */
/* I realize that we're only reading one file, but it is */
/* the thought that counts. ;-) */
chdir(PROC);
if ( (fd = open("slabinfo", O_RDONLY)) < 0)
{
fprintf(stderr,"slabinfo: slabinfo not foundn");
exit(-1);
}
len = read(fd, buffer, sizeof(buffer)-1);
close(fd);
buffer[len] = '