re2/benchlog/benchplot.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import argparse # for ArgumentParser
4 import subprocess # for Popen
5 import tempfile # for NamedTemporaryFile
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 
66  for name, data in self.benchdata.items():
67 
68  with tempfile.NamedTemporaryFile(delete=False) as f:
69 
70  for index, line in enumerate(data):
71  f.write('{};{}\n'.format(index, ';'.join(line)).encode())
72 
73  self.tempfiles.append(f.name)
74  self.script = self.script + self.template.format(f.name, name)
75 
76  def run(self):
77  self.gen_csv()
78  script = self.script[:-3].format(self.output)
79  command = subprocess.Popen(['gnuplot'], stdin=subprocess.PIPE)
80  command.communicate(script.encode())
81 
82 
83 if __name__ == '__main__':
84 
85  parser = argparse.ArgumentParser(description='generate plots for benchlog')
86  parser.add_argument('benchlog', type=str, help='benchlog generated by re2')
87  args = parser.parse_args()
88 
89  try:
90  subprocess.Popen(['gnuplot'], stdin=subprocess.PIPE)
91  except FileNotFoundError:
92  print('you can install "gnuplot" to generate plots automatically')
93  exit(1)
94 
95  with gnuplot() as plot:
96  plot.output = args.benchlog
97  plot.parse_re2_benchlog(args.benchlog)
98  plot.run()
http2_test_server.format
format
Definition: http2_test_server.py:118
benchplot.gnuplot.tempfiles
list tempfiles
Definition: bloaty/third_party/re2/benchlog/benchplot.py:25
benchplot.gnuplot.__exit__
def __exit__(self, type, value, traceback)
Definition: bloaty/third_party/re2/benchlog/benchplot.py:30
benchplot.gnuplot.__enter__
def __enter__(self)
Definition: bloaty/third_party/re2/benchlog/benchplot.py:27
benchplot.gnuplot.parse_re2_benchlog
def parse_re2_benchlog(self, filename)
Definition: bloaty/third_party/re2/benchlog/benchplot.py:38
benchplot.gnuplot.script
string script
Definition: bloaty/third_party/re2/benchlog/benchplot.py:12
map
zval * map
Definition: php/ext/google/protobuf/encode_decode.c:480
benchplot.gnuplot
Definition: bloaty/third_party/re2/benchlog/benchplot.py:8
grpc._common.encode
def encode(s)
Definition: grpc/_common.py:68
xds_manager.items
items
Definition: xds_manager.py:55
benchplot.gnuplot.run
def run(self)
Definition: bloaty/third_party/re2/benchlog/benchplot.py:76
benchplot.gnuplot.output
string output
Definition: bloaty/third_party/re2/benchlog/benchplot.py:10
benchplot.gnuplot.benchdata
benchdata
Definition: bloaty/third_party/re2/benchlog/benchplot.py:24
open
#define open
Definition: test-fs.c:46
benchplot.gnuplot.gen_csv
def gen_csv(self)
Definition: bloaty/third_party/re2/benchlog/benchplot.py:61
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
benchplot.gnuplot.template
string template
Definition: bloaty/third_party/re2/benchlog/benchplot.py:22
split
static void split(const char *s, char ***ss, size_t *ns)
Definition: debug/trace.cc:111


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:46