timehist.c File Reference

This file contains functions to make a histogram of time values. More...

#include "config.h"
#include <sys/time.h>
#include <sys/types.h>
#include "util/timehist.h"
#include "util/log.h"
#include "util/timeval_func.h"

Functions

static void timestwo (struct timeval *v)
 special timestwo operation for time values in histogram setup
 
static void dosetup (struct timehist *hist)
 do setup exponentially
 
struct timehisttimehist_setup (void)
 Setup a histogram, default. More...
 
void timehist_delete (struct timehist *hist)
 Delete histogram. More...
 
void timehist_clear (struct timehist *hist)
 Clear histogram. More...
 
void timehist_insert (struct timehist *hist, struct timeval *tv)
 Add time value to histogram. More...
 
void timehist_print (struct timehist *hist)
 Printout histogram. More...
 
void timehist_log (struct timehist *hist, const char *name)
 Log histogram, print it to the logfile. More...
 
static size_t timehist_count (struct timehist *hist)
 total number in histogram
 
double timehist_quartile (struct timehist *hist, double q)
 Find time value for given quartile, such as 0.25, 0.50, 0.75. More...
 
void timehist_export (struct timehist *hist, long long *array, size_t sz)
 Export histogram to an array. More...
 
void timehist_import (struct timehist *hist, long long *array, size_t sz)
 Import histogram from an array. More...
 

Detailed Description

This file contains functions to make a histogram of time values.

Function Documentation

◆ timehist_setup()

struct timehist* timehist_setup ( void  )

Setup a histogram, default.

Returns
histogram or NULL on malloc failure.

References timehist::buckets, dosetup(), timehist::num, and NUM_BUCKETS_HIST.

Referenced by mesh_create(), and print_hist().

◆ timehist_delete()

void timehist_delete ( struct timehist hist)

Delete histogram.

Parameters
histto delete

References timehist::buckets.

Referenced by mesh_delete(), and print_hist().

◆ timehist_clear()

void timehist_clear ( struct timehist hist)

Clear histogram.

Parameters
histto clear all data from

References timehist::buckets, th_buck::count, and timehist::num.

Referenced by mesh_stats_clear().

◆ timehist_insert()

void timehist_insert ( struct timehist hist,
struct timeval *  tv 
)

Add time value to histogram.

Parameters
histhistogram
tvtime value

References timehist::buckets, th_buck::count, timehist::num, timeval_smaller(), and th_buck::upper.

◆ timehist_print()

void timehist_print ( struct timehist hist)

Printout histogram.

Parameters
histhistogram

References timehist::buckets, th_buck::count, th_buck::lower, timehist::num, and th_buck::upper.

◆ timehist_log()

void timehist_log ( struct timehist hist,
const char *  name 
)

Log histogram, print it to the logfile.

Parameters
histhistogram
namethe name of the value column

References timehist::buckets, th_buck::count, log_info(), th_buck::lower, timehist::num, timehist_quartile(), and th_buck::upper.

◆ timehist_quartile()

double timehist_quartile ( struct timehist hist,
double  q 
)

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.

Parameters
histhistogram. Interpolated information is used from it.
qquartile, 0.50 results in the median. Must be >0 and <1.
Returns
: the time in seconds for that percentage.

References timehist::buckets, th_buck::count, th_buck::lower, timehist::num, timehist_count(), and th_buck::upper.

Referenced by server_stats_compile(), and timehist_log().

◆ timehist_export()

void timehist_export ( struct timehist hist,
long long *  array,
size_t  sz 
)

Export histogram to an array.

Parameters
histhistogram
arraythe array to export to.
sznumber of items in array.

References timehist::buckets, th_buck::count, and timehist::num.

Referenced by server_stats_compile().

◆ timehist_import()

void timehist_import ( struct timehist hist,
long long *  array,
size_t  sz 
)

Import histogram from an array.

Parameters
histhistogram
arraythe array to import from.
sznumber of items in array.

References timehist::buckets, th_buck::count, and timehist::num.

Referenced by print_hist().