]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
refactored StatHist::val
authorFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 6 Dec 2011 07:01:34 +0000 (08:01 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 6 Dec 2011 07:01:34 +0000 (08:01 +0100)
introduced all prototypes into header-file.

src/StatHist.cc
src/StatHist.h
src/stat.cc

index 33c255fb19a6c19911f34ee88feea3cd45b282d7..62d0027cecc866824be50d552caca432a95d35e0 100644 (file)
@@ -52,7 +52,6 @@
 /* Local functions */
 static void statHistInit(StatHist * H, int capacity, hbase_f * val_in, hbase_f * val_out, double min, double max);
 static int statHistBin(const StatHist * H, double v);
-static double statHistVal(const StatHist * H, int bin);
 static StatHistBinDumper statHistBinDumper;
 
 namespace Math
@@ -90,7 +89,7 @@ statHistInit(StatHist * H, int capacity, hbase_f * val_in, hbase_f * val_out, do
     /* a max value should go into the last bin */
     assert(statHistBin(H, max) == H->capacity - 1);
     /* it is hard to test val_out, here is a crude test */
-    assert(((int) floor(0.99 + statHistVal(H, 0) - min)) == 0);
+    assert(((int) floor(0.99 + H->val(0) - min)) == 0);
 }
 
 void
@@ -177,20 +176,20 @@ statHistBin(const StatHist * H, double v)
     return bin;
 }
 
-static double
-statHistVal(const StatHist * H, int bin)
+double
+StatHist::val(int bin) const
 {
-    return H->val_out((double) bin / H->scale) + H->min;
+    return val_out((double) bin / scale) + min;
 }
 
 double
 statHistDeltaMedian(const StatHist * A, const StatHist * B)
 {
-    return statHistDeltaPctile(A, B, 0.5);
+    return A->deltaPctile(*B, 0.5);
 }
 
 double
-statHistDeltaPctile(const StatHist * A, const StatHist * B, double pctile)
+StatHist::deltaPctile(const StatHist & B, double pctile) const
 {
     int i;
     int s1 = 0;
@@ -198,23 +197,25 @@ statHistDeltaPctile(const StatHist * A, const StatHist * B, double pctile)
     int a = 0;
     int b = 0;
     int I = 0;
-    int J = A->capacity;
+    int J = capacity;
     int K;
     double f;
-    int *D = (int *)xcalloc(A->capacity, sizeof(int));
-    assert(A->capacity == B->capacity);
 
-    for (i = 0; i < A->capacity; i++) {
-        D[i] = B->bins[i] - A->bins[i];
+    assert(capacity == B.capacity);
+
+    int *D = (int *)xcalloc(capacity, sizeof(int));
+
+    for (i = 0; i < capacity; ++i) {
+        D[i] = B.bins[i] - bins[i];
         assert(D[i] >= 0);
     }
 
-    for (i = 0; i < A->capacity; i++)
+    for (i = 0; i < capacity; ++i)
         s1 += D[i];
 
     h = int(s1 * pctile);
 
-    for (i = 0; i < A->capacity; i++) {
+    for (i = 0; i < capacity; ++i) {
         J = i;
         b += D[J];
 
@@ -244,7 +245,7 @@ statHistDeltaPctile(const StatHist * A, const StatHist * B, double pctile)
 
     K = (int) floor(f * (double) (J - I) + I);
 
-    return statHistVal(A, K);
+    return val(K);
 }
 
 static void
@@ -265,7 +266,7 @@ statHistDump(const StatHist * H, StoreEntry * sentry, StatHistBinDumper * bd)
         bd = statHistBinDumper;
 
     for (i = 0; i < H->capacity; i++) {
-        const double right_border = statHistVal(H, i + 1);
+        const double right_border = H->val(i + 1);
         assert(right_border - left_border > 0.0);
         bd(sentry, i, left_border, right_border - left_border, H->bins[i]);
         left_border = right_border;
index 7c41d39889d296f0b93509b3b5b8c8d19f551168..ca06db20228d11f5c91376be62ca6826210d2b59 100644 (file)
@@ -48,6 +48,18 @@ public:
     double scale;
     hbase_f *val_in;        /* e.g., log() for log-based histogram */
     hbase_f *val_out;       /* e.g., exp() for log based histogram */
+    double deltaPctile(const StatHist &B, double pctile) const;
+    double val(int bin) const; //todo: make private
+    void count(double val) const;
+    StatHist &operator=(const StatHist &);
+    StatHist();
+    StatHist(const StatHist&);
+    double deltaMedian(const StatHist &B, double pctile) const;
+    void dump(StoreEntry *sentry, StatHistBinDumper * bd);
+    void logInit(int capacity, double min, double max);
+    void enumInit(int last_enum);
+    void intInit(int n);
+private:
 };
 
 /* StatHist */
index 3768bc737167e6b2d1ff34b62031abbc5324a632..9feacb8d9a60db0d81ea0b29268d52d0317642f8 100644 (file)
@@ -1872,31 +1872,31 @@ statPctileSvc(double pctile, int interval, int which)
     switch (which) {
 
     case PCTILE_HTTP:
-        x = statHistDeltaPctile(&l->client_http.all_svc_time, &f->client_http.all_svc_time, pctile);
+        x = l->client_http.all_svc_time.deltaPctile(f->client_http.all_svc_time, pctile);
         break;
 
     case PCTILE_HIT:
-        x = statHistDeltaPctile(&l->client_http.hit_svc_time, &f->client_http.hit_svc_time, pctile);
+        x = l->client_http.hit_svc_time.deltaPctile(f->client_http.hit_svc_time, pctile);
         break;
 
     case PCTILE_MISS:
-        x = statHistDeltaPctile(&l->client_http.miss_svc_time, &f->client_http.miss_svc_time, pctile);
+        x = l->client_http.miss_svc_time.deltaPctile(f->client_http.miss_svc_time, pctile);
         break;
 
     case PCTILE_NM:
-        x = statHistDeltaPctile(&l->client_http.nm_svc_time, &f->client_http.nm_svc_time, pctile);
+        x = l->client_http.nm_svc_time.deltaPctile(f->client_http.nm_svc_time, pctile);
         break;
 
     case PCTILE_NH:
-        x = statHistDeltaPctile(&l->client_http.nh_svc_time, &f->client_http.nh_svc_time, pctile);
+        x = l->client_http.nh_svc_time.deltaPctile(f->client_http.nh_svc_time, pctile);
         break;
 
     case PCTILE_ICP_QUERY:
-        x = statHistDeltaPctile(&l->icp.query_svc_time, &f->icp.query_svc_time, pctile);
+        x = l->icp.query_svc_time.deltaPctile(f->icp.query_svc_time, pctile);
         break;
 
     case PCTILE_DNS:
-        x = statHistDeltaPctile(&l->dns.svc_time, &f->dns.svc_time, pctile);
+        x = l->dns.svc_time.deltaPctile(f->dns.svc_time, pctile);
         break;
 
     default: