- {
- printf_filtered ("(not applicable)\n");
- }
- printf_filtered (" Space used for caching: %d\n", bcachep -> cache_bytes);
- printf_filtered (" Space saved by cache hits: %d\n", bcachep -> cache_savings);
- printf_filtered (" Number of bcache overflows: %d\n", bcachep -> bcache_overflows);
- printf_filtered (" Number of index buckets used: %d\n", tcount);
- printf_filtered (" Number of hash table buckets used: %d\n", hcount);
- printf_filtered (" Number of chained items: %d\n", lcount);
- printf_filtered (" Average hash table population: ");
- if (tcount > 0)
- {
- printf_filtered ("%d%%\n", (hcount * 100) / (tcount * BCACHE_HASHSIZE));
- }
+ printf_filtered ("%3d%%\n", (int) (portion * 100.0 / total));
+}
+
+
+/* Print statistics on BCACHE's memory usage and efficacity at
+ eliminating duplication. NAME should describe the kind of data
+ BCACHE holds. Statistics are printed using `printf_filtered' and
+ its ilk. */
+void
+print_bcache_statistics (struct bcache *c, char *type)
+{
+ int occupied_buckets;
+ int max_chain_length;
+ int median_chain_length;
+ int max_entry_size;
+ int median_entry_size;
+
+ /* Count the number of occupied buckets, tally the various string
+ lengths, and measure chain lengths. */
+ {
+ unsigned int b;
+ int *chain_length = XCALLOC (c->num_buckets + 1, int);
+ int *entry_size = XCALLOC (c->unique_count + 1, int);
+ int stringi = 0;
+
+ occupied_buckets = 0;
+
+ for (b = 0; b < c->num_buckets; b++)
+ {
+ struct bstring *s = c->bucket[b];
+
+ chain_length[b] = 0;
+
+ if (s)
+ {
+ occupied_buckets++;
+
+ while (s)
+ {
+ gdb_assert (b < c->num_buckets);
+ chain_length[b]++;
+ gdb_assert (stringi < c->unique_count);
+ entry_size[stringi++] = s->length;
+ s = s->next;
+ }
+ }
+ }
+
+ /* To compute the median, we need the set of chain lengths
+ sorted. */
+ qsort (chain_length, c->num_buckets, sizeof (chain_length[0]),
+ compare_positive_ints);
+ qsort (entry_size, c->unique_count, sizeof (entry_size[0]),
+ compare_positive_ints);
+
+ if (c->num_buckets > 0)
+ {
+ max_chain_length = chain_length[c->num_buckets - 1];
+ median_chain_length = chain_length[c->num_buckets / 2];
+ }
+ else
+ {
+ max_chain_length = 0;
+ median_chain_length = 0;
+ }
+ if (c->unique_count > 0)
+ {
+ max_entry_size = entry_size[c->unique_count - 1];
+ median_entry_size = entry_size[c->unique_count / 2];
+ }
+ else
+ {
+ max_entry_size = 0;
+ median_entry_size = 0;
+ }
+
+ xfree (chain_length);
+ xfree (entry_size);
+ }
+
+ printf_filtered (_(" Cached '%s' statistics:\n"), type);
+ printf_filtered (_(" Total object count: %ld\n"), c->total_count);
+ printf_filtered (_(" Unique object count: %lu\n"), c->unique_count);
+ printf_filtered (_(" Percentage of duplicates, by count: "));
+ print_percentage (c->total_count - c->unique_count, c->total_count);
+ printf_filtered ("\n");
+
+ printf_filtered (_(" Total object size: %ld\n"), c->total_size);
+ printf_filtered (_(" Unique object size: %ld\n"), c->unique_size);
+ printf_filtered (_(" Percentage of duplicates, by size: "));
+ print_percentage (c->total_size - c->unique_size, c->total_size);
+ printf_filtered ("\n");
+
+ printf_filtered (_(" Max entry size: %d\n"), max_entry_size);
+ printf_filtered (_(" Average entry size: "));
+ if (c->unique_count > 0)
+ printf_filtered ("%ld\n", c->unique_size / c->unique_count);