Ejemplo n.º 1
0
// summarize returns a Summary of the last benchmark run.
func (c *connectionBenchmark) summarize() *Summary {
	return &Summary{
		SuccessTotal:                c.successTotal,
		ErrorTotal:                  c.errorTotal,
		TimeElapsed:                 c.elapsed,
		SuccessHistogram:            hdrhistogram.Import(c.successHistogram.Export()),
		UncorrectedSuccessHistogram: hdrhistogram.Import(c.uncorrectedSuccessHistogram.Export()),
		ErrorHistogram:              hdrhistogram.Import(c.errorHistogram.Export()),
		UncorrectedErrorHistogram:   hdrhistogram.Import(c.uncorrectedErrorHistogram.Export()),
		Throughput:                  float64(c.successTotal+c.errorTotal) / c.elapsed.Seconds(),
		RequestRate:                 c.requestRate,
	}
}
Ejemplo n.º 2
0
func TestExportImport(t *testing.T) {
	min := int64(1)
	max := int64(10000000)
	sigfigs := 3
	h := hdrhistogram.New(min, max, sigfigs)
	for i := 0; i < 1000000; i++ {
		if err := h.RecordValue(int64(i)); err != nil {
			t.Fatal(err)
		}
	}

	s := h.Export()

	if v := s.LowestTrackableValue; v != min {
		t.Errorf("LowestTrackableValue was %v, but expected %v", v, min)
	}

	if v := s.HighestTrackableValue; v != max {
		t.Errorf("HighestTrackableValue was %v, but expected %v", v, max)
	}

	if v := int(s.SignificantFigures); v != sigfigs {
		t.Errorf("SignificantFigures was %v, but expected %v", v, sigfigs)
	}

	if imported := hdrhistogram.Import(s); !imported.Equals(h) {
		t.Error("Expected Histograms to be equivalent")
	}

}
Ejemplo n.º 3
0
// Current returns a copy of the data currently in the window.
func (h *Histogram) Current() *hdrhistogram.Histogram {
	h.mu.Lock()
	maybeTick(h)
	export := h.windowed.Merge().Export()
	h.mu.Unlock()
	return hdrhistogram.Import(export)
}
Ejemplo n.º 4
0
func (self *HdrHistogramLogReader) NextHistogram() (*hdrhistogram.Histogram, error) {
	var snapshot *hdrhistogram.Snapshot
	err := binary.Read(self.r, binary.LittleEndian, snapshot)
	if err != nil {
		return nil, err
	}
	h := hdrhistogram.Import(snapshot)
	return h, nil
}
Ejemplo n.º 5
0
// Current returns a copy of the data currently in the window.
func (h *Histogram) Current() *hdrhistogram.Histogram {
	h.mu.Lock()
	maybeTick(h)
	export := h.windowed.Merge().Export()
	// Make a deep copy of export.Counts, because (*hdrhistogram.Histogram).Export() does
	// a shallow copy of the histogram counts, which leads to data races when multiple goroutines
	// call this method.
	// TODO(cdo): Remove this when I've gotten a chance to submit a PR for the proper fix
	// to hdrhistogram.
	export.Counts = append([]int64(nil), export.Counts...)
	h.mu.Unlock()
	return hdrhistogram.Import(export)
}
Ejemplo n.º 6
0
func cloneHistogram(in *hdrhistogram.Histogram) *hdrhistogram.Histogram {
	return hdrhistogram.Import(in.Export())
}