In [ ]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline  
df = pd.read_csv('./nvsmi_records.csv')

In [ ]:
f_vmstat = open('./vmstat_records.txt')
lines = f_vmstat.readlines()
usr = []
sys = []
iow = []
timestamps = []
i=0
for line in lines:
    if line.find('procs') != -1 or line.find('UTC') != -1:
        continue
    i = i + 1
    timestamps.append(i)
    usr.append(int(line.split()[12]))
    sys.append(int(line.split()[13]))
    iow.append(int(line.split()[15]))

In [ ]:
t = []
sm = []
mm = []
i = 0
gpus = [0,1,2,3,4,5,6,7]

for row in df.values:
    if row[2] == 0:
        i = i + 1
    if row[2] in gpus:
        if i < 4000:
            t.append(i)
            sm.append(int(row[3].split()[0]))
            mm.append(int(row[4].split()[0]))

In [ ]:
fig = plt.figure()
fig.suptitle('SM/MM Util. Over Time (s)')
plt.plot(t, sm, '--', linewidth=1, markersize=2, label='GPU-SM' )
plt.plot(t, mm, '--', linewidth=1, markersize=2, label='GPU-MM' )
plt.plot(timestamps, usr, '--', linewidth=1, markersize=2, label='CPU-USR' )
plt.plot(timestamps, sys, '--', linewidth=1, markersize=2, label='CPU-SYS' )
plt.plot(timestamps, iow, '--', linewidth=1, markersize=2, label='CPU-IOW' )
legend = fig.legend(loc='upper left', shadow=False, fontsize='small')

# Put a nicer background color on the legend.
#legend.get_frame().set_facecolor('C0')
plt.show()
fig.savefig('sm.svg', width=1024, height=768)
fig.savefig('sm.pdf', width=1024, height=768)