Debian Codegraph @

gopls/internal/debug/metrics.go

raw symbols SCIP
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/jsonrpc2"
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 secondsDistribution = []float64{
17 0.0001, // 0.1ms
18 0.0005, // 0.5ms
19 0.001, // 1ms
20 0.002, // 2ms
21 0.005, // 5ms
22 0.01, // 10ms
23 0.05, // 50ms
24 0.1, // 100ms
25 0.5, // 500ms
26 1, // 1s
27 5, // 5s
28 10, // 10s
29 50, // 50s
30 100, // 1m40s
31 500, // 8m20s
32 1000, // 16m40s
33 }
34
35 receivedBytes = metric.HistogramInt64{
36 Name: "received_bytes",
37 Description: "Distribution of received bytes, by method.",
38 Keys: []label.Key{jsonrpc2.RPCDirection, jsonrpc2.Method},
39 Buckets: bytesDistribution,
40 }
41
42 sentBytes = metric.HistogramInt64{
43 Name: "sent_bytes",
44 Description: "Distribution of sent bytes, by method.",
45 Keys: []label.Key{jsonrpc2.RPCDirection, jsonrpc2.Method},
46 Buckets: bytesDistribution,
47 }
48
49 latency = metric.HistogramFloat64{
50 Name: "latency",
51 Description: "Distribution of latency in seconds, by method.",
52 Keys: []label.Key{jsonrpc2.RPCDirection, jsonrpc2.Method},
53 Buckets: secondsDistribution,
54 }
55
56 started = metric.Scalar{
57 Name: "started",
58 Description: "Count of RPCs started by method.",
59 Keys: []label.Key{jsonrpc2.RPCDirection, jsonrpc2.Method},
60 }
61
62 completed = metric.Scalar{
63 Name: "completed",
64 Description: "Count of RPCs completed by method and status.",
65 Keys: []label.Key{jsonrpc2.RPCDirection, jsonrpc2.Method, jsonrpc2.StatusCode},
66 }
67 )
68
69 func registerMetrics(m *metric.Config) {
70 receivedBytes.Record(m, jsonrpc2.ReceivedBytes)
71 sentBytes.Record(m, jsonrpc2.SentBytes)
72 latency.Record(m, jsonrpc2.Latency)
73 started.Count(m, jsonrpc2.Started)
74 completed.Count(m, jsonrpc2.Latency)
75 }