add percentile handling to histogram
This commit is contained in:
parent
aaafca31b6
commit
22802f72c3
2 changed files with 22 additions and 2 deletions
|
@ -113,6 +113,26 @@ static inline void stasis_histogram_pretty_print_64(stasis_histogram_64_t* a);
|
|||
static inline void stasis_histogram_pretty_print_32(stasis_histogram_32_t* a);
|
||||
void stasis_histograms_auto_dump(void);
|
||||
|
||||
double stasis_histogram_nth_percentile_64(stasis_histogram_64_t* a, int pctile) {
|
||||
long sum = 0;
|
||||
for(int i = 0; i < 64; i++) {
|
||||
sum += a->buckets[i];
|
||||
}
|
||||
sum *= pctile;
|
||||
sum /= 100;
|
||||
long newsum = 0;
|
||||
int i;
|
||||
for(i = 0; i < 64; i++) {
|
||||
newsum += a->buckets[i];
|
||||
if(newsum >= sum) { break; }
|
||||
}
|
||||
long ret = 1;
|
||||
for(int j = 0; j < i; j++) {
|
||||
ret *= 2;
|
||||
}
|
||||
return ((double)ret)/1000000.0;
|
||||
}
|
||||
|
||||
void stasis_histogram_pretty_print_64(stasis_histogram_64_t* a) {
|
||||
uint8_t logs[64];
|
||||
int max_log = 0;
|
||||
|
|
|
@ -32,7 +32,7 @@ static inline struct timespec stasis_double_to_timespec(double a) {
|
|||
ts.tv_nsec = (long int)((a - (double)ts.tv_sec) * 1000000000.0);
|
||||
return ts;
|
||||
}
|
||||
static uint8_t stasis_log_2_timeval(const struct timeval a) {
|
||||
return stasis_log_2_64(a.tv_sec * 1000000 + a.tv_usec);
|
||||
static inline uint8_t stasis_log_2_timeval(const struct timeval a) {
|
||||
return stasis_log_2_64((a.tv_sec * 1000000 + a.tv_usec));
|
||||
}
|
||||
#endif /* TIME_H_ */
|
||||
|
|
Loading…
Reference in a new issue