Remove python proc stats parsing code

Summary:
Remove python code to parse /proc/self/smaps and associated tests. This is now
done in the EdenServer c++ code.

Reviewed By: simpkins

Differential Revision: D8550273

fbshipit-source-id: 6a2a5cbd25beff412376b0ada683f9dc30e15aff
This commit is contained in:
Eamonn Kent 2018-06-21 08:12:34 -07:00 committed by Facebook Github Bot
parent 2d4daf67a3
commit d2aad68634
2 changed files with 0 additions and 117 deletions

View File

@ -80,51 +80,6 @@ def do_stats_general(
)
MemoryMapping = Dict[bytes, bytes]
# Returns a list of all mappings
def parse_smaps(smaps: bytes) -> List[MemoryMapping]:
output: List[MemoryMapping] = []
current: Optional[MemoryMapping] = None
for line in smaps.splitlines():
if b"-" in line: # blech
if current is not None:
output.append(current)
current = {}
else:
if current is None:
log.warning("first line should be range")
continue
split = line.split(b":")
if len(split) != 2:
log.warning("line not key: value")
continue
key, value = line.split(b":")
current[key.strip()] = value.strip()
if current is not None:
output.append(current)
return output
def total_private_dirty(maps: List[MemoryMapping]) -> Optional[int]:
total = 0
for mapping in maps:
try:
private_dirty = mapping[b"Private_Dirty"]
except KeyError:
pass
else:
if not private_dirty.endswith(b" kB"):
log.warning(
"value does not end with kB: %s",
private_dirty.decode(errors="backslashreplace"),
)
return None
total += int(private_dirty[:-3]) * 1024
return total
@stats_cmd("memory", "Show memory statistics for Eden")
class MemoryCmd(Subcmd):
def run(self, args: argparse.Namespace) -> int:

View File

@ -97,75 +97,3 @@ key 1 2 3 4
self.assertEqual("123.4 MB", stats_print.format_size(123400000))
self.assertEqual("12 B", stats_print.format_size(12))
self.assertEqual("0", stats_print.format_size(0))
def test_count_private_dirty_bytes(self):
smaps = b"""\
7ff33e76c000-7ff33e770000 r--p 00025000 fc:03 263921 /usr/lib64/libtinfo.so.5.9
Size: 16 kB
Rss: 16 kB
Pss: 16 kB
Shared_Clean: 0 kB
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirty: 16 kB
Referenced: 16 kB
Anonymous: 16 kB
LazyFree: 0 kB
AnonHugePages: 0 kB
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd mr mw me ac
7ff33e770000-7ff33e771000 rw-p 00029000 fc:03 263921 /usr/lib64/libtinfo.so.5.9
Size: 4 kB
Rss: 4 kB
Pss: 4 kB
Shared_Clean: 0 kB
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirty: 4 kB
Referenced: 4 kB
Anonymous: 4 kB
LazyFree: 0 kB
AnonHugePages: 0 kB
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB
VmFlags: rd wr mr mw me ac"""
self.assertEqual(5 * 4096, stats.total_private_dirty(stats.parse_smaps(smaps)))
@unittest.skipUnless(
sys.platform == "linux", "/proc/self/smaps only exists on Linux"
)
def test_correctly_parses_real_smaps(self):
with open("/proc/self/smaps", "rb") as f:
smaps = f.read()
total = stats.total_private_dirty(stats.parse_smaps(smaps))
self.assertIsNotNone(total)
self.assertGreater(total, 0)
def test_parse_smaps_ignores_unknown_line_formats(self):
smaps = b"""\
Weird line in front
7ff33e770000-7ff33e771000 rw-p 00029000 fc:03 263921 /usr/lib64/libtinfo.so.5.9
Size: 4 kB
No Colon
Private_Dirty: 4 kB
:Three:Colons:
line at end
"""
mappings = stats.parse_smaps(smaps)
self.assertEqual(1, len(mappings))
self.assertEqual(4096, stats.total_private_dirty(mappings))
def test_total_private_dirty_returns_None_if_unknown_value_format(self):
self.assertEqual(0, stats.total_private_dirty([]))
self.assertIs(None, stats.total_private_dirty([{b"Private_Dirty": b"4096 B"}]))