github.com/MerlinKodo/gvisor@v0.0.0-20231110090155-957f62ecf90e/pkg/metric/condmetric_profiling.go (about) 1 // Copyright 2022 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //go:build condmetric_profiling 16 // +build condmetric_profiling 17 18 package metric 19 20 import ( 21 "fmt" 22 23 pb "github.com/MerlinKodo/gvisor/pkg/metric/metric_go_proto" 24 ) 25 26 // This file defines conditional metrics that are meant to be used when profiling 27 // runsc during benchmark tests. 28 29 // ProfilingUint64Metric is a metric type that is registered and used only when 30 // the "condmetric_profiling" go tag is specified for go build. 31 // 32 // Otherwise it is exactly like a Uint64Metric. 33 type ProfilingUint64Metric = Uint64Metric 34 35 // ProfilingDistributionMetric is a metric type that is registered and used only 36 // when the "condmetric_profiling" go tag is specified for go build. 37 // 38 // Otherwise it is exactly like a DistributionMetric. 39 type ProfilingDistributionMetric = DistributionMetric 40 41 // ProfilingTimerMetric is a metric type that is registered and used only when 42 // the "condmetric_profiling" go tag is specified for go build. 43 // 44 // Otherwise it is exactly like a TimerMetric. 45 type ProfilingTimerMetric = TimerMetric 46 47 // NewProfilingUint64Metric is equivalent to NewUint64Metric except it creates a 48 // ProfilingUint64Metric 49 var NewProfilingUint64Metric = newProfilingUint64Metric 50 51 // MustCreateNewProfilingUint64Metric is equivalent to MustCreateNewUint64Metric 52 // except it creates a ProfilingUint64Metric. 53 var MustCreateNewProfilingUint64Metric = mustCreateNewProfilingUint64Metric 54 55 // NewProfilingDistributionMetric is equivalent to NewDistributionMetric except 56 // it creates a ProfilingDistributionMetric. 57 var NewProfilingDistributionMetric = NewDistributionMetric 58 59 // MustCreateNewProfilingDistributionMetric is equivalent to 60 // MustCreateNewDistributionMetric except it creates a 61 // ProfilingDistributionMetric. 62 var MustCreateNewProfilingDistributionMetric = MustCreateNewDistributionMetric 63 64 // NewProfilingTimerMetric is equivalent to NewTimerMetric except it creates a 65 // ProfilingTimerMetric. 66 var NewProfilingTimerMetric = NewTimerMetric 67 68 // MustCreateNewProfilingTimerMetric is equivalent to MustCreateNewTimerMetric 69 // except it creates a ProfilingTimerMetric. 70 var MustCreateNewProfilingTimerMetric = MustCreateNewTimerMetric 71 72 func newProfilingUint64Metric(name string, sync bool, units pb.MetricMetadata_Units, description string, fields ...Field) (*Uint64Metric, error) { 73 m, err := NewUint64Metric(name, sync, units, description, fields...) 74 if err != nil { 75 return m, err 76 } 77 definedProfilingMetrics = append(definedProfilingMetrics, m.name) 78 return m, err 79 } 80 81 func mustCreateNewProfilingUint64Metric(name string, sync bool, description string, fields ...Field) *Uint64Metric { 82 m, err := newProfilingUint64Metric(name, sync, pb.MetricMetadata_UNITS_NONE, description, fields...) 83 if err != nil { 84 panic(fmt.Sprintf("Unable to create metric %q: %s", name, err)) 85 } 86 return m 87 }