github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/runtime/metrics/value.go (about)

     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.
     4  
     5  package metrics
     6  
     7  import (
     8  	"github.com/shogo82148/std/unsafe"
     9  )
    10  
    11  // ValueKindはメトリックの [Value] のタグで、そのタイプを示します。
    12  type ValueKind int
    13  
    14  const (
    15  	// KindBadは、Valueに型がなく、使用すべきではないことを示します。
    16  	KindBad ValueKind = iota
    17  
    18  	// KindUint64 は Value の型が uint64 であることを示します。
    19  	KindUint64
    20  
    21  	// KindFloat64はValueの型がfloat64であることを示します。
    22  	KindFloat64
    23  
    24  	// KindFloat64HistogramはValueの型が*Float64Histogramであることを示します。
    25  	KindFloat64Histogram
    26  )
    27  
    28  // Valueはランタイムが返すメトリック値を表します。
    29  type Value struct {
    30  	kind    ValueKind
    31  	scalar  uint64
    32  	pointer unsafe.Pointer
    33  }
    34  
    35  // Kindは、この値の種類を表すタグを返します。
    36  func (v Value) Kind() ValueKind
    37  
    38  // Uint64はメトリックの内部uint64値を返します。
    39  //
    40  // もしv.Kind() != KindUint64の場合、このメソッドはパニックします。
    41  func (v Value) Uint64() uint64
    42  
    43  // Float64はメトリックの内部float64値を返します。
    44  //
    45  // もしv.Kind() != KindFloat64なら、このメソッドはパニックを引き起こします。
    46  func (v Value) Float64() float64
    47  
    48  func (v Value) Float64Histogram() *Float64Histogram