(pid int32, mem *MemoryDetail)
| 308 | } |
| 309 | |
| 310 | func readSmaps(pid int32, mem *MemoryDetail) error { |
| 311 | filePath := fmt.Sprintf("/proc/%d/smaps", pid) |
| 312 | file, err := os.Open(filePath) |
| 313 | if err != nil { |
| 314 | return err |
| 315 | } |
| 316 | defer file.Close() |
| 317 | |
| 318 | scanner := bufio.NewScanner(file) |
| 319 | |
| 320 | for scanner.Scan() { |
| 321 | line := scanner.Text() |
| 322 | fields := strings.Fields(line) |
| 323 | if len(fields) < 2 { |
| 324 | continue |
| 325 | } |
| 326 | |
| 327 | key := strings.TrimSuffix(fields[0], ":") |
| 328 | value, _ := strconv.ParseUint(fields[1], 10, 64) |
| 329 | value *= 1024 |
| 330 | |
| 331 | switch key { |
| 332 | case "Pss": |
| 333 | mem.PSS += value |
| 334 | case "Private_Clean", "Private_Dirty": |
| 335 | mem.USS += value |
| 336 | case "Shared_Clean", "Shared_Dirty": |
| 337 | if mem.Shared == 0 { |
| 338 | mem.Shared += value |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | return scanner.Err() |
| 344 | } |
no test coverage detected