-
-
-#if BITSET_STATS
-int
-bitset_list (bset, list, num, next)
- bitset bset;
- bitset_bindex *list;
- bitset_bindex num;
- bitset_bindex *next;
-{
- bitset_bindex count;
-
- count = BITSET_LIST_ (bset, list, num, next);
-
- if (bitset_stats)
- {
- bitset_bindex tmp;
- bitset_bindex size;
- bitset_bindex i;
- enum bitset_type type;
-
- type = BITSET_TYPE_ (bset);
- BITSET_STATS_LISTS_INC (bset);
-
- /* Log histogram of number of set bits. */
- for (i = 0, tmp = count; tmp; tmp >>= 1, i++)
- continue;
- if (i >= BITSET_LOG_COUNT_BINS)
- i = BITSET_LOG_COUNT_BINS - 1;
- BITSET_STATS_LIST_COUNTS_INC (bset, i);
-
- /* Log histogram of number of bits in set. */
- size = bitset_size (bset);
- for (i = 0, tmp = size; tmp; tmp >>= 1, i++)
- continue;
- if (i >= BITSET_LOG_SIZE_BINS)
- i = BITSET_LOG_SIZE_BINS - 1;
- BITSET_STATS_LIST_SIZES_INC (bset, i);
-
- /* Histogram of fraction of bits set. */
- i = size ? (count * BITSET_DENSITY_BINS) / size : 0;
- if (i >= BITSET_DENSITY_BINS)
- i = BITSET_DENSITY_BINS - 1;
- BITSET_STATS_LIST_DENSITY_INC (bset, i);
- }
- return count;
-}
-
-
-/* Print a percentage histogram with message MSG to FILE. */
-static void
-bitset_percent_histogram_print (file, name, msg, n_bins, bins)
- FILE *file;
- const char *name;
- const char *msg;
- unsigned int n_bins;
- unsigned int *bins;
-{
- unsigned int i;
- unsigned int total;
-
- total = 0;
- for (i = 0; i < n_bins; i++)
- total += bins[i];
-
- if (!total)
- return;
-
- fprintf (file, "%s %s", name, msg);
- for (i = 0; i < n_bins; i++)
- fprintf (file, "%.0f-%.0f%%\t%8d (%5.1f%%)\n",
- i * 100.0 / n_bins,
- (i + 1) * 100.0 / n_bins, bins[i],
- (100.0 * bins[i]) / total);
-}
-
-
-/* Print a log histogram with message MSG to FILE. */
-static void
-bitset_log_histogram_print (file, name, msg, n_bins, bins)
- FILE *file;
- const char *name;
- const char *msg;
- unsigned int n_bins;
- unsigned int *bins;
-{
- unsigned int i;
- unsigned int total;
- unsigned int max_width;
-
- total = 0;
- for (i = 0; i < n_bins; i++)
- total += bins[i];
-
- if (!total)
- return;
-
- /* 2 * ceil (log10(2) * (N - 1)) + 1 */
- max_width = 2 * (unsigned int) (0.30103 * (n_bins - 1) + 0.9999) + 1;
-
- fprintf (file, "%s %s", name, msg);
- for (i = 0; i < 2; i++)
- fprintf (file, "%*d\t%8d (%5.1f%%)\n",
- max_width, i, bins[i], 100.0 * bins[i] / total);
-
- /* Perhaps we should bail out once the histogram goes to zero. */
- for (; i < n_bins; i++)
- fprintf (file, "%*d-%d\t%8d (%5.1f%%)\n",
- max_width - ((unsigned int) (0.30103 * (i) + 0.9999) + 1),
- 1 << (i - 1), (1 << i) - 1, bins[i],
- (100.0 * bins[i]) / total);
-}
-
-
-/* Print bitset statistics to FILE. */
-static void
-bitset_stats_print_1 (file, name, stats)
- FILE *file;
- const char *name;
- struct bitset_type_stats_struct *stats;
-{
- if (!stats)
- return;
-
- fprintf (file, "%d %ss xmalloced, %d freed.\n",
- stats->xmallocs, name, stats->xfrees);
- fprintf (file, "%d %ss oballoced, %d freed.\n",
- stats->oballocs, name, stats->obfrees);
-
- fprintf (file, "%d bitset_lists\n", stats->lists);
-
- bitset_log_histogram_print (file, name, "count log histogram\n",
- BITSET_LOG_COUNT_BINS, stats->list_counts);
-
- bitset_log_histogram_print (file, name, "size log histogram\n",
- BITSET_LOG_SIZE_BINS, stats->list_sizes);
-
- bitset_percent_histogram_print (file, name, "density histogram\n",
- BITSET_DENSITY_BINS, stats->list_density);
-}
-
-
-/* Print all bitset statistics to FILE. */
-static void
-bitset_stats_print (file, verbose)
- FILE *file;
- int verbose ATTRIBUTE_UNUSED;
-{
- int i;
- static const char *names[] = BITSET_TYPE_NAMES;
-
- if (!bitset_stats)
- return;
-
- fprintf (file, "Bitset statistics:\n\n");
-
- if (bitset_stats->runs > 1)
- fprintf (file, "Accumulated runs = %d\n", bitset_stats->runs);
-
- for (i = 0; i < BITSET_TYPE_NUM; i++)
- bitset_stats_print_1 (file, names[i], &bitset_stats->types[i]);
-}
-#endif /* BITSET_STATS */
-
-
-/* Initialise bitset statistics logging. */
-void
-bitset_stats_init ()
-{
-#if BITSET_STATS
- bitset_stats = &bitset_stats_data;
- bitset_stats_read ();
-#endif /* BITSET_STATS */
-}
-
-
-/* Read bitset statistics file. */
-static void
-bitset_stats_read ()
-{
- FILE *file;
-
- if (!bitset_stats)
- return;
-
- file = fopen (BITSET_STATS_FILE, "r");
- if (file)
- {
- if (fread (&bitset_stats_data, sizeof (bitset_stats_data),
- 1, file) != 1)
- {
- if (ferror (file))
- perror ("Could not read stats file.");
- else
- fprintf (stderr, "Bad stats file size.\n");
- }
- fclose (file);
- }
- bitset_stats_data.runs++;
-}
-
-
-/* Write bitset statistics file. */
-static void
-bitset_stats_write ()
-{
- FILE *file;
-
- if (!bitset_stats)
- return;
-
- file = fopen (BITSET_STATS_FILE, "w");
- if (file)
- {
- if (fwrite (&bitset_stats_data, sizeof (bitset_stats_data),
- 1, file) != 1)
- perror ("Could not write stats file.");
- fclose (file);
- }
- else
- perror ("Could not open stats file for writing.");
-}
-
-
-/* Dump bitset statistics to FILE. */
-void
-bitset_stats_dump (file)
- FILE *file;
-{
-#if BITSET_STATS
- bitset_stats_print (file, 0);
- bitset_stats_write ();
-#endif /* BITSET_STATS */
-}
-
-
-/* Function to be called from debugger to print bitset stats. */
-void
-debug_bitset_stats (void)
-{
-#if BITSET_STATS
- bitset_stats_print (stderr, 1);
-#endif /* BITSET_STATS */
-}