func (h *histogram) average() float64 {
	t := h.total()
	if t == 0 {
		return 0
	}
	return float64(h.sum) / float64(t)
}
Average returns the average value of recorded observations.
package trace
import (
	"bytes"
	"fmt"
	"html/template"
	"log"
	"math"
	"sync"
	"golang.org/x/net/internal/timeseries"
)
const (
	bucketCount = 38
)
type histogram struct {
	sum          int64    
	sumOfSquares float64  
	buckets      []int64  
	value        int      
	valueCount   int64    
}
func (h *histogram) addMeasurement(value int64) {
	h.sum += value
	h.sumOfSquares += float64(value) * float64(value)
	bucketIndex := getBucket(value)
	if h.valueCount == 0 || (h.valueCount > 0 && h.value == bucketIndex) {
		h.value = bucketIndex
		h.valueCount++
	} else {
		h.allocateBuckets()
		h.buckets[bucketIndex]++
	}
}
func (h *histogram) allocateBuckets() {
	if h.buckets == nil {
		h.buckets = make([]int64, bucketCount)
		h.buckets[h.value] = h.valueCount
		h.value = 0
		h.valueCount = -1
	}
}
func log2(i int64) int {
	n := 0
	for ; i >= 0x100; i >>= 8 {
		n += 8
	}
	for ; i > 0; i >>= 1 {
		n += 1
	}
	return n
}
func getBucket(i int64) (index int) {
	index = log2(i) - 1
	if index < 0 {
		index = 0
	}
	if index >= bucketCount {
		index = bucketCount - 1
	}
	return
}
func (h *histogram) total() (total int64) {
	if h.valueCount >= 0 {
		total = h.valueCount
	}
	for _, val := range h.buckets {
		total += int64(val)
	}
	return
}