mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 09:43:03 +00:00
style: modernize lib/bitset_stats.c
This commit is contained in:
@@ -108,18 +108,15 @@ static void
|
|||||||
bitset_percent_histogram_print (FILE *file, const char *name, const char *msg,
|
bitset_percent_histogram_print (FILE *file, const char *name, const char *msg,
|
||||||
unsigned n_bins, unsigned *bins)
|
unsigned n_bins, unsigned *bins)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned total = 0;
|
||||||
unsigned total;
|
for (unsigned i = 0; i < n_bins; i++)
|
||||||
|
|
||||||
total = 0;
|
|
||||||
for (i = 0; i < n_bins; i++)
|
|
||||||
total += bins[i];
|
total += bins[i];
|
||||||
|
|
||||||
if (!total)
|
if (!total)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fprintf (file, "%s %s", name, msg);
|
fprintf (file, "%s %s", name, msg);
|
||||||
for (i = 0; i < n_bins; i++)
|
for (unsigned i = 0; i < n_bins; i++)
|
||||||
fprintf (file, "%.0f-%.0f%%\t%8u (%5.1f%%)\n",
|
fprintf (file, "%.0f-%.0f%%\t%8u (%5.1f%%)\n",
|
||||||
i * 100.0 / n_bins,
|
i * 100.0 / n_bins,
|
||||||
(i + 1) * 100.0 / n_bins, bins[i],
|
(i + 1) * 100.0 / n_bins, bins[i],
|
||||||
@@ -132,26 +129,27 @@ static void
|
|||||||
bitset_log_histogram_print (FILE *file, const char *name, const char *msg,
|
bitset_log_histogram_print (FILE *file, const char *name, const char *msg,
|
||||||
unsigned n_bins, unsigned *bins)
|
unsigned n_bins, unsigned *bins)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned total = 0;
|
||||||
unsigned total;
|
for (unsigned i = 0; i < n_bins; i++)
|
||||||
unsigned max_width;
|
|
||||||
|
|
||||||
total = 0;
|
|
||||||
for (i = 0; i < n_bins; i++)
|
|
||||||
total += bins[i];
|
total += bins[i];
|
||||||
|
|
||||||
if (!total)
|
if (!total)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Determine number of useful bins. */
|
/* Determine number of useful bins. */
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
for (i = n_bins; i > 3 && ! bins[i - 1]; i--)
|
for (i = n_bins; i > 3 && ! bins[i - 1]; i--)
|
||||||
continue;
|
continue;
|
||||||
n_bins = i;
|
n_bins = i;
|
||||||
|
}
|
||||||
|
|
||||||
/* 2 * ceil (log10 (2) * (N - 1)) + 1. */
|
/* 2 * ceil (log10 (2) * (N - 1)) + 1. */
|
||||||
max_width = 2 * (unsigned) (0.30103 * (n_bins - 1) + 0.9999) + 1;
|
unsigned max_width = 2 * (unsigned) (0.30103 * (n_bins - 1) + 0.9999) + 1;
|
||||||
|
|
||||||
fprintf (file, "%s %s", name, msg);
|
fprintf (file, "%s %s", name, msg);
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
for (i = 0; i < 2; i++)
|
for (i = 0; i < 2; i++)
|
||||||
fprintf (file, "%*d\t%8u (%5.1f%%)\n",
|
fprintf (file, "%*d\t%8u (%5.1f%%)\n",
|
||||||
max_width, i, bins[i], 100.0 * bins[i] / total);
|
max_width, i, bins[i], 100.0 * bins[i] / total);
|
||||||
@@ -164,6 +162,7 @@ bitset_log_histogram_print (FILE *file, const char *name, const char *msg,
|
|||||||
bins[i],
|
bins[i],
|
||||||
(100.0 * bins[i]) / total);
|
(100.0 * bins[i]) / total);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Print bitset statistics to FILE. */
|
/* Print bitset statistics to FILE. */
|
||||||
@@ -205,8 +204,6 @@ bitset_stats_print_1 (FILE *file, const char *name,
|
|||||||
static void
|
static void
|
||||||
bitset_stats_print (FILE *file, bool verbose ATTRIBUTE_UNUSED)
|
bitset_stats_print (FILE *file, bool verbose ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!bitset_stats_info)
|
if (!bitset_stats_info)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -215,7 +212,7 @@ bitset_stats_print (FILE *file, bool verbose ATTRIBUTE_UNUSED)
|
|||||||
if (bitset_stats_info->runs > 1)
|
if (bitset_stats_info->runs > 1)
|
||||||
fprintf (file, _("Accumulated runs = %u\n"), bitset_stats_info->runs);
|
fprintf (file, _("Accumulated runs = %u\n"), bitset_stats_info->runs);
|
||||||
|
|
||||||
for (i = 0; i < BITSET_TYPE_NUM; i++)
|
for (int i = 0; i < BITSET_TYPE_NUM; i++)
|
||||||
bitset_stats_print_1 (file, bitset_type_names[i],
|
bitset_stats_print_1 (file, bitset_type_names[i],
|
||||||
&bitset_stats_info->types[i]);
|
&bitset_stats_info->types[i]);
|
||||||
}
|
}
|
||||||
@@ -242,15 +239,13 @@ bitset_stats_disable (void)
|
|||||||
void
|
void
|
||||||
bitset_stats_read (const char *file_name)
|
bitset_stats_read (const char *file_name)
|
||||||
{
|
{
|
||||||
FILE *file;
|
|
||||||
|
|
||||||
if (!bitset_stats_info)
|
if (!bitset_stats_info)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!file_name)
|
if (!file_name)
|
||||||
file_name = BITSET_STATS_FILE;
|
file_name = BITSET_STATS_FILE;
|
||||||
|
|
||||||
file = fopen (file_name, "r");
|
FILE *file = fopen (file_name, "r");
|
||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
if (fread (&bitset_stats_info_data, sizeof (bitset_stats_info_data),
|
if (fread (&bitset_stats_info_data, sizeof (bitset_stats_info_data),
|
||||||
@@ -272,15 +267,13 @@ bitset_stats_read (const char *file_name)
|
|||||||
void
|
void
|
||||||
bitset_stats_write (const char *file_name)
|
bitset_stats_write (const char *file_name)
|
||||||
{
|
{
|
||||||
FILE *file;
|
|
||||||
|
|
||||||
if (!bitset_stats_info)
|
if (!bitset_stats_info)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!file_name)
|
if (!file_name)
|
||||||
file_name = BITSET_STATS_FILE;
|
file_name = BITSET_STATS_FILE;
|
||||||
|
|
||||||
file = fopen (file_name, "w");
|
FILE *file = fopen (file_name, "w");
|
||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
if (fwrite (&bitset_stats_info_data, sizeof (bitset_stats_info_data),
|
if (fwrite (&bitset_stats_info_data, sizeof (bitset_stats_info_data),
|
||||||
@@ -573,15 +566,14 @@ static bitset_bindex
|
|||||||
bitset_stats_list (bitset bset, bitset_bindex *list,
|
bitset_stats_list (bitset bset, bitset_bindex *list,
|
||||||
bitset_bindex num, bitset_bindex *next)
|
bitset_bindex num, bitset_bindex *next)
|
||||||
{
|
{
|
||||||
bitset_bindex count;
|
bitset_bindex count = BITSET_LIST_ (bset->s.bset, list, num, next);
|
||||||
|
|
||||||
|
BITSET_STATS_LISTS_INC (bset->s.bset);
|
||||||
|
|
||||||
bitset_bindex tmp;
|
bitset_bindex tmp;
|
||||||
bitset_bindex size;
|
bitset_bindex size;
|
||||||
bitset_bindex i;
|
bitset_bindex i;
|
||||||
|
|
||||||
count = BITSET_LIST_ (bset->s.bset, list, num, next);
|
|
||||||
|
|
||||||
BITSET_STATS_LISTS_INC (bset->s.bset);
|
|
||||||
|
|
||||||
/* Log histogram of number of set bits. */
|
/* Log histogram of number of set bits. */
|
||||||
for (i = 0, tmp = count; tmp; tmp >>= 1, i++)
|
for (i = 0, tmp = count; tmp; tmp >>= 1, i++)
|
||||||
continue;
|
continue;
|
||||||
@@ -677,9 +669,6 @@ bitset_stats_bytes (void)
|
|||||||
bitset
|
bitset
|
||||||
bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type)
|
bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type)
|
||||||
{
|
{
|
||||||
size_t bytes;
|
|
||||||
bitset sbset;
|
|
||||||
|
|
||||||
bset->b.vtable = &bitset_stats_vtable;
|
bset->b.vtable = &bitset_stats_vtable;
|
||||||
|
|
||||||
/* Disable cache. */
|
/* Disable cache. */
|
||||||
@@ -691,6 +680,8 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type)
|
|||||||
|
|
||||||
/* Set up the actual bitset implementation that
|
/* Set up the actual bitset implementation that
|
||||||
we are a wrapper over. */
|
we are a wrapper over. */
|
||||||
|
size_t bytes;
|
||||||
|
bitset sbset;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user