summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/systat/engine.c66
-rw-r--r--usr.bin/systat/engine.h4
2 files changed, 68 insertions, 2 deletions
diff --git a/usr.bin/systat/engine.c b/usr.bin/systat/engine.c
index 512e5def1d1..4c14c2fa8a0 100644
--- a/usr.bin/systat/engine.c
+++ b/usr.bin/systat/engine.c
@@ -1,4 +1,4 @@
-/* $Id: engine.c,v 1.3 2008/06/13 17:45:02 canacar Exp $ */
+/* $Id: engine.c,v 1.4 2008/07/22 03:00:23 canacar Exp $ */
/*
* Copyright (c) 2001, 2007 Can Erkin Acar <canacar@openbsd.org>
*
@@ -691,6 +691,13 @@ print_fld_sdiv(field_def *fld, u_int64_t size, int div)
size /= div;
if (tbprintf("%lluG", size) <= len)
goto ok;
+ if (size == 0)
+ goto err;
+
+ tb_start();
+ size /= div;
+ if (tbprintf("%lluT", size) <= len)
+ goto ok;
err:
print_fld_str(fld, "*");
@@ -708,6 +715,63 @@ print_fld_size(field_def *fld, u_int64_t size)
}
void
+print_fld_ssdiv(field_def *fld, int64_t size, int div)
+{
+ int len;
+
+ if (fld == NULL)
+ return;
+
+ len = fld->width;
+ if (len < 1)
+ return;
+
+ tb_start();
+ if (tbprintf("%lld", size) <= len)
+ goto ok;
+
+ tb_start();
+ size /= div;
+ if (tbprintf("%lldK", size) <= len)
+ goto ok;
+ if (size == 0)
+ goto err;
+
+ tb_start();
+ size /= div;
+ if (tbprintf("%lldM", size) <= len)
+ goto ok;
+ if (size == 0)
+ goto err;
+
+ tb_start();
+ size /= div;
+ if (tbprintf("%lldG", size) <= len)
+ goto ok;
+ if (size == 0)
+ goto err;
+
+ tb_start();
+ size /= div;
+ if (tbprintf("%lldT", size) <= len)
+ goto ok;
+
+err:
+ print_fld_str(fld, "*");
+ tb_end();
+ return;
+
+ok:
+ print_fld_tb(fld);
+}
+
+void
+print_fld_ssize(field_def *fld, int64_t size)
+{
+ print_fld_ssdiv(fld, size, 1024);
+}
+
+void
print_fld_rate(field_def *fld, double rate)
{
if (rate < 0) {
diff --git a/usr.bin/systat/engine.h b/usr.bin/systat/engine.h
index fd3d7e91a01..86f00012b53 100644
--- a/usr.bin/systat/engine.h
+++ b/usr.bin/systat/engine.h
@@ -1,4 +1,4 @@
-/* $Id: engine.h,v 1.1 2008/06/12 22:26:01 canacar Exp $ */
+/* $Id: engine.h,v 1.2 2008/07/22 03:00:23 canacar Exp $ */
/*
* Copyright (c) 2001, 2007 Can Erkin Acar <canacar@openbsd.org>
*
@@ -109,6 +109,8 @@ void print_fld_str(field_def *fld, const char *str);
void print_fld_age(field_def *fld, unsigned int age);
void print_fld_sdiv(field_def *fld, u_int64_t size, int div);
void print_fld_size(field_def *fld, u_int64_t size);
+void print_fld_ssdiv(field_def *fld, int64_t size, int div);
+void print_fld_ssize(field_def *fld, int64_t size);
void print_fld_bw(field_def *fld, double bw);
void print_fld_rate(field_def *fld, double rate);
void print_fld_uint(field_def *fld, unsigned int size);