diff options
author | Ian Cottrell <iancottrell@google.com> | 2020-03-07 13:38:47 -0500 |
---|---|---|
committer | Ian Cottrell <iancottrell@google.com> | 2020-03-12 04:17:52 +0000 |
commit | eff45d17df682817c1dfe385717099af58a257a6 (patch) | |
tree | 2dca5364fc5b720e466f2d3f1d7a7941b9ac9bff /internal/lsp/debug/metrics.go | |
parent | a9aaa4e906df02a1ca74047ce2c901bcb44bbfea (diff) | |
download | golang-x-tools-eff45d17df682817c1dfe385717099af58a257a6.tar.gz |
internal/telemetry: convert key from string to struct
This makes keys a pointer, which reduces the allocations during logging, and has
a significant improvement in memory and cpu cost when there is no exporter.
Packing a string into an interface requires a 16 byte allocation, packing a pointer
does not.
name old time/op new time/op delta
/LogNoExporter-8 4.39µs ± 2% 3.83µs ± 2% -12.74% (p=0.000 n=18+20)
/Log-8 23.5µs ± 2% 22.6µs ± 1% -4.20% (p=0.000 n=19+18)
name old alloc/op new alloc/op delta
/LogNoExporter-8 1.70kB ± 0% 1.38kB ± 0% -18.78% (p=0.000 n=20+20)
/Log-8 4.91kB ± 0% 4.91kB ± 0% ~ (p=1.000 n=20+20)
name old allocs/op new allocs/op delta
/LogNoExporter-8 83.0 ± 0% 63.0 ± 0% -24.10% (p=0.000 n=20+20)
/Log-8 163 ± 0% 163 ± 0% ~ (all equal)
Change-Id: Iec127f1bff8d5c8f4bd0a6d9f6d8fc4b8bc740b2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222599
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'internal/lsp/debug/metrics.go')
-rw-r--r-- | internal/lsp/debug/metrics.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/internal/lsp/debug/metrics.go b/internal/lsp/debug/metrics.go index 44bd7eed4..7da805f03 100644 --- a/internal/lsp/debug/metrics.go +++ b/internal/lsp/debug/metrics.go @@ -6,6 +6,7 @@ package debug import ( "golang.org/x/tools/internal/lsp/telemetry" + "golang.org/x/tools/internal/telemetry/event" "golang.org/x/tools/internal/telemetry/metric" ) @@ -17,33 +18,33 @@ var ( receivedBytes = metric.HistogramInt64{ Name: "received_bytes", Description: "Distribution of received bytes, by method.", - Keys: []interface{}{telemetry.RPCDirection, telemetry.Method}, + Keys: []*event.Key{telemetry.RPCDirection, telemetry.Method}, Buckets: bytesDistribution, }.Record(telemetry.ReceivedBytes) sentBytes = metric.HistogramInt64{ Name: "sent_bytes", Description: "Distribution of sent bytes, by method.", - Keys: []interface{}{telemetry.RPCDirection, telemetry.Method}, + Keys: []*event.Key{telemetry.RPCDirection, telemetry.Method}, Buckets: bytesDistribution, }.Record(telemetry.SentBytes) latency = metric.HistogramFloat64{ Name: "latency", Description: "Distribution of latency in milliseconds, by method.", - Keys: []interface{}{telemetry.RPCDirection, telemetry.Method}, + Keys: []*event.Key{telemetry.RPCDirection, telemetry.Method}, Buckets: millisecondsDistribution, }.Record(telemetry.Latency) started = metric.Scalar{ Name: "started", Description: "Count of RPCs started by method.", - Keys: []interface{}{telemetry.RPCDirection, telemetry.Method}, + Keys: []*event.Key{telemetry.RPCDirection, telemetry.Method}, }.CountInt64(telemetry.Started) completed = metric.Scalar{ Name: "completed", Description: "Count of RPCs completed by method and status.", - Keys: []interface{}{telemetry.RPCDirection, telemetry.Method, telemetry.StatusCode}, + Keys: []*event.Key{telemetry.RPCDirection, telemetry.Method, telemetry.StatusCode}, }.CountFloat64(telemetry.Latency) ) |