2020-02-05 22:16:58 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & 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 wgengine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
2020-02-11 17:37:20 +00:00
|
|
|
|
|
|
|
"tailscale.com/logger"
|
2020-02-05 22:16:58 +00:00
|
|
|
)
|
|
|
|
|
2020-02-11 17:37:20 +00:00
|
|
|
func RusagePrefixLog(logf logger.Logf) func(f string, argv ...interface{}) {
|
2020-02-05 22:16:58 +00:00
|
|
|
return func(f string, argv ...interface{}) {
|
|
|
|
var m runtime.MemStats
|
|
|
|
runtime.ReadMemStats(&m)
|
|
|
|
goMem := float64(m.HeapInuse+m.StackInuse) / (1 << 20)
|
|
|
|
maxRSS := rusageMaxRSS()
|
|
|
|
pf := fmt.Sprintf("%.1fM/%.1fM %s", goMem, maxRSS, f)
|
|
|
|
logf(pf, argv...)
|
|
|
|
}
|
|
|
|
}
|