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