]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
nicer stats display
authorAndrew Tridgell <tridge@samba.org>
Mon, 1 Apr 2002 00:50:03 +0000 (02:50 +0200)
committerAndrew Tridgell <tridge@samba.org>
Mon, 1 Apr 2002 00:50:03 +0000 (02:50 +0200)
ccache.h
stats.c
util.c

index 582756dd8b75aa1f3c7f06e043de3d05dcef8c57..4f08574182d430a4bb685809e310e03effcd08bd 100644 (file)
--- 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 8db2dbadf9a1ce51fad8e2fc8a584a1ae4b04200..341ecad87aff5dcdf08867c726474920cddfdde0 100644 (file)
--- 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<STATS_END;i++) {
                if (counters[i] != 0) {
-                       printf("%s: %u\n", stats_message(i), counters[i]);
+                       int n = stats_message(i);
+                       if (n == -1) continue;
+                       printf("%s ", stats_messages[n].message);
+                       if (stats_messages[n].fn) {
+                               stats_messages[n].fn(counters[i]);
+                               printf("\n");
+                       } else {
+                               printf("%8u\n", counters[i]);
+                       }
                }
        }
 }
diff --git a/util.c b/util.c
index 008b89a8a74edee6b94bcf05c430077aeb13fbdc..7dee37020f58e3effa2cb420cfe0e4172d5641de 100644 (file)
--- a/util.c
+++ b/util.c
@@ -267,13 +267,25 @@ int safe_open(const char *fname)
        return fd;
 }
 
+/* display a kilobyte unsigned value in M, k or G */
+void display_size(unsigned v)
+{
+       if (v > 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;
 }