| 6 | import os # for remove |
| 7 | |
| 8 | class gnuplot(object): |
| 9 | |
| 10 | output = "result.png" |
| 11 | |
| 12 | script = """ |
| 13 | set terminal png size 1024, 768 |
| 14 | set output "{}.png" |
| 15 | set title "re2 benchlog" |
| 16 | set datafile separator ";" |
| 17 | set grid x y |
| 18 | set ylabel "MB/s" |
| 19 | set autoscale |
| 20 | plot """ |
| 21 | |
| 22 | template = """'{}' using 1:5:xticlabels(2) with linespoints linewidth 3 title "{}",\\\n""" |
| 23 | |
| 24 | benchdata = dict() |
| 25 | tempfiles = [] |
| 26 | |
| 27 | def __enter__(self): |
| 28 | return self |
| 29 | |
| 30 | def __exit__(self, type, value, traceback): |
| 31 | """ |
| 32 | remove all temporary files |
| 33 | """ |
| 34 | |
| 35 | for filename in self.tempfiles: |
| 36 | os.remove(filename) |
| 37 | |
| 38 | def parse_re2_benchlog(self, filename): |
| 39 | """ |
| 40 | parse the input benchlog and return a dictionary contain bench data |
| 41 | """ |
| 42 | |
| 43 | benchdata = self.benchdata |
| 44 | |
| 45 | with open(filename) as f: |
| 46 | |
| 47 | for raw in f.readlines(): |
| 48 | |
| 49 | data = raw.split('\t') |
| 50 | |
| 51 | if len(data) == 4: |
| 52 | |
| 53 | data = data[0].split('/') + data[1:] |
| 54 | data = list(map(str.strip, data)) |
| 55 | |
| 56 | if not benchdata.get(data[0]): |
| 57 | benchdata[data[0]] = [ data[1:] ] |
| 58 | else: |
| 59 | benchdata[data[0]].append(data[1:]) |
| 60 | |
| 61 | def gen_csv(self): |
| 62 | """ |
| 63 | generate temporary csv files |
| 64 | """ |
| 65 | |