[procps] [PATCH] Add support for displaying petabyte and exabyte values.

  • From: Tony Ernst <tee@xxxxxxx>
  • To: procps@xxxxxxxxxxxxx
  • Date: Wed, 24 Aug 2011 14:33:38 -0500

The scale_num() routine currently scales up to terabyte values.
This patch allows it to go beyond that.

Signed-off-by: Tony Ernst <tee@xxxxxxx>
---
 top.c |   11 +++++++----
 top.h |    2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/top.c b/top.c
index b945797..d86ce14 100644
--- a/top.c
+++ b/top.c
@@ -1030,15 +1030,18 @@ static int get_int (const char *prompt) {
          *    SK_Kb (1) it's kilobytes
          *    SK_Mb (2) it's megabytes
          *    SK_Gb (3) it's gigabytes
-         *    SK_Tb (4) it's terabytes  */
+         *    SK_Tb (4) it's terabytes
+         *    SK_Pb (5) it's petabytes
+         *    SK_Eb (6) it's exabytes   */
 static const char *scale_num (unsigned long num, const int width, const int 
type) {
       // kilobytes, megabytes, gigabytes, terabytes, duh!
-   static double scale[] = { 1024.0, 1024.0*1024, 1024.0*1024*1024, 
1024.0*1024*1024*1024, 0 };
+   static double scale[] = { 1024.0, 1024.0*1024, 1024.0*1024*1024, 
1024.0*1024*1024*1024, 
+                             1024.0*1024*1024*1024*1024, 
1024.0*1024*1024*1024*1024*1024, 0 };
       // kilo, mega, giga, tera, none
 #ifdef CASEUP_SUFIX
-   static char nextup[] =  { 'K', 'M', 'G', 'T', 0 };
+   static char nextup[] =  { 'K', 'M', 'G', 'T', 'P', 'E', 0 };
 #else
-   static char nextup[] =  { 'k', 'm', 'g', 't', 0 };
+   static char nextup[] =  { 'k', 'm', 'g', 't', 'p', 'e', 0 };
 #endif
    static char buf[SMLBUFSIZ];
    double *dp;
diff --git a/top.h b/top.h
index dcf54ae..f3ac5b2 100644
--- a/top.h
+++ b/top.h
@@ -145,7 +145,7 @@ enum pflag {
         /* The scaling 'type' used with scale_num() -- this is how
            the passed number is interpreted should scaling be necessary */
 enum scale_num {
-   SK_no, SK_Kb, SK_Mb, SK_Gb, SK_Tb
+   SK_no, SK_Kb, SK_Mb, SK_Gb, SK_Tb, SK_Pb, SK_Eb
 };
 
         /* This typedef just ensures consistent 'process flags' handling */
-- 
1.7.1


Other related posts:

  • » [procps] [PATCH] Add support for displaying petabyte and exabyte values. - Tony Ernst