#!/usr/bin/python import time try: import psutil except ImportError: print "Cannot import psutil module - this is needed for this application."; print "Exiting..." sys.exit(); # end if try: import matplotlib.pyplot as plt; # Needed for plots except: print "Cannot import matplotlib module - this is needed for this application."; print "Exiting..." sys.exit(); # end if def column(matrix, i): return [row[i] for row in matrix] # end def # =================== # Main Python section # =================== # if __name__ == '__main__': # Main dictionary d = {}; # define interval and add to dictionary interv = 0.5; d['interval'] = interv; # Number of cores: N = psutil.cpu_count(); d['NCPUS'] = N; cpu_percent = []; epoch_list = []; for x in range(140): # hard coded as an example cpu_percent_local = []; epoch_list.append(time.time()); cpu_percent_local=psutil.cpu_percent(interval=interv,percpu=True); cpu_percent.append(cpu_percent_local); # end for # Normalize epoch to beginning epoch_list[:] = [x - epoch_list[0] for x in epoch_list]; # Plots for i in range(N): A = column(cpu_percent, i); plt.plot(epoch_list, A); # end if plt.xlabel('Time (seconds)'); plt.ylabel('CPU Percentage'); plt.show(); # end if