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