mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-04 14:41:01 +00:00
types/logger: move RusagePrefixLog to logger package, disable by default
The RusagePrefixLog is rarely useful, hasn't been useful in a long time, is rarely the measurement we need, and is pretty spammy (and syscall-heavy). Disable it by default. We can enable it when we're debugging memory.
This commit is contained in:
parent
ff0cf6340a
commit
86c271caba
@ -19,6 +19,7 @@ import (
|
|||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -115,7 +116,10 @@ func run() error {
|
|||||||
pol.Shutdown(ctx)
|
pol.Shutdown(ctx)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
logf := wgengine.RusagePrefixLog(log.Printf)
|
var logf logger.Logf = log.Printf
|
||||||
|
if v, _ := strconv.ParseBool(os.Getenv("TS_DEBUG_MEMORY")); v {
|
||||||
|
logf = logger.RusagePrefixLog(logf)
|
||||||
|
}
|
||||||
logf = logger.RateLimitedFn(logf, 5*time.Second, 5, 100)
|
logf = logger.RateLimitedFn(logf, 5*time.Second, 5, 100)
|
||||||
|
|
||||||
if args.cleanup {
|
if args.cleanup {
|
||||||
|
@ -2,19 +2,17 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package wgengine
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"tailscale.com/types/logger"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RusagePrefixLog returns a Logf func wrapping the provided logf func that adds
|
// RusagePrefixLog returns a Logf func wrapping the provided logf func that adds
|
||||||
// a prefixed log message to each line with the current binary memory usage
|
// a prefixed log message to each line with the current binary memory usage
|
||||||
// and max RSS.
|
// and max RSS.
|
||||||
func RusagePrefixLog(logf logger.Logf) logger.Logf {
|
func RusagePrefixLog(logf Logf) Logf {
|
||||||
return func(f string, argv ...interface{}) {
|
return func(f string, argv ...interface{}) {
|
||||||
var m runtime.MemStats
|
var m runtime.MemStats
|
||||||
runtime.ReadMemStats(&m)
|
runtime.ReadMemStats(&m)
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
// +build !windows
|
// +build !windows
|
||||||
|
|
||||||
package wgengine
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package wgengine
|
package logger
|
||||||
|
|
||||||
func rusageMaxRSS() float64 {
|
func rusageMaxRSS() float64 {
|
||||||
// TODO(apenwarr): Substitute Windows equivalent of Getrusage() here.
|
// TODO(apenwarr): Substitute Windows equivalent of Getrusage() here.
|
Loading…
x
Reference in New Issue
Block a user