MCPcopy
hub / github.com/grpc/grpc-go / computeLatencies

Method computeLatencies

benchmark/stats/stats.go:411–446  ·  view source on GitHub ↗

computeLatencies computes percentile latencies based on durations stored in the stats object and updates the corresponding fields in the result object.

(result *BenchResults)

Source from the content-addressed store, hash-verified

409// computeLatencies computes percentile latencies based on durations stored in
410// the stats object and updates the corresponding fields in the result object.
411func (s *Stats) computeLatencies(result *BenchResults) {
412 if len(s.hw.durations) == 0 {
413 return
414 }
415 sort.Sort(s.hw.durations)
416 minDuration := int64(s.hw.durations[0])
417 maxDuration := int64(s.hw.durations[len(s.hw.durations)-1])
418
419 // Use the largest unit that can represent the minimum time duration.
420 s.hw.unit = time.Nanosecond
421 for _, u := range []time.Duration{time.Microsecond, time.Millisecond, time.Second} {
422 if minDuration <= int64(u) {
423 break
424 }
425 s.hw.unit = u
426 }
427
428 numBuckets := s.numBuckets
429 if n := int(maxDuration - minDuration + 1); n < numBuckets {
430 numBuckets = n
431 }
432 s.hw.histogram = NewHistogram(HistogramOptions{
433 NumBuckets: numBuckets,
434 // max-min(lower bound of last bucket) = (1 + growthFactor)^(numBuckets-2) * baseBucketSize.
435 GrowthFactor: math.Pow(float64(maxDuration-minDuration), 1/float64(numBuckets-2)) - 1,
436 BaseBucketSize: 1.0,
437 MinValue: minDuration,
438 })
439 for _, d := range s.hw.durations {
440 s.hw.histogram.Add(int64(d))
441 }
442 result.Data.Fiftieth = s.hw.durations[max(s.hw.histogram.Count*int64(50)/100-1, 0)]
443 result.Data.Ninetieth = s.hw.durations[max(s.hw.histogram.Count*int64(90)/100-1, 0)]
444 result.Data.NinetyNinth = s.hw.durations[max(s.hw.histogram.Count*int64(99)/100-1, 0)]
445 result.Data.Average = time.Duration(float64(s.hw.histogram.Sum) / float64(s.hw.histogram.Count))
446}
447
448// dump returns a printable version.
449func (s *Stats) dump(result *BenchResults) {

Callers 2

EndRunMethod · 0.95
EndUnconstrainedRunMethod · 0.95

Calls 2

NewHistogramFunction · 0.85
AddMethod · 0.65

Tested by

no test coverage detected