diff options
author | Michael Pratt <mpratt@google.com> | 2021-01-13 08:18:24 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-01-13 08:20:00 -0800 |
commit | e4d8f55cef1aa0b6b48dec5a20fe6e480d70d0a0 (patch) | |
tree | ed0eb226c216bed19c8258a91d4d01ef513ea4ba | |
parent | 19ab0f15f3d2069611257d619acf551071a2aedc (diff) |
Human-readable metric emit logs
Rather than dumping metrics on a single line, nearly unrelated textproto, print
them in alphabetical order, each on their own line.
e.g.,
D0108 17:42:42.198216 3382465 metric.go:253] Emitting metrics:
D0108 17:42:42.198240 3382465 metric.go:255] /fs/opens: &{Uint64Value:22}
D0108 17:42:42.198271 3382465 metric.go:255] /fs/read_wait: &{Uint64Value:0}
D0108 17:42:42.198294 3382465 metric.go:255] /fs/reads: &{Uint64Value:26}
D0108 17:42:42.198319 3382465 metric.go:255] /gofer/opened_write_execute_file: &{Uint64Value:0}
D0108 17:42:42.198327 3382465 metric.go:255] /gofer/opens_9p: &{Uint64Value:0}
D0108 17:42:42.198340 3382465 metric.go:255] /gofer/opens_host: &{Uint64Value:20}
...
PiperOrigin-RevId: 351590340
-rw-r--r-- | pkg/metric/metric.go | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/pkg/metric/metric.go b/pkg/metric/metric.go index d012c5734..c9f9357de 100644 --- a/pkg/metric/metric.go +++ b/pkg/metric/metric.go @@ -18,6 +18,7 @@ package metric import ( "errors" "fmt" + "sort" "sync/atomic" "gvisor.dev/gvisor/pkg/eventchannel" @@ -139,7 +140,8 @@ func MustRegisterCustomUint64Metric(name string, cumulative, sync bool, descript } } -// NewUint64Metric creates and registers a new cumulative metric with the given name. +// NewUint64Metric creates and registers a new cumulative metric with the given +// name. // // Metrics must be statically defined (i.e., at init). func NewUint64Metric(name string, sync bool, units pb.MetricMetadata_Units, description string) (*Uint64Metric, error) { @@ -147,7 +149,8 @@ func NewUint64Metric(name string, sync bool, units pb.MetricMetadata_Units, desc return &m, RegisterCustomUint64Metric(name, true /* cumulative */, sync, units, description, m.Value) } -// MustCreateNewUint64Metric calls NewUint64Metric and panics if it returns an error. +// MustCreateNewUint64Metric calls NewUint64Metric and panics if it returns an +// error. func MustCreateNewUint64Metric(name string, sync bool, description string) *Uint64Metric { m, err := NewUint64Metric(name, sync, pb.MetricMetadata_UNITS_NONE, description) if err != nil { @@ -156,7 +159,8 @@ func MustCreateNewUint64Metric(name string, sync bool, description string) *Uint return m } -// MustCreateNewUint64NanosecondsMetric calls NewUint64Metric and panics if it returns an error. +// MustCreateNewUint64NanosecondsMetric calls NewUint64Metric and panics if it +// returns an error. func MustCreateNewUint64NanosecondsMetric(name string, sync bool, description string) *Uint64Metric { m, err := NewUint64Metric(name, sync, pb.MetricMetadata_UNITS_NANOSECONDS, description) if err != nil { @@ -245,6 +249,15 @@ func EmitMetricUpdate() { return } - log.Debugf("Emitting metrics: %v", &m) + if log.IsLogging(log.Debug) { + sort.Slice(m.Metrics, func(i, j int) bool { + return m.Metrics[i].Name < m.Metrics[j].Name + }) + log.Debugf("Emitting metrics:") + for _, metric := range m.Metrics { + log.Debugf("%s: %+v", metric.Name, metric.Value) + } + } + eventchannel.Emit(&m) } |