- Clarified cache size limit options' semantics
+ - Improved display of cache max size values.
+
Bug fixes:
- Fixed build on FreeBSD.
" -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"
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");
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);
-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
#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 },
{ 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)
{
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)));
+/* Format a size as a human-readable string. Caller frees. */
+char *format_size(size_t v)
+{
+ 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