github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/metrics/histogram.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  package metrics
    10  
    11  //柱状图根据一系列Int64值计算分布统计信息。
    12  type Histogram interface {
    13  	Clear()
    14  	Count() int64
    15  	Max() int64
    16  	Mean() float64
    17  	Min() int64
    18  	Percentile(float64) float64
    19  	Percentiles([]float64) []float64
    20  	Sample() Sample
    21  	Snapshot() Histogram
    22  	StdDev() float64
    23  	Sum() int64
    24  	Update(int64)
    25  	Variance() float64
    26  }
    27  
    28  //GetOrRegisterHistogram返回现有的柱状图或构造,以及
    29  //注册新的标准柱状图。
    30  func GetOrRegisterHistogram(name string, r Registry, s Sample) Histogram {
    31  	if nil == r {
    32  		r = DefaultRegistry
    33  	}
    34  	return r.GetOrRegister(name, func() Histogram { return NewHistogram(s) }).(Histogram)
    35  }
    36  
    37  //NewHistogram从一个样本构造一个新的标准柱状图。
    38  func NewHistogram(s Sample) Histogram {
    39  	if !Enabled {
    40  		return NilHistogram{}
    41  	}
    42  	return &StandardHistogram{sample: s}
    43  }
    44  
    45  //NewRegisteredHistogram构造并注册来自
    46  //样品。
    47  func NewRegisteredHistogram(name string, r Registry, s Sample) Histogram {
    48  	c := NewHistogram(s)
    49  	if nil == r {
    50  		r = DefaultRegistry
    51  	}
    52  	r.Register(name, c)
    53  	return c
    54  }
    55  
    56  //HistogramSnapshot是另一个柱状图的只读副本。
    57  type HistogramSnapshot struct {
    58  	sample *SampleSnapshot
    59  }
    60  
    61  //清晰的恐慌。
    62  func (*HistogramSnapshot) Clear() {
    63  	panic("Clear called on a HistogramSnapshot")
    64  }
    65  
    66  //count返回快照时记录的样本数
    67  //拿。
    68  func (h *HistogramSnapshot) Count() int64 { return h.sample.Count() }
    69  
    70  //max返回快照时样本中的最大值。
    71  //拿。
    72  func (h *HistogramSnapshot) Max() int64 { return h.sample.Max() }
    73  
    74  //mean返回快照时样本中值的平均值
    75  //被带走了。
    76  func (h *HistogramSnapshot) Mean() float64 { return h.sample.Mean() }
    77  
    78  //Min返回快照时样本中的最小值
    79  //拿。
    80  func (h *HistogramSnapshot) Min() int64 { return h.sample.Min() }
    81  
    82  //Percentile返回在
    83  //拍摄快照的时间。
    84  func (h *HistogramSnapshot) Percentile(p float64) float64 {
    85  	return h.sample.Percentile(p)
    86  }
    87  
    88  //Percentiles返回样本中任意百分位值的切片
    89  //拍摄快照时。
    90  func (h *HistogramSnapshot) Percentiles(ps []float64) []float64 {
    91  	return h.sample.Percentiles(ps)
    92  }
    93  
    94  //sample返回柱状图下的样本。
    95  func (h *HistogramSnapshot) Sample() Sample { return h.sample }
    96  
    97  //快照返回快照。
    98  func (h *HistogramSnapshot) Snapshot() Histogram { return h }
    99  
   100  //stdev返回在
   101  //拍摄快照的时间。
   102  func (h *HistogramSnapshot) StdDev() float64 { return h.sample.StdDev() }
   103  
   104  //sum返回快照拍摄时样本中的总和。
   105  func (h *HistogramSnapshot) Sum() int64 { return h.sample.Sum() }
   106  
   107  //更新恐慌。
   108  func (*HistogramSnapshot) Update(int64) {
   109  	panic("Update called on a HistogramSnapshot")
   110  }
   111  
   112  //variance返回拍摄快照时输入的方差。
   113  func (h *HistogramSnapshot) Variance() float64 { return h.sample.Variance() }
   114  
   115  //nilHistogram是一个无操作的柱状图。
   116  type NilHistogram struct{}
   117  
   118  //清除是不可操作的。
   119  func (NilHistogram) Clear() {}
   120  
   121  //计数是不允许的。
   122  func (NilHistogram) Count() int64 { return 0 }
   123  
   124  //马克斯不是一个OP。
   125  func (NilHistogram) Max() int64 { return 0 }
   126  
   127  //平均值是不允许的。
   128  func (NilHistogram) Mean() float64 { return 0.0 }
   129  
   130  //min是NO-OP。
   131  func (NilHistogram) Min() int64 { return 0 }
   132  
   133  //百分位数是不允许的。
   134  func (NilHistogram) Percentile(p float64) float64 { return 0.0 }
   135  
   136  //百分位数是不允许的。
   137  func (NilHistogram) Percentiles(ps []float64) []float64 {
   138  	return make([]float64, len(ps))
   139  }
   140  
   141  //样本是不可操作的。
   142  func (NilHistogram) Sample() Sample { return NilSample{} }
   143  
   144  //快照是不可操作的。
   145  func (NilHistogram) Snapshot() Histogram { return NilHistogram{} }
   146  
   147  //stdev是一个no-op。
   148  func (NilHistogram) StdDev() float64 { return 0.0 }
   149  
   150  //和是一个NO-op.
   151  func (NilHistogram) Sum() int64 { return 0 }
   152  
   153  //更新是不可操作的。
   154  func (NilHistogram) Update(v int64) {}
   155  
   156  //方差是不可操作的。
   157  func (NilHistogram) Variance() float64 { return 0.0 }
   158  
   159  //标准柱状图是柱状图的标准实现,使用
   160  //用于绑定其内存使用的示例。
   161  type StandardHistogram struct {
   162  	sample Sample
   163  }
   164  
   165  //清除清除柱状图及其样本。
   166  func (h *StandardHistogram) Clear() { h.sample.Clear() }
   167  
   168  //count返回自上次直方图以来记录的样本数
   169  //变明朗。
   170  func (h *StandardHistogram) Count() int64 { return h.sample.Count() }
   171  
   172  //max返回样本中的最大值。
   173  func (h *StandardHistogram) Max() int64 { return h.sample.Max() }
   174  
   175  //mean返回样本值的平均值。
   176  func (h *StandardHistogram) Mean() float64 { return h.sample.Mean() }
   177  
   178  //Min返回样本中的最小值。
   179  func (h *StandardHistogram) Min() int64 { return h.sample.Min() }
   180  
   181  //Percentile返回样本中任意百分位数的值。
   182  func (h *StandardHistogram) Percentile(p float64) float64 {
   183  	return h.sample.Percentile(p)
   184  }
   185  
   186  //Percentiles返回
   187  //样品。
   188  func (h *StandardHistogram) Percentiles(ps []float64) []float64 {
   189  	return h.sample.Percentiles(ps)
   190  }
   191  
   192  //sample返回柱状图下的样本。
   193  func (h *StandardHistogram) Sample() Sample { return h.sample }
   194  
   195  //快照返回柱状图的只读副本。
   196  func (h *StandardHistogram) Snapshot() Histogram {
   197  	return &HistogramSnapshot{sample: h.sample.Snapshot().(*SampleSnapshot)}
   198  }
   199  
   200  //stdev返回样本值的标准偏差。
   201  func (h *StandardHistogram) StdDev() float64 { return h.sample.StdDev() }
   202  
   203  //sum返回样本中的和。
   204  func (h *StandardHistogram) Sum() int64 { return h.sample.Sum() }
   205  
   206  //更新示例新值。
   207  func (h *StandardHistogram) Update(v int64) { h.sample.Update(v) }
   208  
   209  //方差返回样本中值的方差。
   210  func (h *StandardHistogram) Variance() float64 { return h.sample.Variance() }