gopsutil icon indicating copy to clipboard operation
gopsutil copied to clipboard

Calculating pss/uss from /proc/<pid>/smaps

Open ronklein opened this issue 7 years ago • 7 comments

Added pss and uss metrics. Fixed issue in MemoryMapsWithContext. Parsing of /proc//smaps failed when field "Name:" exists.

ronklein avatar Jul 25 '18 13:07 ronklein

We can't accept your additions as they are Linux-only currently, try to run GOOS=windows go test github.com/shirou/gopsutil/process to see undefined types/methods errors at compile time.

Please document what these values represent and provide a source re: how you calculate them.

Lomanic avatar Jul 25 '18 16:07 Lomanic

Moved specific linux test, to a dedicated test file. USS/PSS calculation is described in https://lwn.net/Articles/230975/. Added comments to emphasis that.

ronklein avatar Jul 26 '18 08:07 ronklein

The MemoryInfoSmaps type and function are still Linux-only, gopsutil is platform-agnostic and provides the same public API (types, methods) across all the supported platforms, moving around this new test to make it Linux-only does not fix anything. The GOOS=windows go test command was here to underline the undefined type/method errors on this platform (any platform not Linux).

Also, do we need a new type MemoryInfoSmaps where PSS is already found in MemoryMapsStat? Wouldn't it be sensible to just add the new USS field to MemoryMapsStat?

Lomanic avatar Jul 26 '18 16:07 Lomanic

Currently MemoryMapsWithContext is called with a boolean "grouped" variable. But this variable is not used. Maybe the intention was to use this flag to decide whether to sum up all memory maps into a single group? If so, then we can add USS and use the grouped flag to decide to either return all memory maps, or a single aggregate memory map (sum of each memory map type).

ronklein avatar Jul 27 '18 18:07 ronklein

MemoryMaps is a port of psutil memory_map. This (perhaps only this) method is allowed to use platform dependent struct, because psutil does.

grouped is not implemented, but it is just because my laziness. I will appreciate if you would make a PR with PSS and grouped feature.

shirou avatar Jul 28 '18 13:07 shirou

Sure, i will make a PR for it. I will also make a PR for implementing memory_full_info(), which returns both USS and PSS.

ronklein avatar Jul 29 '18 07:07 ronklein

Just noticed, that you've been up to the same stuff. Here's a PR that adds grouping of MemoryMaps, please have a look: https://github.com/shirou/gopsutil/pull/567.

tagirb avatar Aug 08 '18 07:08 tagirb