terabytes

This commit is contained in:
albert 2006-01-22 07:57:13 +00:00
parent d8760aae6c
commit 58f47c6614
3 changed files with 14 additions and 12 deletions

1
NEWS
View File

@ -1,5 +1,6 @@
procps-3.2.6 --> procps-3.2.7 procps-3.2.6 --> procps-3.2.7
top: document H option -- thanks Tony Ernst top: document H option -- thanks Tony Ernst
top: terabytes -- thanks Tony Ernst
procps-3.2.5 --> procps-3.2.6 procps-3.2.5 --> procps-3.2.6

23
top.c
View File

@ -745,23 +745,24 @@ static int get_int (const char *prompt)
* SK_no (0) it's a byte count * SK_no (0) it's a byte count
* SK_Kb (1) it's kilobytes * SK_Kb (1) it's kilobytes
* SK_Mb (2) it's megabytes * SK_Mb (2) it's megabytes
* SK_Gb (3) it's gigabytes */ * SK_Gb (3) it's gigabytes
static const char *scale_num (unsigned num, const int width, const unsigned type) * SK_Tb (4) it's terabytes */
static const char *scale_num (unsigned long num, const int width, const unsigned type)
{ {
/* kilobytes, megabytes, gigabytes, duh! */ /* kilobytes, megabytes, gigabytes, terabytes, duh! */
static float scale[] = { 1024, 1024*1024, 1024*1024*1024, 0 }; static double scale[] = { 1024.0, 1024.0*1024, 1024.0*1024*1024, 1024.0*1024*1024*1024, 0 };
/* kilo, mega, giga, none */ /* kilo, mega, giga, tera, none */
#ifdef CASEUP_SCALE #ifdef CASEUP_SCALE
static char nextup[] = { 'K', 'M', 'G', 0 }; static char nextup[] = { 'K', 'M', 'G', 'T', 0 };
#else #else
static char nextup[] = { 'k', 'm', 'g', 0 }; static char nextup[] = { 'k', 'm', 'g', 't', 0 };
#endif #endif
static char buf[TNYBUFSIZ]; static char buf[TNYBUFSIZ];
float *dp; double *dp;
char *up; char *up;
/* try an unscaled version first... */ /* try an unscaled version first... */
if (width >= snprintf(buf, sizeof(buf), "%u", num)) return buf; if (width >= snprintf(buf, sizeof(buf), "%lu", num)) return buf;
/* now try successively higher types until it fits */ /* now try successively higher types until it fits */
for (up = nextup + type, dp = scale; *dp; ++dp, ++up) { for (up = nextup + type, dp = scale; *dp; ++dp, ++up) {
@ -769,7 +770,7 @@ static const char *scale_num (unsigned num, const int width, const unsigned type
if (width >= snprintf(buf, sizeof(buf), "%.1f%c", num / *dp, *up)) if (width >= snprintf(buf, sizeof(buf), "%.1f%c", num / *dp, *up))
return buf; return buf;
/* the integer version */ /* the integer version */
if (width >= snprintf(buf, sizeof(buf), "%d%c", (int)(num / *dp), *up)) if (width >= snprintf(buf, sizeof(buf), "%ld%c", (unsigned long)(num / *dp), *up))
return buf; return buf;
} }
/* well shoot, this outta' fit... */ /* well shoot, this outta' fit... */
@ -2991,7 +2992,7 @@ static proc_t **summary_show (void)
} }
#define PAGES_TO_KB(n) (unsigned)( (n) << page_to_kb_shift ) #define PAGES_TO_KB(n) (unsigned long)( (n) << page_to_kb_shift )
// the following macro is our means to 'inline' emitting a column -- next to // the following macro is our means to 'inline' emitting a column -- next to
// procs_refresh, that's the most frequent and costly part of top's job ! // procs_refresh, that's the most frequent and costly part of top's job !

2
top.h
View File

@ -240,7 +240,7 @@ typedef struct RCF_t { // the complete rcfile (new style)
// The scaling 'type' used with scale_num() -- this is how // The scaling 'type' used with scale_num() -- this is how
// the passed number is interpreted should scaling be necessary // the passed number is interpreted should scaling be necessary
enum scale_num { enum scale_num {
SK_no, SK_Kb, SK_Mb, SK_Gb SK_no, SK_Kb, SK_Mb, SK_Gb, SK_Tb
}; };
// Flags for each possible field // Flags for each possible field