golang.org/x/tools/gopls@v0.15.3/internal/debug/metrics.go (about) 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. 4 5 package debug 6 7 import ( 8 "golang.org/x/tools/internal/event/export/metric" 9 "golang.org/x/tools/internal/event/label" 10 "golang.org/x/tools/internal/event/tag" 11 ) 12 13 var ( 14 // the distributions we use for histograms 15 bytesDistribution = []int64{1 << 10, 1 << 11, 1 << 12, 1 << 14, 1 << 16, 1 << 20} 16 millisecondsDistribution = []float64{0.1, 0.5, 1, 2, 5, 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000} 17 18 receivedBytes = metric.HistogramInt64{ 19 Name: "received_bytes", 20 Description: "Distribution of received bytes, by method.", 21 Keys: []label.Key{tag.RPCDirection, tag.Method}, 22 Buckets: bytesDistribution, 23 } 24 25 sentBytes = metric.HistogramInt64{ 26 Name: "sent_bytes", 27 Description: "Distribution of sent bytes, by method.", 28 Keys: []label.Key{tag.RPCDirection, tag.Method}, 29 Buckets: bytesDistribution, 30 } 31 32 latency = metric.HistogramFloat64{ 33 Name: "latency", 34 Description: "Distribution of latency in milliseconds, by method.", 35 Keys: []label.Key{tag.RPCDirection, tag.Method}, 36 Buckets: millisecondsDistribution, 37 } 38 39 started = metric.Scalar{ 40 Name: "started", 41 Description: "Count of RPCs started by method.", 42 Keys: []label.Key{tag.RPCDirection, tag.Method}, 43 } 44 45 completed = metric.Scalar{ 46 Name: "completed", 47 Description: "Count of RPCs completed by method and status.", 48 Keys: []label.Key{tag.RPCDirection, tag.Method, tag.StatusCode}, 49 } 50 ) 51 52 func registerMetrics(m *metric.Config) { 53 receivedBytes.Record(m, tag.ReceivedBytes) 54 sentBytes.Record(m, tag.SentBytes) 55 latency.Record(m, tag.Latency) 56 started.Count(m, tag.Started) 57 completed.Count(m, tag.Latency) 58 }