From: Wouter Wijngaards Date: Thu, 10 Jan 2008 09:02:18 +0000 (+0000) Subject: quartile prints. X-Git-Tag: release-0.9~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1a3c9b646f1bec09ed648f4e1baf11088fb49fb;p=thirdparty%2Funbound.git quartile prints. git-svn-id: file:///svn/unbound/trunk@833 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index 89ea668ea..327464491 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -2,6 +2,9 @@ - fixup openssl RAND problem, when the system is not configured to give entropy, and the rng needs to be seeded. +8 January 2008: Wouter + - print median and quartiles with extensive logging. + 4 January 2008: Wouter - document misconfiguration in private network. diff --git a/util/timehist.c b/util/timehist.c index 6d9f95199..cad132a25 100644 --- a/util/timehist.c +++ b/util/timehist.c @@ -153,6 +153,10 @@ void timehist_log(struct timehist* hist) { #ifndef S_SPLINT_S size_t i; + log_info("[25%%]=%g median[50%%]=%g [75%%]=%g", + timehist_quartile(hist, 0.25), + timehist_quartile(hist, 0.50), + timehist_quartile(hist, 0.75)); /* 0000.000000 0000.000000 0 */ log_info("lower(secs) upper(secs) replycount"); for(i=0; inum; i++) { @@ -167,3 +171,40 @@ void timehist_log(struct timehist* hist) } #endif } + +/** total number in histogram */ +size_t +timehist_count(struct timehist* hist) +{ + size_t i, res = 0; + for(i=0; inum; i++) + res += hist->buckets[i].count; + return res; +} + +double +timehist_quartile(struct timehist* hist, double q) +{ + double lookfor, passed, res; + double low = 0, up = 0; + size_t i; + if(!hist || hist->num == 0) + return 0.; + /* look for i'th element, interpolated */ + lookfor = (double)timehist_count(hist) * q; + passed = 0; + i = 0; + while(i+1 < hist->num && + passed+(double)hist->buckets[i].count < lookfor) { + passed += (double)hist->buckets[i++].count; + } + /* got the right bucket */ +#ifndef S_SPLINT_S + low = (double)hist->buckets[i].lower.tv_sec + + (double)hist->buckets[i].lower.tv_usec/1000000.; + up = (double)hist->buckets[i].upper.tv_sec + + (double)hist->buckets[i].upper.tv_usec/1000000.; +#endif + res = (lookfor - passed)*(up-low)/((double)hist->buckets[i].count); + return res; +} diff --git a/util/timehist.h b/util/timehist.h index 3dbeb607f..0d8dfe592 100644 --- a/util/timehist.h +++ b/util/timehist.h @@ -83,6 +83,16 @@ void timehist_delete(struct timehist* hist); */ void timehist_insert(struct timehist* hist, struct timeval* tv); +/** + * Find time value for given quartile, such as 0.25, 0.50, 0.75. + * The looks up the value for the i-th element in the sorted list of time + * values, as approximated using the histogram. + * @param hist: histogram. Interpolated information is used from it. + * @param q: quartile, 0.50 results in the median. Must be >0 and <1. + * @return: the time in seconds for that percentage. + */ +double timehist_quartile(struct timehist* hist, double q); + /** * Printout histogram * @param hist: histogram