summaryrefslogtreecommitdiffstats
path: root/release
diff options
context:
space:
mode:
authorluigi <luigi@FreeBSD.org>2001-12-14 01:10:50 +0000
committerluigi <luigi@FreeBSD.org>2001-12-14 01:10:50 +0000
commitbe0e572294d7683426b3e00996ab3ee1c3229ab9 (patch)
tree6b73b898064316575931fb960cf529f57dbab326 /release
parenta6be0b0189c6aa7058163245f672f9a1608efc5d (diff)
downloadFreeBSD-src-be0e572294d7683426b3e00996ab3ee1c3229ab9.zip
FreeBSD-src-be0e572294d7683426b3e00996ab3ee1c3229ab9.tar.gz
Add a '-l' flag to show CPU load for the various states, similar to what
"top" does (thinking of it, i could have as well used the same format line!) This only makes sense when "-w" option is also specified, because the load is computed as the difference between subsequent samples. I think this (and the "-d" feature which shows differences in the network statistics counts) would also make sense in the standard vmstat and netstat.
Diffstat (limited to 'release')
-rw-r--r--release/picobsd/tinyware/ns/ns.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/release/picobsd/tinyware/ns/ns.c b/release/picobsd/tinyware/ns/ns.c
index 64c4054..83ddecc 100644
--- a/release/picobsd/tinyware/ns/ns.c
+++ b/release/picobsd/tinyware/ns/ns.c
@@ -66,6 +66,7 @@
char *progname;
int iflag = 0;
+int lflag = 0; /* print cpu load info */
int rflag = 0;
int sflag = 0;
int pflag = 0;
@@ -78,7 +79,7 @@ extern int optind;
void
usage()
{
- fprintf(stderr, "\n%s [-nrsi] [-p proto] [-w wait]\n", progname);
+ fprintf(stderr, "\n%s [-nrsil] [-p proto] [-w wait]\n", progname);
#ifdef BRIDGING
fprintf(stderr, " proto: {ip|tcp|udp|icmp|bdg}\n\n");
#else
@@ -743,7 +744,7 @@ main(int argc, char *argv[])
progname = argv[0];
- while ((c = getopt(argc, argv, "dinrsp:w:")) != -1) {
+ while ((c = getopt(argc, argv, "dilnrsp:w:")) != -1) {
switch (c) {
case 'd': /* print deltas in stats every w seconds */
delta++ ;
@@ -759,6 +760,9 @@ main(int argc, char *argv[])
case 'i':
iflag++;
break;
+ case 'l':
+ lflag++;
+ break;
case 's':
sflag++;
rflag = 0;
@@ -793,6 +797,7 @@ again:
printf("\033[H%s", ctime(&t.tv_sec));
}
print_routing(proto);
+ print_load_stats();
stats(proto);
if (wflag) {
sleep(wflag);
@@ -801,6 +806,45 @@ again:
exit(0);
}
+int
+print_load_stats(void)
+{
+ static u_int32_t cp_time[5];
+ u_int32_t new_cp_time[5];
+ int l;
+ int shz;
+ static int stathz ;
+
+ if (!lflag || !wflag)
+ return 0;
+ l = sizeof(new_cp_time) ;
+ bzero(new_cp_time, l);
+ if (sysctlbyname("kern.cp_time", new_cp_time, &l, NULL, 0) < 0) {
+ warn("sysctl: retrieving cp_time length");
+ return 0;
+ }
+ if (stathz == 0) {
+ struct clockinfo ci;
+
+ bzero (&ci, sizeof(ci));
+ l = sizeof(ci) ;
+ if (sysctlbyname("kern.clockrate", &ci, &l, NULL, 0) < 0) {
+ warn("sysctl: retrieving clockinfo length");
+ return 0;
+ }
+ stathz = ci.stathz ;
+ bcopy(new_cp_time, cp_time, sizeof(cp_time));
+ }
+ shz = stathz * wflag ;
+ if (shz == 0)
+ shz = 1;
+#define X(i) ( (double)(new_cp_time[i] - cp_time[i])*100/shz )
+ printf("\nUSER %5.2f%% NICE %5.2f%% SYS %5.2f%% "
+ "INTR %5.2f%% IDLE %5.2f%%\n",
+ X(0), X(1), X(2), X(3), X(4) );
+ bcopy(new_cp_time, cp_time, sizeof(cp_time));
+}
+
#ifdef BRIDGING
/* print bridge statistics */
int
OpenPOWER on IntegriCloud