From 7d291bee3622b18c16d53a359a230306b67203f9 Mon Sep 17 00:00:00 2001 From: hunt Date: Fri, 6 Jul 2007 18:42:00 +0000 Subject: [PATCH] 2007-07-06 Martin Hunt * stat-common.c (__stp_stat_add): Fix calculations for linear histogram buckets. * stat.c (_stp_stat_init): Check for interval too small. --- runtime/ChangeLog | 8 ++++++++ runtime/stat-common.c | 7 +++---- runtime/stat.c | 9 ++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 4f4e55243..4be3350b6 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,11 @@ +2007-07-06 Martin Hunt + + * stat-common.c (__stp_stat_add): Fix calculations + for linear histogram buckets. + + * stat.c (_stp_stat_init): Check for interval too + small. + 2007-07-05 Eugene Teo * regs.c (_stp_print_regs): #ifdef CONFIG_CPU_CP15 instead. diff --git a/runtime/stat-common.c b/runtime/stat-common.c index 48f8218a8..9ca045c9a 100644 --- a/runtime/stat-common.c +++ b/runtime/stat-common.c @@ -237,10 +237,9 @@ static void __stp_stat_add (Hist st, stat *sd, int64_t val) sd->histogram[n]++; break; case HIST_LINEAR: - if (val < st->start) - val = st->start; - else - val -= st->start; + val -= st->start; + if (val < 0) + val = 0; do_div (val, st->interval); if (val >= st->buckets) val = st->buckets - 1; diff --git a/runtime/stat.c b/runtime/stat.c index cf224e5ea..f4e205aa7 100644 --- a/runtime/stat.c +++ b/runtime/stat.c @@ -90,9 +90,16 @@ Stat _stp_stat_init (int type, ...) start = va_arg(ap, int); stop = va_arg(ap, int); interval = va_arg(ap, int); - /* FIXME. check interval != 0 and not too large */ + if (interval == 0) { + _stp_warn("histogram: interval cannot be zero.\n"); + return NULL; + } buckets = (stop - start) / interval; if ((stop - start) % interval) buckets++; + if (buckets > 128) { + _stp_warn("histogram: Interval is too small. Maximum buckets is 128.\n"); + return NULL; + } } va_end (ap); } -- 2.43.5