summaryrefslogtreecommitdiffstats
path: root/runtime/stat-common.c
diff options
context:
space:
mode:
authorgraydon <graydon>2005-11-29 01:06:47 +0000
committergraydon <graydon>2005-11-29 01:06:47 +0000
commita46369128cb3df3d729a0f6f8f300d99f4c3cff6 (patch)
tree460b8e6b28d101eb1c5fd27c7e577193b2c13122 /runtime/stat-common.c
parenta432e18a24569804c82f14b36ae7d8dfcc245da7 (diff)
downloadsystemtap-steved-a46369128cb3df3d729a0f6f8f300d99f4c3cff6.tar.gz
systemtap-steved-a46369128cb3df3d729a0f6f8f300d99f4c3cff6.tar.xz
systemtap-steved-a46369128cb3df3d729a0f6f8f300d99f4c3cff6.zip
[ChangeLog]
2005-11-28 Graydon Hoare <graydon@redhat.com> * translate.cxx (var::assert_hist_compatible): New method. (var::hist): New method. (c_unparser::load_aggregate): New method. (hist_op_downcaster): Remove, it was a mistake. (expression_is_hist_op): Likewise. (c_tmpcounter::visit_print_format): Implement print(@hist(...)). (c_unparser::visit_print_format): Likewise. * staptree.h (struct print_format): Add optional hist_op* member. * staptree.cxx (traversing_visitor::visit_functioncall): Visit hist_op if present in print_format. (deep_copy_visitor::visit_print_format): Likewise. * parse.cxx (parse_symbol): Special case to consume print(@hist(...)). * elaborate.cxx (typeresolution_info::visit_arrayindex): Fix type inference bug. (typeresolution_info::visit_foreach_loop): Likewise. * testsuite/buildok/print_histograms.stp: New test. [runtime/ChangeLog] 2005-11-28 Graydon Hoare <graydon@redhat.com> * stat-common.c (_stp_stat_print_histogram): Various formatting corrections and aesthetic tweaks. (__stp_stat_add): Correction to linear bucket underflow cases.
Diffstat (limited to 'runtime/stat-common.c')
-rw-r--r--runtime/stat-common.c67
1 files changed, 43 insertions, 24 deletions
diff --git a/runtime/stat-common.c b/runtime/stat-common.c
index aa30641e..94f1bdfa 100644
--- a/runtime/stat-common.c
+++ b/runtime/stat-common.c
@@ -98,17 +98,34 @@ static int msb64(int64_t val)
static void _stp_stat_print_histogram (Hist st, stat *sd)
{
- int scale, i, j, val_space, cnt_space;
+ int scale, i, j, val_space, cnt_space,
+ low_bucket = -1, high_bucket = 0;
int64_t val, v, max = 0;
if (st->type != HIST_LOG && st->type != HIST_LINEAR)
return;
-
- /* get the maximum value, for scaling */
- for (i = 0; i < st->buckets; i++)
+
+ /* Get the maximum value, for scaling. Also calculate the low
+ and high values to bound the reporting range. */
+ for (i = 0; i < st->buckets; i++) {
+ if (sd->histogram[i] > 0 && low_bucket == -1)
+ low_bucket = i;
+ if (sd->histogram[i] > 0)
+ high_bucket = i;
if (sd->histogram[i] > max)
max = sd->histogram[i];
-
+ }
+
+ /* Touch up the bucket margin to show up to two zero-slots on
+ either side of the data range, seems aesthetically pleasant. */
+ for (i = 0; i < 2; i++) {
+ if (low_bucket > 0)
+ low_bucket--;
+
+ if (high_bucket < (st->buckets-1))
+ high_bucket++;
+ }
+
if (max <= HIST_WIDTH)
scale = 1;
else {
@@ -120,9 +137,9 @@ static void _stp_stat_print_histogram (Hist st, stat *sd)
cnt_space = needed_space (max);
if (st->type == HIST_LINEAR)
- val_space = needed_space (st->start + st->interval * (st->buckets - 1));
+ val_space = needed_space (st->start + st->interval * high_bucket);
else
- val_space = needed_space (1 << (st->buckets - 1));
+ val_space = needed_space (((int64_t)1) << high_bucket);
//dbug ("max=%lld scale=%d val_space=%d\n", max, scale, val_space);
/* print header */
@@ -142,17 +159,19 @@ static void _stp_stat_print_histogram (Hist st, stat *sd)
else
val = 0;
for (i = 0; i < st->buckets; i++) {
- reprint (val_space - needed_space(val), " ");
- _stp_printf("%d", val);
- _stp_print_cstr (" |");
-
- /* v = s->histogram[i] / scale; */
- v = sd->histogram[i];
- do_div (v, scale);
+ if (i >= low_bucket && i <= high_bucket) {
+ reprint (val_space - needed_space(val), " ");
+ _stp_printf("%lld", val);
+ _stp_print_cstr (" |");
+
+ /* v = s->histogram[i] / scale; */
+ v = sd->histogram[i];
+ do_div (v, scale);
- reprint (v, "@");
- reprint (HIST_WIDTH - v + 1 + cnt_space - needed_space(sd->histogram[i]), " ");
- _stp_printf ("%lld\n", sd->histogram[i]);
+ reprint (v, "@");
+ reprint (HIST_WIDTH - v + 1 + cnt_space - needed_space(sd->histogram[i]), " ");
+ _stp_printf ("%lld\n", sd->histogram[i]);
+ }
if (st->type == HIST_LINEAR)
val += st->interval;
else if (val == 0)
@@ -217,14 +236,14 @@ static void __stp_stat_add (Hist st, stat *sd, int64_t val)
sd->histogram[n]++;
break;
case HIST_LINEAR:
- val -= st->start;
+ if (val < st->start)
+ val = st->start;
+ else
+ val -= st->start;
do_div (val, st->interval);
- n = val;
- if (n < 0)
- n = 0;
- if (n >= st->buckets)
- n = st->buckets - 1;
- sd->histogram[n]++;
+ if (val >= st->buckets)
+ val = st->buckets - 1;
+ sd->histogram[val]++;
default:
break;
}