From 7a952aedac7e42f39bb434263bb6070fa71a9309 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Apr 2002 02:50:03 +0200 Subject: [PATCH] nicer stats display --- ccache.h | 1 + stats.c | 47 ++++++++++++++++++++++++++++------------------- util.c | 16 ++++++++++++++-- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/ccache.h b/ccache.h index 582756dd8..4f0857418 100644 --- a/ccache.h +++ b/ccache.h @@ -86,6 +86,7 @@ void stats_tocache(size_t size); void stats_read(const char *stats_file, unsigned counters[STATS_END]); void stats_set_limits(long maxfiles, long maxsize); size_t value_units(const char *s); +void display_size(unsigned v); void stats_set_sizes(const char *dir, size_t num_files, size_t total_size); int unify_hash(const char *fname); diff --git a/stats.c b/stats.c index 8db2dbadf..341ecad87 100644 --- a/stats.c +++ b/stats.c @@ -32,34 +32,35 @@ extern char *cache_dir; static struct { enum stats stat; char *message; + void (*fn)(unsigned ); } stats_messages[] = { - { STATS_TOCACHE, "cache miss" }, - { STATS_CACHED, "cache hit" }, - { STATS_LINK, "called for link" }, - { STATS_STDOUT, "compiler produced stdout" }, - { STATS_STATUS, "compile failed" }, - { STATS_ERROR, "ccache internal error" }, - { STATS_PREPROCESSOR, "preprocessor error" }, - { STATS_COMPILER, "couldn't find the compiler" }, - { STATS_MISSING, "cache file missing" }, - { STATS_ARGS, "bad compiler arguments" }, - { STATS_NUMFILES, "files in cache" }, - { STATS_TOTALSIZE, "cache size" }, - { STATS_MAXFILES, "max files" }, - { STATS_MAXSIZE, "max cache size" }, - { STATS_NONE, NULL } + { STATS_TOCACHE, "cache miss ", NULL }, + { STATS_CACHED, "cache hit ", NULL }, + { STATS_LINK, "called for link ", NULL }, + { STATS_STDOUT, "compiler produced stdout ", NULL }, + { STATS_STATUS, "compile failed ", NULL }, + { STATS_ERROR, "ccache internal error ", NULL }, + { STATS_PREPROCESSOR, "preprocessor error ", NULL }, + { STATS_COMPILER, "couldn't find the compiler ", NULL }, + { STATS_MISSING, "cache file missing ", NULL }, + { STATS_ARGS, "bad compiler arguments ", NULL }, + { STATS_NUMFILES, "files in cache ", NULL }, + { STATS_TOTALSIZE, "cache size ", display_size }, + { STATS_MAXFILES, "max files ", NULL }, + { STATS_MAXSIZE, "max cache size ", display_size }, + { STATS_NONE, NULL, NULL } }; /* return a string description of a statistic */ -static char *stats_message(enum stats stat) +static int stats_message(enum stats stat) { int i; for (i=0;stats_messages[i].stat != STATS_NONE; i++) { if (stats_messages[i].stat == stat) { - return stats_messages[i].message; + return i; } } - return "unknown"; + return -1; } /* parse a stats file from a buffer - adding to the counters */ @@ -212,7 +213,15 @@ void stats_summary(void) /* and display them */ for (i=0;i 1024*1024) { + printf("%8.1f Gbytes", v/((double)(1024*1024))); + } else if (v > 1024) { + printf("%8.1f Mbytes", v/((double)(1024))); + } else { + printf("%8u Kbytes", v); + } +} + /* return a value in multiples of 1024 give a string that can end in K, M or G */ size_t value_units(const char *s) { char m; - size_t v = atoi(s); + double v = atof(s); m = s[strlen(s)-1]; switch (m) { case 'G': @@ -290,7 +302,7 @@ size_t value_units(const char *s) v *= 1; break; } - return v; + return (size_t)v; } -- 2.47.3