Skip to content

Commit

Permalink
ports: Add some more diagnosis and hide the details behind a -v flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Jul 5, 2024
1 parent 3d1b4ad commit ceb4ea2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ports
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,17 @@ else:
pids = [proc for proc in os.listdir("/proc") if set(proc) <= set("1234567890")]
status = collections.Counter()
for pid in pids:
with open(f"/proc/{pid}/stat") as f:
if m := re.match(r"^[0-9]+ \((.*?)\) (.)", f.read()):
status[m.group(2)] += 1
#if m.group(2) == "D": print(pid, "DiskSleep", m.group(1))
try:
with open(f"/proc/{pid}/stat") as f:
# Assumes that the process title is the only text string and thus the only place with parentheses.
m = re.match(r"^[0-9]+ \((.*)\) (.*)", f.read())
if not m: continue
title = m.group(1)
info = m.group(2).split()
state, ppid, *_ = info
status[state] += 1
if state == "D" and "-v" in sys.argv:
print(pid, "DiskSleep", title, "ppid", ppid)
except FileNotFoundError: pass # Process must have terminated while we were searching
print("Procs", len(pids), f"({status['D']} D, {status['R']} R)")
sys.exit(error)

0 comments on commit ceb4ea2

Please sign in to comment.