1 // Copyright 2020 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.
12 // ValueKind is a tag for a metric Value which indicates its type.
16 // KindBad indicates that the Value has no type and should not be used.
17 KindBad ValueKind = iota
19 // KindUint64 indicates that the type of the Value is a uint64.
22 // KindFloat64 indicates that the type of the Value is a float64.
25 // KindFloat64Histogram indicates that the type of the Value is a *Float64Histogram.
29 // Value represents a metric value returned by the runtime.
32 scalar uint64 // contains scalar values for scalar Kinds.
33 pointer unsafe.Pointer // contains non-scalar values.
36 // Kind returns the tag representing the kind of value this is.
37 func (v Value) Kind() ValueKind {
41 // Uint64 returns the internal uint64 value for the metric.
43 // If v.Kind() != KindUint64, this method panics.
44 func (v Value) Uint64() uint64 {
45 if v.kind != KindUint64 {
46 panic("called Uint64 on non-uint64 metric value")
51 // Float64 returns the internal float64 value for the metric.
53 // If v.Kind() != KindFloat64, this method panics.
54 func (v Value) Float64() float64 {
55 if v.kind != KindFloat64 {
56 panic("called Float64 on non-float64 metric value")
58 return math.Float64frombits(v.scalar)
61 // Float64Histogram returns the internal *Float64Histogram value for the metric.
63 // If v.Kind() != KindFloat64Histogram, this method panics.
64 func (v Value) Float64Histogram() *Float64Histogram {
65 if v.kind != KindFloat64Histogram {
66 panic("called Float64Histogram on non-Float64Histogram metric value")
68 return (*Float64Histogram)(v.pointer)