mirror of
https://github.com/reactos/ccache.git
synced 2024-12-02 16:46:24 +00:00
Improve display of max size display values
This commit is contained in:
parent
d4d8843588
commit
2b2f5ddcd8
2
NEWS
2
NEWS
@ -57,6 +57,8 @@ New features and improvements:
|
||||
|
||||
- Clarified cache size limit options' semantics
|
||||
|
||||
- Improved display of cache max size values.
|
||||
|
||||
Bug fixes:
|
||||
|
||||
- Fixed build on FreeBSD.
|
||||
|
8
ccache.c
8
ccache.c
@ -61,7 +61,8 @@ static const char USAGE_TEXT[] =
|
||||
" -F, --max-files=N set maximum number of files in cache to N (use 0 for\n"
|
||||
" no limit)\n"
|
||||
" -M, --max-size=SIZE set maximum size of cache to SIZE (use 0 for no\n"
|
||||
" limit; available suffixes: G, M and K)\n"
|
||||
" limit; available suffixes: G, M and K; default\n"
|
||||
" suffix: G)\n"
|
||||
" -s, --show-stats show statistics summary\n"
|
||||
" -z, --zero-stats zero statistics counters\n"
|
||||
"\n"
|
||||
@ -1736,7 +1737,10 @@ static int ccache_main(int argc, char *argv[])
|
||||
if (v == 0) {
|
||||
printf("Unset cache size limit\n");
|
||||
} else {
|
||||
printf("Set cache size limit to %uk\n", (unsigned)v);
|
||||
char *s = format_size(v);
|
||||
printf("Set cache size limit to %s\n",
|
||||
s);
|
||||
free(s);
|
||||
}
|
||||
} else {
|
||||
printf("Could not set cache size limit.\n");
|
||||
|
2
ccache.h
2
ccache.h
@ -102,7 +102,7 @@ void stats_tocache(size_t size);
|
||||
void stats_read(const char *stats_file, unsigned counters[STATS_END]);
|
||||
int stats_set_limits(long maxfiles, long maxsize);
|
||||
size_t value_units(const char *s);
|
||||
void display_size(unsigned v);
|
||||
char *format_size(size_t v);
|
||||
void stats_set_sizes(const char *dir, size_t num_files, size_t total_size);
|
||||
|
||||
int unify_hash(struct mdfour *hash, const char *fname);
|
||||
|
@ -25,7 +25,8 @@ verb(
|
||||
-F, --max-files=N set maximum number of files in cache to N (use 0 for
|
||||
no limit)
|
||||
-M, --max-size=SIZE set maximum size of cache to SIZE (use 0 for no
|
||||
limit; available suffixes: G, M and K)
|
||||
limit; available suffixes: G, M and K; default
|
||||
suffix: G)
|
||||
-s, --show-stats show statistics summary
|
||||
-z, --zero-stats zero statistics counters
|
||||
|
||||
|
11
stats.c
11
stats.c
@ -41,11 +41,13 @@ extern char *cache_dir;
|
||||
#define FLAG_NOZERO 1 /* don't zero with the -z option */
|
||||
#define FLAG_ALWAYS 2 /* always show, even if zero */
|
||||
|
||||
static void display_size(size_t v);
|
||||
|
||||
/* statistics fields in display order */
|
||||
static struct {
|
||||
enum stats stat;
|
||||
char *message;
|
||||
void (*fn)(unsigned );
|
||||
void (*fn)(size_t );
|
||||
unsigned flags;
|
||||
} stats_info[] = {
|
||||
{ STATS_CACHEHIT_DIR, "cache hit (direct) ", NULL, FLAG_ALWAYS },
|
||||
@ -75,6 +77,13 @@ static struct {
|
||||
{ STATS_NONE, NULL, NULL, 0 }
|
||||
};
|
||||
|
||||
static void display_size(size_t v)
|
||||
{
|
||||
char *s = format_size(v);
|
||||
printf("%15s", s);
|
||||
free(s);
|
||||
}
|
||||
|
||||
/* parse a stats file from a buffer - adding to the counters */
|
||||
static void parse_stats(unsigned counters[STATS_END], char *buf)
|
||||
{
|
||||
|
16
util.c
16
util.c
@ -547,16 +547,18 @@ int safe_open(const char *fname)
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* display a kilobyte unsigned value in M, k or G */
|
||||
void display_size(unsigned v)
|
||||
/* Format a size as a human-readable string. Caller frees. */
|
||||
char *format_size(size_t v)
|
||||
{
|
||||
if (v > 1024*1024) {
|
||||
printf("%8.1f Gbytes", v/((double)(1024*1024)));
|
||||
} else if (v > 1024) {
|
||||
printf("%8.1f Mbytes", v/((double)(1024)));
|
||||
char *s;
|
||||
if (v >= 1024*1024) {
|
||||
x_asprintf(&s, "%.1f Gbytes", v/((double)(1024*1024)));
|
||||
} else if (v >= 1024) {
|
||||
x_asprintf(&s, "%.1f Mbytes", v/((double)(1024)));
|
||||
} else {
|
||||
printf("%8u Kbytes", v);
|
||||
x_asprintf(&s, "%.0f Kbytes", (double)v);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/* return a value in multiples of 1024 give a string that can end
|
||||
|
Loading…
Reference in New Issue
Block a user