1import sys 2import argparse 3import sqlite3 4import matplotlib.pyplot as plt 5import numpy as np 6import os 7 8 9# usage: python3 rollingplot.py DB_FILE_PATH PERF_NAME [--aggregate AGGREGATE_RATIO] 10 11 12class DataSet: 13 14 def __init__(self, db_path): 15 self.conn = sqlite3.connect(db_path) 16 self.cursor = self.conn.cursor() 17 self.xdata = [] 18 self.ydata = [] 19 20 def derive(self, perf_name, aggregate, hart): 21 sql = "SELECT xAxisPt, yAxisPt FROM {}_rolling_{}".format(perf_name, hart) 22 self.cursor.execute(sql) 23 result = self.cursor.fetchall() 24 aggcnt = 0 25 aggydata = 0 26 aggxdata = 0 27 for row in result: 28 aggcnt += 1 29 aggydata += row[1] 30 if aggcnt == aggregate: 31 self.xdata.append(row[0]) 32 self.ydata.append(aggydata/(row[0]-aggxdata)) 33 aggcnt = 0 34 aggydata = 0 35 aggxdata = row[0] 36 37 def plot(self): 38 plt.plot(self.xdata, self.ydata, lw=1, ls='-', c='black') 39 dirName = "results" 40 if not os.path.exists(dirName): 41 os.mkdir(dirName) 42 # temporary label for tutorial 43 plt.ylabel('IPC') 44 plt.xlabel('Sampling Index') 45 plt.savefig(os.path.join(dirName, 'perf.png'), bbox_inches='tight', pad_inches=0.05, dpi=200) 46 47 48if __name__ == "__main__": 49 parser = argparse.ArgumentParser(description="performance rolling plot script for xs") 50 parser.add_argument('db_path', metavar='db_path', type=str, help='path to chiseldb file') 51 parser.add_argument('perf_name', metavar='perf_name', type=str, help="name of the performance counter") 52 parser.add_argument('--aggregate', '-A', default=1, type=int, help="aggregation ratio") 53 args = parser.parse_args() 54 55 if args.aggregate <= 0: 56 print("aggregation ratio must be no less than 1") 57 sys.exit(1) 58 59 db_path = args.db_path 60 perf_name = args.perf_name 61 aggregate = args.aggregate 62 63 dataset = DataSet(db_path) 64 dataset.derive(perf_name, aggregate, 0) 65 dataset.plot()