2023-01-27 01:10:27 +07:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2023-03-14 14:01:55 +07:00
|
|
|
* Copyright (c) 2022-2023, daeuniverse Organization <dae@v2raya.org>
|
2023-01-27 01:10:27 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
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))
|
|
|
|
}
|