Skip to content

Commit

Permalink
Add percentiles to stats
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatas committed Sep 23, 2021
1 parent 77825fc commit 2561bb8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/query/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ func (s *statGroup) push(n float64) {

// string makes a simple description of a statGroup.
func (s *statGroup) string() string {
return fmt.Sprintf("min: %8.2fms, med: %8.2fms, mean: %8.2fms, max: %7.2fms, stddev: %8.2fms, sum: %5.1fsec, count: %d",
return fmt.Sprintf("min: %8.2fms, p25: %8.2fms, med: %8.2fms, p75: %8.2fms, p99: %8.2fms, mean: %8.2fms, max: %7.2fms, stddev: %8.2fms, sum: %5.1fsec, count: %d",
s.Min(),
s.Median(),
s.Percentile(25.0),
s.Mean(),
s.Percentile(75.0),
s.Percentile(99.0),
s.Max(),
s.StdDev(),
s.sum/hdrScaleFactor,
Expand All @@ -109,7 +112,7 @@ func (s *statGroup) write(w io.Writer) error {

// Median returns the Median value of the StatGroup in milliseconds
func (s *statGroup) Median() float64 {
return float64(s.latencyHDRHistogram.ValueAtQuantile(50.0)) / hdrScaleFactor
return s.Percentile(50.0)
}

// Mean returns the Mean value of the StatGroup in milliseconds
Expand All @@ -132,6 +135,11 @@ func (s *statGroup) StdDev() float64 {
return float64(s.latencyHDRHistogram.StdDev()) / hdrScaleFactor
}

// Extract Percentile from StatGroup in milliseconds
func (s *statGroup) Percentile(quantile float64) float64 {
return float64(s.latencyHDRHistogram.ValueAtQuantile(quantile)) / hdrScaleFactor
}

// writeStatGroupMap writes a map of StatGroups in an ordered fashion by
// key that they are stored by
func writeStatGroupMap(w io.Writer, statGroups map[string]*statGroup) error {
Expand Down

0 comments on commit 2561bb8

Please sign in to comment.