mirror of
https://github.com/golang/go
synced 2024-11-18 20:34:39 -07:00
eff45d17df
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>
51 lines
1.8 KiB
Go
51 lines
1.8 KiB
Go
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package debug
|
|
|
|
import (
|
|
"golang.org/x/tools/internal/lsp/telemetry"
|
|
"golang.org/x/tools/internal/telemetry/event"
|
|
"golang.org/x/tools/internal/telemetry/metric"
|
|
)
|
|
|
|
var (
|
|
// the distributions we use for histograms
|
|
bytesDistribution = []int64{1 << 10, 1 << 11, 1 << 12, 1 << 14, 1 << 16, 1 << 20}
|
|
millisecondsDistribution = []float64{0.1, 0.5, 1, 2, 5, 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000}
|
|
|
|
receivedBytes = metric.HistogramInt64{
|
|
Name: "received_bytes",
|
|
Description: "Distribution of received bytes, by 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: []*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: []*event.Key{telemetry.RPCDirection, telemetry.Method},
|
|
Buckets: millisecondsDistribution,
|
|
}.Record(telemetry.Latency)
|
|
|
|
started = metric.Scalar{
|
|
Name: "started",
|
|
Description: "Count of RPCs started by 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: []*event.Key{telemetry.RPCDirection, telemetry.Method, telemetry.StatusCode},
|
|
}.CountFloat64(telemetry.Latency)
|
|
)
|