]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
quartile prints.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 10 Jan 2008 09:02:18 +0000 (09:02 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 10 Jan 2008 09:02:18 +0000 (09:02 +0000)
git-svn-id: file:///svn/unbound/trunk@833 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
util/timehist.c
util/timehist.h

index 89ea668ea90910138fd73579ed68a4bd8e2082de..327464491836e2c4355d53f2c302a943427e8007 100644 (file)
@@ -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.
 
index 6d9f95199335068b6faa65f59c487f3bd9f51493..cad132a257a757b0fd1beb0379ccd3e2bf004e13 100644 (file)
@@ -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; i<hist->num; 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; i<hist->num; 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;
+}
index 3dbeb607f2a08b1a9eb1515f9dd2bc8749d1ce7b..0d8dfe592d4eb466e02b330d55671e581191e745 100644 (file)
@@ -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