Page MenuHomeFreeBSD

D46231.id141854.diff
No OneTemporary

D46231.id141854.diff

diff --git a/usr.sbin/gstat/gstat.8 b/usr.sbin/gstat/gstat.8
--- a/usr.sbin/gstat/gstat.8
+++ b/usr.sbin/gstat/gstat.8
@@ -80,6 +80,8 @@
.Pq Dv BIO_FLUSH .
.It Fl s
Enable blocks' size statistics.
+.It Fl S
+Enable auto scale
.It Fl I Ar interval
Refresh the
.Nm
diff --git a/usr.sbin/gstat/gstat.c b/usr.sbin/gstat/gstat.c
--- a/usr.sbin/gstat/gstat.c
+++ b/usr.sbin/gstat/gstat.c
@@ -29,7 +29,7 @@
* SUCH DAMAGE.
*/
-
+#include <sys/param.h>
#include <sys/devicestat.h>
#include <sys/mman.h>
#include <sys/resource.h>
@@ -52,7 +52,7 @@
#include <unistd.h>
static int flag_a, flag_b, flag_B, flag_c, flag_C, flag_d, flag_o, flag_p,
- flag_s;
+ flag_s, flag_S;
static int flag_I = 1000000;
#define HIGH_PCT_BUSY_THRESH 80
@@ -73,6 +73,26 @@
return ("Filter: ");
}
+// Input kb, scaling automatically
+static void
+scale_input(double *bytes, const char **ident)
+{
+ if (!flag_S)
+ return;
+
+ *ident = "k";
+
+ if (*bytes > 1024) {
+ *ident = "M";
+ *bytes /= 1024;
+ }
+
+ if (*bytes > 1024) {
+ *ident = "G";
+ *bytes /= 1024;
+ }
+}
+
int
main(int argc, char **argv)
{
@@ -80,7 +100,7 @@
int curx, cury, maxx, maxy, line_len, loop, max_flen, head_printed;
struct devstat *gsp, *gsq;
void *sp, *sq;
- double dt;
+ double dt, temp;
struct timespec tp, tq;
struct gmesh gmp;
struct gprovider *pp;
@@ -88,6 +108,8 @@
struct gident *gid;
regex_t f_re, tmp_f_re;
short cf, cb;
+ const char *title_ident = "k";
+ const char *format_ident = "";
char *p;
char f_s[100], pf_s[100], tmp_f_s[100];
char ts[100], g_name[4096];
@@ -98,6 +120,12 @@
History *hist;
HistEvent hist_ev;
+#define SCALE(value, result, ident) \
+ do { \
+ result = (double)(value); \
+ scale_input(&result, &ident); \
+ } while (0);
+
hist = NULL;
el = NULL;
maxx = -1;
@@ -108,7 +136,7 @@
flag_b = 1;
f_s[0] = '\0';
- while ((i = getopt(argc, argv, "abBdcCf:I:ops")) != -1) {
+ while ((i = getopt(argc, argv, "abBdcCf:I:opsS")) != -1) {
switch (i) {
case 'a':
flag_a = 1;
@@ -164,6 +192,10 @@
case 's':
flag_s = 1;
break;
+ case 'S':
+ flag_S = 1;
+ title_ident = " x";
+ break;
case '?':
default:
usage();
@@ -260,19 +292,25 @@
PRINTMSG("\n");
PRINTMSG(" L(q) ops/s ");
if (flag_s) {
- PRINTMSG(" r/s kB kBps ms/r ");
- PRINTMSG(" w/s kB kBps ms/w ");
+ PRINTMSG(" r/s %sB %sBps ms/r ",
+ title_ident, title_ident);
+ PRINTMSG(" w/s %sB %sBps ms/w ",
+ title_ident, title_ident);
}
else {
- PRINTMSG(" r/s kBps ms/r ");
- PRINTMSG(" w/s kBps ms/w ");
+ PRINTMSG(" r/s %sBps ms/r ",
+ title_ident);
+ PRINTMSG(" w/s %sBps ms/w ",
+ title_ident);
}
if (flag_d) {
if (flag_s) {
- PRINTMSG(" d/s kB kBps");
+ PRINTMSG(" d/s %sB %sBps",
+ title_ident, title_ident);
PRINTMSG(" ms/d ");
} else
- PRINTMSG(" d/s kBps ms/d ");
+ PRINTMSG(" d/s %sBps ms/d ",
+ title_ident);
}
if (flag_o)
PRINTMSG(" o/s ms/o ");
@@ -445,17 +483,25 @@
PRINTMSG(" %4ju", (uintmax_t)u64);
PRINTMSG(" %6.0f", (double)ld[0]);
PRINTMSG(" %6.0f", (double)ld[1]);
- if (flag_s)
- PRINTMSG(" %6.0f", (double)ld[13]);
- PRINTMSG(" %6.0f", (double)ld[2] * 1024);
+ if (flag_s) {
+ SCALE((double)ld[13], temp, format_ident);
+ PRINTMSG(" %6.0f%s", temp,
+ format_ident);
+ }
+ SCALE((double)ld[2] * 1024, temp, format_ident);
+ PRINTMSG(" %6.0f%s", temp, format_ident);
if (ld[3] > 1e3)
PRINTMSG(" %6.0f", (double)ld[3]);
else
PRINTMSG(" %6.1f", (double)ld[3]);
PRINTMSG(" %6.0f", (double)ld[4]);
- if (flag_s)
- PRINTMSG(" %6.0f", (double)ld[14]);
- PRINTMSG(" %6.0f", (double)ld[5] * 1024);
+ if (flag_s) {
+ SCALE((double)ld[14], temp, format_ident);
+ PRINTMSG(" %6.0f%s", temp,
+ format_ident);
+ }
+ SCALE((double)ld[5] * 1024, temp, format_ident);
+ PRINTMSG(" %6.0f%s", temp, format_ident);
if (ld[6] > 1e3)
PRINTMSG(" %6.0f", (double)ld[6]);
else
@@ -463,11 +509,14 @@
if (flag_d) {
PRINTMSG(" %6.0f", (double)ld[8]);
- if (flag_s)
- PRINTMSG(" %6.0f",
- (double)ld[15]);
- PRINTMSG(" %6.0f",
- (double)ld[9] * 1024);
+ if (flag_s) {
+ SCALE((double)ld[15], temp, format_ident);
+ PRINTMSG(" %6.0f%s", temp,
+ format_ident);
+ }
+ SCALE((double)ld[9] * 1024, temp, format_ident);
+ PRINTMSG(" %6.0f%s", temp,
+ format_ident);
if (ld[10] > 1e3)
PRINTMSG(" %6.0f",
(double)ld[10]);
@@ -595,7 +644,7 @@
static void
usage(void)
{
- fprintf(stderr, "usage: gstat [-abBcCdps] [-f filter] [-I interval]\n");
+ fprintf(stderr, "usage: gstat [-abBcCdpsS] [-f filter] [-I interval]\n");
exit(EX_USAGE);
/* NOTREACHED */
}

File Metadata

Mime Type
text/plain
Expires
Thu, Feb 5, 10:58 AM (2 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28441835
Default Alt Text
D46231.id141854.diff (4 KB)

Event Timeline