diff options
Diffstat (limited to 'runtime/map-stat.c')
-rw-r--r-- | runtime/map-stat.c | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/runtime/map-stat.c b/runtime/map-stat.c index 6634a2b7..dc3fd6ac 100644 --- a/runtime/map-stat.c +++ b/runtime/map-stat.c @@ -14,25 +14,19 @@ #include "stat-common.c" - static void _stp_map_print_histogram (MAP map, stat *sd) { _stp_stat_print_histogram (&map->hist, sd); } -static MAP _stp_map_new_hstat_log (unsigned max_entries, int key_size, int buckets) +static MAP _stp_map_new_hstat_log (unsigned max_entries, int key_size) { /* add size for buckets */ - int size = buckets * sizeof(int64_t) + sizeof(stat); + int size = HIST_LOG_BUCKETS * sizeof(int64_t) + sizeof(stat); MAP m = _stp_map_new (max_entries, STAT, key_size, size); if (m) { m->hist.type = HIST_LOG; - m->hist.buckets = buckets; - if (buckets < 1 || buckets > 64) { - _stp_warn("histogram: Bad number of buckets. Must be between 1 and 64\n"); - m->hist.type = HIST_NONE; - return m; - } + m->hist.buckets = HIST_LOG_BUCKETS; } return m; } @@ -41,12 +35,13 @@ static MAP _stp_map_new_hstat_linear (unsigned max_entries, int ksize, int start { MAP m; int size; - int buckets = (stop - start) / interval; - if ((stop - start) % interval) buckets++; - + int buckets = _stp_stat_calc_buckets(stop, start, interval); + if (!buckets) + return NULL; + /* add size for buckets */ size = buckets * sizeof(int64_t) + sizeof(stat); - + m = _stp_map_new (max_entries, STAT, ksize, size); if (m) { m->hist.type = HIST_LINEAR; @@ -54,12 +49,6 @@ static MAP _stp_map_new_hstat_linear (unsigned max_entries, int ksize, int start m->hist.stop = stop; m->hist.interval = interval; m->hist.buckets = buckets; - if (m->hist.buckets <= 0) { - _stp_warn("histogram: bad stop, start and/or interval\n"); - m->hist.type = HIST_NONE; - return m; - } - } return m; } @@ -68,8 +57,9 @@ static PMAP _stp_pmap_new_hstat_linear (unsigned max_entries, int ksize, int sta { PMAP pmap; int size; - int buckets = (stop - start) / interval; - if ((stop - start) % interval) buckets++; + int buckets = _stp_stat_calc_buckets(stop, start, interval); + if (!buckets) + return NULL; /* add size for buckets */ size = buckets * sizeof(int64_t) + sizeof(stat); @@ -97,10 +87,10 @@ static PMAP _stp_pmap_new_hstat_linear (unsigned max_entries, int ksize, int sta return pmap; } -static PMAP _stp_pmap_new_hstat_log (unsigned max_entries, int key_size, int buckets) +static PMAP _stp_pmap_new_hstat_log (unsigned max_entries, int key_size) { /* add size for buckets */ - int size = buckets * sizeof(int64_t) + sizeof(stat); + int size = HIST_LOG_BUCKETS * sizeof(int64_t) + sizeof(stat); PMAP pmap = _stp_pmap_new (max_entries, STAT, key_size, size); if (pmap) { int i; @@ -108,12 +98,12 @@ static PMAP _stp_pmap_new_hstat_log (unsigned max_entries, int key_size, int buc for_each_cpu(i) { m = (MAP)per_cpu_ptr (pmap->map, i); m->hist.type = HIST_LOG; - m->hist.buckets = buckets; + m->hist.buckets = HIST_LOG_BUCKETS; } /* now set agg map params */ m = &pmap->agg; m->hist.type = HIST_LOG; - m->hist.buckets = buckets; + m->hist.buckets = HIST_LOG_BUCKETS; } return pmap; } |