Skip to content
Snippets Groups Projects
Commit bda49247 authored by Ben Gamari's avatar Ben Gamari :turtle:
Browse files

sample_proc: Add smaps parser

parent fce5e0ef
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ from pathlib import Path
import sys
import time
import subprocess
from typing import List, Optional
from typing import List, Optional, Iterator
def read_proc(pid: int) -> dict:
f = Path('/proc') / str(pid) / 'status'
......@@ -46,6 +46,30 @@ def plot_it(results: "numpy.ndarray",
else:
pl.show()
def parse_smaps(s: str) -> Iterator[dict]:
cur = {}
for l in s.split('\n'):
parts = l.split()
if len(parts) == 0:
yield cur # end of file
if parts[0].endswith(':'):
cur[parts[0][:-1]] = ' '.join(parts[1:])
else:
if cur != {}:
yield cur
start_s, end_s = parts[0].split('-')
perms = parts[1]
cur = {
'start': int(start_s, 16),
'end': int(end_s, 16),
'perms': parts[1],
'offset': int(parts[2], 16),
'dev': parts[3],
'inode': int(parts[4], 16),
'pathname': parts[5] if len(parts) >= 6 else '',
}
def main():
import argparse
parser = argparse.ArgumentParser()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment