unbound: util/timehist.c File Reference

unbound 0.1

Functions
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"`

## 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 timehist * | timehist_setup (void)
| Setup a histogram, default.
void | timehist_delete (struct timehist *hist)
| Delete histogram.
void | timehist_clear (struct timehist *hist)
| Clear histogram.
static int | timeval_smaller (const struct timeval *x, const struct timeval *y)
| histogram compare of time values
void | timehist_insert (struct timehist *hist, struct timeval *tv)
| Add time value to histogram.
void | timehist_print (struct timehist *hist)
| Printout histogram.
void | timehist_log (struct timehist *hist, const char *name)
| Log histogram, print it to the logfile.
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.
void | timehist_export (struct timehist *hist, long long *array, size_t sz)
| Export histogram to an array.
void | timehist_import (struct timehist *hist, long long *array, size_t sz)
| Import histogram from an array.

## 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

  hist | to delete

References timehist::buckets.

Referenced by mesh_delete(), and print_hist().

## ◆ timehist_clear()

void timehist_clear | ( | struct timehist * | hist | ) |

Clear histogram.

Parameters

  hist | to 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

  hist | histogram
  tv | time value

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

Referenced by mesh_send_reply().

## ◆ timehist_print()

void timehist_print | ( | struct timehist * | hist | ) |

Printout histogram.

Parameters

  hist | histogram

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

  hist | histogram
  name | the name of the value column

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

Referenced by mesh_stats().

## ◆ 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

  hist | histogram. Interpolated information is used from it.
  q | quartile, 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

  hist | histogram
  array | the array to export to.
  sz | number 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

  hist | histogram
  array | the array to import from.
  sz | number of items in array.

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

Referenced by print_hist().