diff --git a/sbin/hammer/cmd_stats.c b/sbin/hammer/cmd_stats.c index 5a853f7..bb814e1 100644 --- a/sbin/hammer/cmd_stats.c +++ b/sbin/hammer/cmd_stats.c @@ -37,8 +37,13 @@ #include "hammer.h" #include #include +#include +#include +#include +#include static void loaddelay(struct timespec *ts, const char *arg); +static void usage(void); void hammer_cmd_bstats(char **av, int ac) @@ -109,6 +114,9 @@ hammer_cmd_bstats(char **av, int ac) void hammer_cmd_iostats(char **av, int ac) { + int ch; + char st[8][5]; + _Bool humanize; int mibs[9][16]; size_t lens[9]; int64_t stats[9]; @@ -154,6 +162,21 @@ hammer_cmd_iostats(char **av, int ac) perror("sysctl: HAMMER stats not available"); exit(1); } + + humanize = false; + + while ((ch = getopt(ac, av, "hm")) != -1) { + switch (ch) { + case 'm': + humanize = true; + break; + case 'h': + usage(); + default: + usage(); + } + } + for (count = 0; ; ++count) { for (i = 0; i <= 8; ++i) { @@ -164,19 +187,40 @@ hammer_cmd_iostats(char **av, int ac) exit(1); } } + if (count) { if ((count & 15) == 1) printf(" file-rd file-wr dev-read dev-write inode_ops ino_flsh cmmit undo\n"); - printf("%9jd %9jd %9jd %9jd %9jd %8jd %5jd %8jd\n", - (intmax_t)(stats[0] - copy[0]), - (intmax_t)(stats[1] - copy[1]), - (intmax_t)(stats[2] - copy[2]), - (intmax_t)(stats[3] - copy[3]), - (intmax_t)(stats[4] + stats[5] - - copy[4] - copy[5]), - (intmax_t)(stats[6] - copy[6]), - (intmax_t)(stats[7] - copy[7]), - (intmax_t)(stats[8] - copy[8])); + if (humanize) { + humanize_number(st[0], sizeof(st[0]), (intmax_t)(stats[0] - copy[0]), "", HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE|HN_B); + humanize_number(st[1], sizeof(st[1]), (intmax_t)(stats[1] - copy[1]), "", HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE|HN_B); + humanize_number(st[2], sizeof(st[2]), (intmax_t)(stats[2] - copy[2]), "", HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE|HN_B); + humanize_number(st[3], sizeof(st[3]), (intmax_t)(stats[3] - copy[3]), "", HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE|HN_B); + humanize_number(st[4], sizeof(st[4]), (intmax_t)(stats[4] + stats[5] - copy[4] - copy[5]), "", HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE|HN_B); + humanize_number(st[5], sizeof(st[5]), (intmax_t)(stats[6] - copy[6]), "", HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE|HN_B); + humanize_number(st[6], sizeof(st[6]), (intmax_t)(stats[7] - copy[7]), "", HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE|HN_B); + humanize_number(st[7], sizeof(st[7]), (intmax_t)(stats[8] - copy[8]), "", HN_AUTOSCALE, HN_DECIMAL|HN_NOSPACE|HN_B); + printf("%s %s %s %s %s %s %s %s\n", + st[0], + st[1], + st[2], + st[3], + st[4], + st[5], + st[6], + st[7]); + } else { + printf("%9jd %9jd %9jd %9jd %9jd %8jd %5jd %8jd\n", + (intmax_t)(stats[0] - copy[0]), + (intmax_t)(stats[1] - copy[1]), + (intmax_t)(stats[2] - copy[2]), + (intmax_t)(stats[3] - copy[3]), + (intmax_t)(stats[4] + stats[5] - + copy[4] - copy[5]), + (intmax_t)(stats[6] - copy[6]), + (intmax_t)(stats[7] - copy[7]), + (intmax_t)(stats[8] - copy[8])); + } } nanosleep(&delay, NULL); bcopy(stats, copy, sizeof(stats)); @@ -199,3 +243,13 @@ loaddelay(struct timespec *ts, const char *arg) ts->tv_nsec = (int)(modf(d, &d) * 1000000000.0); } +static +void +usage(void) +{ + fprintf(stderr, "hammer iostats [interval] [options]\n"); + fprintf(stderr, "\nOptions:\n" + "\t-m\t Display humanized output.\n" + "\t-h\t Displays this list of options.\n"); + exit(EX_USAGE); +} \ No newline at end of file diff --git a/sbin/hammer/hammer.8 b/sbin/hammer/hammer.8 index 97b121f..0db8b22 100644 --- a/sbin/hammer/hammer.8 +++ b/sbin/hammer/hammer.8 @@ -257,6 +257,8 @@ Pause .Ar interval seconds between each display. The default interval is one second. +.It Fl m +Displays humanized numbers. .\" ==== history ==== .It Cm history Ar path ... Show the modification history for diff --git a/sbin/hammer/hammer.c b/sbin/hammer/hammer.c index 88b51c4..4af9873 100644 --- a/sbin/hammer/hammer.c +++ b/sbin/hammer/hammer.c @@ -548,7 +548,7 @@ usage(int exit_code) " command [argument ...]\n" "hammer synctid [quick]\n" "hammer bstats [interval]\n" - "hammer iostats [interval]\n" + "hammer iostats [interval] [options]\n" "hammer history[@offset[,len]] ...\n" "hammer namekey1 \n" "hammer namekey2 \n"