Skip to content

Instantly share code, notes, and snippets.

@Tantalus13A98B5F
Created January 6, 2020 04:33
Show Gist options
  • Save Tantalus13A98B5F/eed03a8953b0a197a7f26a6dae56ebd9 to your computer and use it in GitHub Desktop.
Save Tantalus13A98B5F/eed03a8953b0a197a7f26a6dae56ebd9 to your computer and use it in GitHub Desktop.
A simple script to visualize the memory usage on Windows by accumulation.
import subprocess as subp
import pandas as pd
from matplotlib import pyplot as plt
p = subp.Popen(['tasklist', '/fo', 'csv'], stdout=subp.PIPE)
df = pd.read_csv(p.stdout, encoding='gbk')
df['mem'] = df['内存使用 '].transform(lambda x: int(x[:-2].replace(',', '')))
df['proc'] = df['映像名称']
df = df.groupby('proc')['mem'] \
.agg(['sum', 'count']) \
.rename(columns={'sum': 'mem'}) \
.sort_values('mem') \
.reset_index()
df['tot'] = df['mem'].cumsum()
ax = df.plot('mem', 'tot', 'scatter')
for it in df.tail(20).iterrows():
idx, it = it
label = '{}, {}'.format(it['proc'], it['count']) \
if it['count'] > 1 else it['proc']
ax.annotate(label, (it['mem'], it['tot']))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment