hdrhist

package module
v0.0.0-...-dce39ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2017 License: MIT Imports: 16 Imported by: 5

README

hdrhist

GoDoc Widget Travis Widget Coverage Status Widget

Documentation

Overview

Package hdrhist provides high dynamic range (HDR) histograms.

HDR histograms can be used to accurately record and analyze distributions with very large ranges of data. This HDR histogram implementation is meant to have minimal memory usage and support recording values quickly. With a precision of 3 significant digits and a range of 1000-100 billion (e.g. 1 μs to 100 s), an HDR histogram consumes about 156 KB. Benchmarks show that recording a value in a histogram should take about 12 ns depending on the hardware.

A typical usecase for HDR Histograms would be recording latency values in client or server software.

This package is a Go port of Gil Tene's HdrHistogram Java package (http://hdrhistogram.github.io/HdrHistogram/). Package hdrhist aims to interoperate with HdrHistogram to the fullest extent possible.

Unless otherwise noted, none of the types in the package are safe for concurrent use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {

	// LowestDiscernible is the lowest, positive value
	// that can be discerned from 0.
	// This number may be rounded down to the nearest power of 2.
	LowestDiscernible int64

	// HighestTrackable is the largest value
	// that can be tracked by the histogram.
	// This must be at least twice the value of LowestDiscernible.
	HighestTrackable int64

	// SigFigs are the number of significant figures
	// that will be maintained by the histogram.
	// Must be ∈ [0,5].
	SigFigs int32

	// AutoResize will adjust HighestTrackable
	// and resize the histogram if necessary.
	// Note that resizing the histogram requires allocation
	// and will take longer than a typical operation.
	AutoResize bool
	// contains filtered or unexported fields
}

Config contains the options that can be used to configure a Hist.

type Hist

type Hist struct {
	// contains filtered or unexported fields
}

Hist maintains a distribution of values with a predetermined level of precision. A Hist can distinguish values with a predetermined range, or optionally resize to handle large values as they are provided.

func New

func New(sigfigs int32) *Hist

New creates a new Hist that auto-resizes and has a LowestDiscernible value of 1. Valid values for sigfigs are between 0 and 5.

func WithConfig

func WithConfig(cfg Config) *Hist

WithConfig creates a new Hist with the provided Config.

func (*Hist) Add

func (h *Hist) Add(o *Hist)

func (*Hist) AllVals

func (h *Hist) AllVals() []HistVal

func (*Hist) Clear

func (h *Hist) Clear()

Clear deletes all recorded values as well as the start and end times.

func (*Hist) Clone

func (h *Hist) Clone() *Hist

Clone returns a deep copy of the histogram. This is useful when combining or taking differences of histograms.

func (*Hist) Config

func (h *Hist) Config() Config

func (*Hist) EndTime

func (h *Hist) EndTime() (time.Time, bool)

func (*Hist) EstMemSize

func (h *Hist) EstMemSize() int

EstMemSize estimates the number of bytes being consumed by the histogram. The resulting size should not be assumed to be exact. The return value is in bytes.

func (*Hist) Init

func (h *Hist) Init(cfg Config)

Init initializes the Hist with the given Config.

func (*Hist) Max

func (h *Hist) Max() int64

func (*Hist) Mean

func (h *Hist) Mean() float64

func (*Hist) Min

func (h *Hist) Min() int64

func (*Hist) PercentileVal

func (h *Hist) PercentileVal(p float64) HistVal

PercentileVal returns the HistVal at the requested percentile p. p should be in the range [0, 100].

func (*Hist) Record

func (h *Hist) Record(v int64)

func (*Hist) RecordCorrected

func (h *Hist) RecordCorrected(v int64, expectedInterval int64)

func (*Hist) RecordN

func (h *Hist) RecordN(v, count int64)

func (*Hist) SetAutoResize

func (h *Hist) SetAutoResize(b bool)

func (*Hist) SetEndTime

func (h *Hist) SetEndTime(t time.Time)

func (*Hist) SetStartTime

func (h *Hist) SetStartTime(t time.Time)

func (*Hist) StartTime

func (h *Hist) StartTime() (time.Time, bool)

func (*Hist) Stdev

func (h *Hist) Stdev() float64

func (*Hist) Sub

func (h *Hist) Sub(o *Hist)

func (*Hist) TotalCount

func (h *Hist) TotalCount() int64

func (*Hist) Val

func (h *Hist) Val(v int64) HistVal

type HistVal

type HistVal struct {
	Value      int64
	Count      int64
	CumCount   int64
	Percentile float64
}

type LogReader

type LogReader struct {
	// contains filtered or unexported fields
}

LogReader reads hists from a log file.

LogReader currently provides no mechanism for extracting comments, or start times.

func NewLogReader

func NewLogReader(r io.Reader) *LogReader

func (*LogReader) Err

func (l *LogReader) Err() error

func (*LogReader) Hist

func (l *LogReader) Hist() *Hist

func (*LogReader) Scan

func (l *LogReader) Scan() bool

type LogWriter

type LogWriter struct {
	// contains filtered or unexported fields
}

A LogWriter writes Hist's to a log file.

· A log file may optionally have a start time.
· A log file may optionally have a base time,
  which will be used to reduce the space consumption of timestamps.
· A log file may have comments interleaved with histograms.

Typical usage of a LogWriter would be as follows:

now := time.Now()
lw := NewLogWriter(w)
lw.WriteStartTime(now)
lw.SetBaseTime(now)
lw.WriteLegend()

LogWriter is unfortunately difficult to use and was taken almost directly from the Java pacakge. This API should be revisited.

func NewLogWriter

func NewLogWriter(w io.Writer) *LogWriter

func (*LogWriter) GetBaseTime

func (l *LogWriter) GetBaseTime() (time.Time, bool)

func (*LogWriter) SetBaseTime

func (l *LogWriter) SetBaseTime(base time.Time)

func (*LogWriter) WriteBaseTime

func (l *LogWriter) WriteBaseTime(base time.Time) error

func (*LogWriter) WriteComment

func (l *LogWriter) WriteComment(text string) error

func (*LogWriter) WriteIntervalHist

func (l *LogWriter) WriteIntervalHist(h *Hist) error

func (*LogWriter) WriteLegend

func (l *LogWriter) WriteLegend() error

func (*LogWriter) WriteStartTime

func (l *LogWriter) WriteStartTime(start time.Time) error

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder provides a recording-only convenience API for snapshotting Hists.

func NewRecorder

func NewRecorder(sigfigs int32) *Recorder

func NewRecorderWithConfig

func NewRecorderWithConfig(cfg Config) *Recorder

func (*Recorder) Clear

func (r *Recorder) Clear()

func (*Recorder) Init

func (r *Recorder) Init(cfg Config)

func (*Recorder) IntervalHist

func (r *Recorder) IntervalHist(h *Hist) *Hist

func (*Recorder) Record

func (r *Recorder) Record(v int64)

func (*Recorder) RecordCorrected

func (r *Recorder) RecordCorrected(v int64, expectedInterval int64)

func (*Recorder) RecordN

func (r *Recorder) RecordN(v, count int64)

Directories

Path Synopsis
internal
bits
Package bits implements bit counting and manipulation functions for the predeclared unsigned integer types.
Package bits implements bit counting and manipulation functions for the predeclared unsigned integer types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL