You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
601 B
23 lines
601 B
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package logger
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
)
|
|
|
|
// 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
|
|
// and max RSS.
|
|
func RusagePrefixLog(logf Logf) Logf {
|
|
return func(f string, argv ...any) {
|
|
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...)
|
|
}
|
|
}
|
|
|