tsweb/varz: optimize some allocs, add helper func for others

Updates #cleanup
Updates tailscale/corp#23546 (noticed when doing this)

Change-Id: Ia9f627fe32bb4955739b2787210ba18f5de27f4d
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/14038/head
Brad Fitzpatrick 2 weeks ago committed by Brad Fitzpatrick
parent 8ba9b558d2
commit 3090461961

@ -23,10 +23,16 @@ import (
"tailscale.com/version" "tailscale.com/version"
) )
// StaticStringVar returns a new expvar.Var that always returns s.
func StaticStringVar(s string) expvar.Var {
var v any = s // box s into an interface just once
return expvar.Func(func() any { return v })
}
func init() { func init() {
expvar.Publish("process_start_unix_time", expvar.Func(func() any { return timeStart.Unix() })) expvar.Publish("process_start_unix_time", expvar.Func(func() any { return timeStart.Unix() }))
expvar.Publish("version", expvar.Func(func() any { return version.Long() })) expvar.Publish("version", StaticStringVar(version.Long()))
expvar.Publish("go_version", expvar.Func(func() any { return runtime.Version() })) expvar.Publish("go_version", StaticStringVar(runtime.Version()))
expvar.Publish("counter_uptime_sec", expvar.Func(func() any { return int64(Uptime().Seconds()) })) expvar.Publish("counter_uptime_sec", expvar.Func(func() any { return int64(Uptime().Seconds()) }))
expvar.Publish("gauge_goroutines", expvar.Func(func() any { return runtime.NumGoroutine() })) expvar.Publish("gauge_goroutines", expvar.Func(func() any { return runtime.NumGoroutine() }))
} }

Loading…
Cancel
Save