github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/sys/proc.go (about) 1 // Package sys provides methods to read system information 2 /* 3 * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package sys 6 7 type ( 8 ProcCPUStats struct { 9 User uint64 10 System uint64 11 Total uint64 12 LastTime int64 13 Percent float64 14 } 15 16 ProcMemStats struct { 17 Size uint64 18 Resident uint64 19 Share uint64 20 } 21 22 ProcStats struct { 23 CPU ProcCPUStats 24 Mem ProcMemStats 25 } 26 ) 27 28 func ProcessStats(pid int) (ProcStats, error) { 29 cpu, err := procCPU(pid) 30 if err != nil { 31 return ProcStats{}, err 32 } 33 stats := ProcStats{CPU: cpu} 34 if contCPUs > 1 { 35 stats.CPU.Percent = float64(stats.CPU.Total) / float64(contCPUs) // TODO: confirm 36 } 37 mem, err := procMem(pid) 38 if err != nil { 39 return ProcStats{}, err 40 } 41 stats.Mem = mem 42 43 return stats, nil 44 }