Last active
August 29, 2024 19:50
-
-
Save liquidcarbon/d6dace5dd0ce98283469160ce040597c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
import json | |
import os | |
import psutil | |
kernel_pids = [p.pid for p in psutil.process_iter(['pid', 'name']) if 'python' in p.info['name']] | |
rows = [] | |
for pid in kernel_pids: | |
process = psutil.Process(pid) | |
try: | |
with open(process.cmdline()[-1], "r") as f: | |
d = json.load(f) | |
jup = Path(d["jupyter_session"]) | |
mem_info = process.memory_info() | |
rows.append(( | |
process.pid, | |
pd.Timestamp(int(process.create_time()), unit="s"), | |
int(mem_info.rss) >> 20, | |
jup.parent, | |
jup.name, | |
)) | |
except Exception as e: | |
# raise e | |
pass | |
df = pd.DataFrame(rows, columns=["pid","start","memMB","nbFolder","nbName"]) | |
df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment