forked from mtusi2026/mtusi2026lab4
28 lines
709 B
Go
28 lines
709 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// Local operator command, never an HTTP endpoint. cgroup v2 records peaks
|
|
// between Docker samples too; the experiment recreates API cgroups per case.
|
|
func memorySnapshot() error {
|
|
result := map[string]uint64{}
|
|
for _, name := range []string{"memory.current", "memory.peak"} {
|
|
raw, err := os.ReadFile("/sys/fs/cgroup/" + name)
|
|
if err != nil {
|
|
return fmt.Errorf("cgroup v2 %s unavailable", name)
|
|
}
|
|
value, err := strconv.ParseUint(strings.TrimSpace(string(raw)), 10, 64)
|
|
if err != nil {
|
|
return fmt.Errorf("invalid cgroup %s", name)
|
|
}
|
|
result[name] = value
|
|
}
|
|
return json.NewEncoder(os.Stdout).Encode(result)
|
|
}
|