rollingplot.py 1.8 KB

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