dae/common/debug.go
czybjtu e71c272693
style: format golang import package code style (#58)
Co-authored-by: Kevin Yu <yqlbu@Bu.edu>
2023-04-23 13:27:29 +08:00

30 lines
621 B
Go

/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) 2022-2023, daeuniverse Organization <dae@v2raya.org>
*/
package common
import (
"os"
"path/filepath"
"strconv"
"strings"
"github.com/sirupsen/logrus"
)
func ReportMemory(tag string) {
if !logrus.IsLevelEnabled(logrus.DebugLevel) {
return
}
b, err := os.ReadFile(filepath.Join("/proc", strconv.Itoa(os.Getpid()), "status"))
if err != nil {
panic(err)
}
str := strings.TrimSpace(string(b))
_, after, _ := strings.Cut(str, "VmHWM:")
usage, _, _ := strings.Cut(after, "\n")
logrus.Debugln(tag+": memory usage:", strings.TrimSpace(usage))
}