17cf78eb2Shappy-lximport sys 27cf78eb2Shappy-lximport argparse 37cf78eb2Shappy-lximport sqlite3 47cf78eb2Shappy-lximport matplotlib.pyplot as plt 57cf78eb2Shappy-lximport numpy as np 6*f2421014SYanqin Liimport os 77cf78eb2Shappy-lx 87cf78eb2Shappy-lx 97cf78eb2Shappy-lx# usage: python3 rollingplot.py DB_FILE_PATH PERF_NAME [--aggregate AGGREGATE_RATIO] 107cf78eb2Shappy-lx 117cf78eb2Shappy-lx 127cf78eb2Shappy-lxclass DataSet: 137cf78eb2Shappy-lx 147cf78eb2Shappy-lx def __init__(self, db_path): 157cf78eb2Shappy-lx self.conn = sqlite3.connect(db_path) 167cf78eb2Shappy-lx self.cursor = self.conn.cursor() 177cf78eb2Shappy-lx self.xdata = [] 187cf78eb2Shappy-lx self.ydata = [] 197cf78eb2Shappy-lx 207cf78eb2Shappy-lx def derive(self, perf_name, aggregate, hart): 217cf78eb2Shappy-lx sql = "SELECT xAxisPt, yAxisPt FROM {}_rolling_{}".format(perf_name, hart) 227cf78eb2Shappy-lx self.cursor.execute(sql) 237cf78eb2Shappy-lx result = self.cursor.fetchall() 247cf78eb2Shappy-lx aggcnt = 0 257cf78eb2Shappy-lx aggydata = 0 267cf78eb2Shappy-lx aggxdata = 0 277cf78eb2Shappy-lx for row in result: 287cf78eb2Shappy-lx aggcnt += 1 297cf78eb2Shappy-lx aggydata += row[1] 307cf78eb2Shappy-lx if aggcnt == aggregate: 317cf78eb2Shappy-lx self.xdata.append(row[0]) 327cf78eb2Shappy-lx self.ydata.append(aggydata/(row[0]-aggxdata)) 337cf78eb2Shappy-lx aggcnt = 0 347cf78eb2Shappy-lx aggydata = 0 357cf78eb2Shappy-lx aggxdata = row[0] 367cf78eb2Shappy-lx 377cf78eb2Shappy-lx def plot(self): 387cf78eb2Shappy-lx plt.plot(self.xdata, self.ydata, lw=1, ls='-', c='black') 39*f2421014SYanqin Li dirName = "results" 40*f2421014SYanqin Li if not os.path.exists(dirName): 41*f2421014SYanqin Li os.mkdir(dirName) 42*f2421014SYanqin Li # temporary label for tutorial 43*f2421014SYanqin Li plt.ylabel('IPC') 44*f2421014SYanqin Li plt.xlabel('Sampling Index') 45*f2421014SYanqin Li plt.savefig(os.path.join(dirName, 'perf.png'), bbox_inches='tight', pad_inches=0.05, dpi=200) 467cf78eb2Shappy-lx 477cf78eb2Shappy-lx 487cf78eb2Shappy-lxif __name__ == "__main__": 497cf78eb2Shappy-lx parser = argparse.ArgumentParser(description="performance rolling plot script for xs") 507cf78eb2Shappy-lx parser.add_argument('db_path', metavar='db_path', type=str, help='path to chiseldb file') 517cf78eb2Shappy-lx parser.add_argument('perf_name', metavar='perf_name', type=str, help="name of the performance counter") 527cf78eb2Shappy-lx parser.add_argument('--aggregate', '-A', default=1, type=int, help="aggregation ratio") 537cf78eb2Shappy-lx args = parser.parse_args() 547cf78eb2Shappy-lx 557cf78eb2Shappy-lx if args.aggregate <= 0: 567cf78eb2Shappy-lx print("aggregation ratio must be no less than 1") 577cf78eb2Shappy-lx sys.exit(1) 587cf78eb2Shappy-lx 597cf78eb2Shappy-lx db_path = args.db_path 607cf78eb2Shappy-lx perf_name = args.perf_name 617cf78eb2Shappy-lx aggregate = args.aggregate 627cf78eb2Shappy-lx 637cf78eb2Shappy-lx dataset = DataSet(db_path) 647cf78eb2Shappy-lx dataset.derive(perf_name, aggregate, 0) 657cf78eb2Shappy-lx dataset.plot()