get rid of warning.
2004/09/28 12:01:02-07:00 osdl.net!shemminger Update to rtstat.c from Robert Olsson (Logical change 1.89)
This commit is contained in:
parent
cb4d97a9a8
commit
63fe5f043e
183
misc/rtstat.c
183
misc/rtstat.c
|
|
@ -10,6 +10,7 @@
|
||||||
*
|
*
|
||||||
* Additional credits:
|
* Additional credits:
|
||||||
* Martin Josefsson <gandalf@wlug.westbo.se> 010828 bug fix
|
* Martin Josefsson <gandalf@wlug.westbo.se> 010828 bug fix
|
||||||
|
* 030420 cleanup
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -18,7 +19,12 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
#define VERSION "0.33 010829"
|
#define VERSION "0.42 030623"
|
||||||
|
|
||||||
|
|
||||||
|
#define FMT_LEN1 11
|
||||||
|
#define FMT_LEN2 15
|
||||||
|
#define FMT_LEN3 17
|
||||||
|
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
extern int optind, opterr, optopt;
|
extern int optind, opterr, optopt;
|
||||||
|
|
@ -26,14 +32,21 @@ extern int optind, opterr, optopt;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
unsigned rt_size, in_hit[2], in_slow_tot[2], in_slow_mc[2],
|
unsigned rt_size, in_hit[2], in_slow_tot[2], in_slow_mc[2],
|
||||||
in_no_rt[2], in_brd[2], in_martian_dst[2], in_martian_src[2],
|
in_no_rt[2], in_brd[2], in_martian_dst[2], in_martian_src[2],
|
||||||
out_hit[2], out_slow_tot[2], out_slow_mc[2];
|
out_hit[2], out_slow_tot[2], out_slow_mc[2], gc_total[2],
|
||||||
|
gc_ignored[2], gc_goal_miss[2], gc_dst_overflow[2],
|
||||||
|
in_hlist_search[2], out_hlist_search[2];
|
||||||
|
|
||||||
|
int llen;
|
||||||
|
|
||||||
|
|
||||||
/* Read (and summarize for SMP) the different stats vars. */
|
/* Read (and summarize for SMP) the different stats vars. */
|
||||||
|
|
||||||
void scan_line(int i)
|
void scan_line(int i)
|
||||||
{
|
{
|
||||||
unsigned temp[10];
|
char buf[1024];
|
||||||
|
unsigned temp[16];
|
||||||
|
|
||||||
|
i %= 2;
|
||||||
|
|
||||||
in_hit[i] = 0;
|
in_hit[i] = 0;
|
||||||
in_slow_tot[i] = 0;
|
in_slow_tot[i] = 0;
|
||||||
|
|
@ -45,9 +58,19 @@ void scan_line(int i)
|
||||||
out_hit[i] = 0;
|
out_hit[i] = 0;
|
||||||
out_slow_tot[i] = 0;
|
out_slow_tot[i] = 0;
|
||||||
out_slow_mc[i] = 0;
|
out_slow_mc[i] = 0;
|
||||||
|
gc_total[i] = 0;
|
||||||
|
gc_ignored[i] = 0;
|
||||||
|
gc_goal_miss[i] = 0;
|
||||||
|
gc_dst_overflow[i] = 0;
|
||||||
|
in_hlist_search[i] = 0;
|
||||||
|
out_hlist_search[i] = 0;
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
fgets(buf, 1023, fp);
|
||||||
|
if( feof(fp) ) break;
|
||||||
|
|
||||||
|
llen = sscanf(buf, "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n",
|
||||||
|
|
||||||
while(!feof(fp)) {
|
|
||||||
fscanf(fp, "%x %x %x %x %x %x %x %x %x %x %x\n",
|
|
||||||
&rt_size,
|
&rt_size,
|
||||||
&temp[0], /* in_hit */
|
&temp[0], /* in_hit */
|
||||||
&temp[1], /* in_slow_tot */
|
&temp[1], /* in_slow_tot */
|
||||||
|
|
@ -58,7 +81,13 @@ void scan_line(int i)
|
||||||
&temp[6], /* in_martian_src */
|
&temp[6], /* in_martian_src */
|
||||||
&temp[7], /* out_hit */
|
&temp[7], /* out_hit */
|
||||||
&temp[8], /* out_slow_tot */
|
&temp[8], /* out_slow_tot */
|
||||||
&temp[9] /* out_slow_mc */
|
&temp[9], /* out_slow_mc */
|
||||||
|
&temp[10], /* gc_total */
|
||||||
|
&temp[11], /* gc_ignored */
|
||||||
|
&temp[12], /* gc_goal_miss */
|
||||||
|
&temp[13], /* gc_dst_overflow */
|
||||||
|
&temp[14], /* in_hlist_search */
|
||||||
|
&temp[15] /* out_hlist_search */
|
||||||
);
|
);
|
||||||
|
|
||||||
in_hit[i] += temp[0];
|
in_hit[i] += temp[0];
|
||||||
|
|
@ -71,13 +100,29 @@ void scan_line(int i)
|
||||||
out_hit[i] += temp[7];
|
out_hit[i] += temp[7];
|
||||||
out_slow_tot[i] += temp[8];
|
out_slow_tot[i] += temp[8];
|
||||||
out_slow_mc[i] += temp[9];
|
out_slow_mc[i] += temp[9];
|
||||||
|
if(llen > FMT_LEN1 ) {
|
||||||
|
gc_total[i] += temp[10];
|
||||||
|
gc_ignored[i] += temp[11];
|
||||||
|
gc_goal_miss[i] += temp[12];
|
||||||
|
gc_dst_overflow[i] += temp[13];
|
||||||
|
}
|
||||||
|
if(llen > FMT_LEN2 ) {
|
||||||
|
in_hlist_search[i] += temp[14];
|
||||||
|
out_hlist_search[i] += temp[15];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_hdr_line(void)
|
void print_hdr_line(void)
|
||||||
{
|
{
|
||||||
printf(" size IN: hit tot mc no_rt bcast madst masrc OUT: hit tot mc\n");
|
printf(" size IN: hit tot mc no_rt bcast madst masrc OUT: hit tot mc");
|
||||||
|
|
||||||
|
if( llen > FMT_LEN1 )
|
||||||
|
printf(" GC: tot ignored goal_miss ovrf");
|
||||||
|
|
||||||
|
if( llen > FMT_LEN2 )
|
||||||
|
printf(" HASH: in_search out_search");
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int usage(int exit_code)
|
int usage(int exit_code)
|
||||||
|
|
@ -97,77 +142,103 @@ int usage(int exit_code)
|
||||||
fprintf(stderr, "bcast == IN: broadcast cache misses per sec\n");
|
fprintf(stderr, "bcast == IN: broadcast cache misses per sec\n");
|
||||||
fprintf(stderr, "madst == IN: dst martians per sec\n");
|
fprintf(stderr, "madst == IN: dst martians per sec\n");
|
||||||
fprintf(stderr, "masrc == IN: src martians per sec\n");
|
fprintf(stderr, "masrc == IN: src martians per sec\n");
|
||||||
|
|
||||||
fprintf(stderr, "hit == OUT: total number of cache hits per sec\n");
|
fprintf(stderr, "hit == OUT: total number of cache hits per sec\n");
|
||||||
fprintf(stderr, "tot == OUT: total number of cache misses per sec\n");
|
fprintf(stderr, "tot == OUT: total number of cache misses per sec\n");
|
||||||
fprintf(stderr, "mc == OUT: mulicast cache misses per sec\n");
|
fprintf(stderr, "mc == OUT: mulicast cache misses per sec\n");
|
||||||
|
fprintf(stderr, "tot == GC: total calls per sec\n");
|
||||||
|
fprintf(stderr, "ignored == GC: calls ignored per sec\n");
|
||||||
|
fprintf(stderr, "goal_miss == GC: goal miss per sec\n");
|
||||||
|
fprintf(stderr, "ovrflw == GC: dst_overflow per sec\n");
|
||||||
|
fprintf(stderr, "in_search == HASH: input hash list search per sec\n");
|
||||||
|
fprintf(stderr, "out_search == HASH: output hash list search per sec\n");
|
||||||
|
|
||||||
exit(exit_code);
|
exit(exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print(int i, int interval)
|
||||||
|
{
|
||||||
|
int new = i % 2;
|
||||||
|
int old = !new;
|
||||||
|
|
||||||
|
printf("%5u %9u %7u %5u %5u %5u %5u %5u %9u %7u %6u",
|
||||||
|
rt_size,
|
||||||
|
(in_hit[new] - in_hit[old])/interval,
|
||||||
|
(in_slow_tot[new] - in_slow_tot[old])/interval,
|
||||||
|
(in_slow_mc[new] - in_slow_mc[old])/interval,
|
||||||
|
(in_no_rt[new] - in_no_rt[old])/interval,
|
||||||
|
(in_brd[new] - in_brd[old])/interval,
|
||||||
|
(in_martian_dst[new] - in_martian_dst[old])/interval,
|
||||||
|
(in_martian_src[new] - in_martian_src[old])/interval,
|
||||||
|
|
||||||
|
(out_hit[new] - out_hit[old])/interval,
|
||||||
|
(out_slow_tot[new] - out_slow_tot[old])/interval,
|
||||||
|
(out_slow_mc[new] - out_slow_mc[old])/interval);
|
||||||
|
|
||||||
|
if(llen > FMT_LEN1 )
|
||||||
|
printf(" %7u %7u %9u %4u",
|
||||||
|
|
||||||
|
(gc_total[new] - gc_total[old])/interval,
|
||||||
|
(gc_ignored[new] - gc_ignored[old])/interval,
|
||||||
|
(gc_goal_miss[new] - gc_goal_miss[old])/interval,
|
||||||
|
(gc_dst_overflow[new] - gc_dst_overflow[old])/interval);
|
||||||
|
|
||||||
|
if(llen > FMT_LEN2 )
|
||||||
|
printf(" %15u %10u",
|
||||||
|
(in_hlist_search[new] - in_hlist_search[old])/interval,
|
||||||
|
(out_hlist_search[new] - out_hlist_search[old])/interval);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int c, i=1, interval=2, hdr=2;
|
int c, i, interval = 2, hdr = 2;
|
||||||
|
|
||||||
while ((c=getopt(argc, argv,"h?s:i:")) != EOF)
|
while ((c=getopt(argc, argv,"h?s:i:")) != EOF) {
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
|
case '?':
|
||||||
case '?':
|
case 'h':
|
||||||
case 'h': usage(0);
|
usage(0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'i':
|
||||||
|
sscanf(optarg, "%u", &interval);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'i': sscanf(optarg, "%u", &interval);
|
case 's':
|
||||||
break;
|
sscanf(optarg, "%u", &hdr);
|
||||||
|
break;
|
||||||
|
|
||||||
case 's': sscanf(optarg, "%u", &hdr);
|
default:
|
||||||
break;
|
usage(1);
|
||||||
|
|
||||||
default: usage(1);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(interval < 1 ) interval=1;
|
if (interval < 1)
|
||||||
|
interval = 1;
|
||||||
|
|
||||||
if ((fp = fopen("/proc/net/rt_cache_stat", "r")));
|
fp = fopen("/proc/net/rt_cache_stat", "r");
|
||||||
else
|
if (!fp) {
|
||||||
{
|
|
||||||
perror("fopen");
|
perror("fopen");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hdr > 0) print_hdr_line();
|
/* Read llen */
|
||||||
|
scan_line(0);
|
||||||
|
rewind(fp);
|
||||||
|
|
||||||
for(;1;i++) {
|
if (hdr > 0)
|
||||||
|
print_hdr_line();
|
||||||
|
|
||||||
if(hdr > 1 && (! (i % 20))) print_hdr_line();
|
for(i = 0;;i++) {
|
||||||
|
if(hdr > 1 && i != 0 && (i % 20) == 0)
|
||||||
scan_line(0);
|
print_hdr_line();
|
||||||
sleep(interval);
|
|
||||||
|
scan_line(i);
|
||||||
rewind(fp);
|
rewind(fp);
|
||||||
scan_line(1);
|
if (i != 0)
|
||||||
rewind(fp);
|
print(i, interval);
|
||||||
|
sleep(interval);
|
||||||
printf("%5u %9u %7u %5u %5u %5u %5u %5u %9u %7u %6u\n",
|
|
||||||
rt_size,
|
|
||||||
(in_hit[1] - in_hit[0])/interval,
|
|
||||||
(in_slow_tot[1] - in_slow_tot[0])/interval,
|
|
||||||
(in_slow_mc[1] - in_slow_mc[0])/interval,
|
|
||||||
(in_no_rt[1] - in_no_rt[0])/interval,
|
|
||||||
(in_brd[1] - in_brd[0])/interval,
|
|
||||||
(in_martian_dst[1] - in_martian_dst[0])/interval,
|
|
||||||
(in_martian_src[1] - in_martian_src[0])/interval,
|
|
||||||
|
|
||||||
(out_hit[1] - out_hit[0])/interval,
|
|
||||||
(out_slow_tot[1] - out_slow_tot[0])/interval,
|
|
||||||
(out_slow_mc[1] - out_slow_mc[0])/interval
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Compile:
|
|
||||||
gcc -g -O2 -Wall -o rtstat rtstat.c
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue