MCPcopy Create free account
hub / github.com/1jehuang/jcode / proc_stat

Function proc_stat

scripts/stress_test.py:85–100  ·  view source on GitHub ↗

Get process stats from /proc.

(pid)

Source from the content-addressed store, hash-verified

83 return None
84
85def proc_stat(pid):
86 """Get process stats from /proc."""
87 stats = {}
88 try:
89 with open(f"/proc/{pid}/status") as f:
90 for line in f:
91 if line.startswith("VmRSS:"):
92 stats["rss_kb"] = int(line.split()[1])
93 elif line.startswith("VmSize:"):
94 stats["vms_kb"] = int(line.split()[1])
95 elif line.startswith("Threads:"):
96 stats["threads"] = int(line.split()[1])
97 stats["fds"] = len(os.listdir(f"/proc/{pid}/fd"))
98 except:
99 pass
100 return stats
101
102def fmt_kb(kb):
103 if kb > 1024*1024:

Callers 1

stress_test.pyFile · 0.85

Calls 1

splitMethod · 0.45

Tested by

no test coverage detected