1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
8 "golang.org/x/tools/internal/event/keys"
9 "golang.org/x/tools/internal/event/label"
12 // Scalar represents the construction information for a scalar metric.
14 // Name is the unique name of this metric.
16 // Description can be used by observers to describe the metric to users.
18 // Keys is the set of labels that collectively describe rows of the metric.
22 // HistogramInt64 represents the construction information for an int64 histogram metric.
23 type HistogramInt64 struct {
24 // Name is the unique name of this metric.
26 // Description can be used by observers to describe the metric to users.
28 // Keys is the set of labels that collectively describe rows of the metric.
30 // Buckets holds the inclusive upper bound of each bucket in the histogram.
34 // HistogramFloat64 represents the construction information for an float64 histogram metric.
35 type HistogramFloat64 struct {
36 // Name is the unique name of this metric.
38 // Description can be used by observers to describe the metric to users.
40 // Keys is the set of labels that collectively describe rows of the metric.
42 // Buckets holds the inclusive upper bound of each bucket in the histogram.
46 // Count creates a new metric based on the Scalar information that counts
47 // the number of times the supplied int64 measure is set.
48 // Metrics of this type will use Int64Data.
49 func (info Scalar) Count(e *Config, key label.Key) {
50 data := &Int64Data{Info: &info, key: nil}
51 e.subscribe(key, data.count)
54 // SumInt64 creates a new metric based on the Scalar information that sums all
55 // the values recorded on the int64 measure.
56 // Metrics of this type will use Int64Data.
57 func (info Scalar) SumInt64(e *Config, key *keys.Int64) {
58 data := &Int64Data{Info: &info, key: key}
59 e.subscribe(key, data.sum)
62 // LatestInt64 creates a new metric based on the Scalar information that tracks
63 // the most recent value recorded on the int64 measure.
64 // Metrics of this type will use Int64Data.
65 func (info Scalar) LatestInt64(e *Config, key *keys.Int64) {
66 data := &Int64Data{Info: &info, IsGauge: true, key: key}
67 e.subscribe(key, data.latest)
70 // SumFloat64 creates a new metric based on the Scalar information that sums all
71 // the values recorded on the float64 measure.
72 // Metrics of this type will use Float64Data.
73 func (info Scalar) SumFloat64(e *Config, key *keys.Float64) {
74 data := &Float64Data{Info: &info, key: key}
75 e.subscribe(key, data.sum)
78 // LatestFloat64 creates a new metric based on the Scalar information that tracks
79 // the most recent value recorded on the float64 measure.
80 // Metrics of this type will use Float64Data.
81 func (info Scalar) LatestFloat64(e *Config, key *keys.Float64) {
82 data := &Float64Data{Info: &info, IsGauge: true, key: key}
83 e.subscribe(key, data.latest)
86 // Record creates a new metric based on the HistogramInt64 information that
87 // tracks the bucketized counts of values recorded on the int64 measure.
88 // Metrics of this type will use HistogramInt64Data.
89 func (info HistogramInt64) Record(e *Config, key *keys.Int64) {
90 data := &HistogramInt64Data{Info: &info, key: key}
91 e.subscribe(key, data.record)
94 // Record creates a new metric based on the HistogramFloat64 information that
95 // tracks the bucketized counts of values recorded on the float64 measure.
96 // Metrics of this type will use HistogramFloat64Data.
97 func (info HistogramFloat64) Record(e *Config, key *keys.Float64) {
98 data := &HistogramFloat64Data{Info: &info, key: key}
99 e.subscribe(key, data.record)