MCPcopy Create free account
hub / github.com/PostHog/duckgres / readSystemMemoryBytes

Function readSystemMemoryBytes

server/sysinfo/sysinfo.go:32–51  ·  view source on GitHub ↗

readSystemMemoryBytes reads total physical memory from /proc/meminfo on Linux. Returns 0 if the file cannot be read or parsed (e.g., on non-Linux systems).

()

Source from the content-addressed store, hash-verified

30// readSystemMemoryBytes reads total physical memory from /proc/meminfo on Linux.
31// Returns 0 if the file cannot be read or parsed (e.g., on non-Linux systems).
32func readSystemMemoryBytes() uint64 {
33 f, err := os.Open("/proc/meminfo")
34 if err != nil {
35 return 0
36 }
37 defer func() { _ = f.Close() }()
38
39 scanner := bufio.NewScanner(f)
40 for scanner.Scan() {
41 line := scanner.Text()
42 if strings.HasPrefix(line, "MemTotal:") {
43 var kb uint64
44 if _, err := fmt.Sscanf(line, "MemTotal: %d kB", &kb); err == nil {
45 return kb * 1024
46 }
47 return 0
48 }
49 }
50 return 0
51}
52
53var (
54 autoMemoryLimitOnce sync.Once

Callers 3

TestAutoMemoryLimitFunction · 0.85
SystemMemoryBytesFunction · 0.85

Calls 3

CloseMethod · 0.65
ScanMethod · 0.65
OpenMethod · 0.45

Tested by 2

TestAutoMemoryLimitFunction · 0.68