Przeglądaj źródła

Add the -b switch to perf2tex, which sets the bar width

jonathanvdc 8 lat temu
rodzic
commit
6b1210e3f9
1 zmienionych plików z 21 dodań i 7 usunięć
  1. 21 7
      performance/perf2tex.py

+ 21 - 7
performance/perf2tex.py

@@ -12,6 +12,8 @@ import utils
 COLOR_SCHEME_MAX_COLOR = (36, 255, 106)
 COLOR_SCHEME_MIN_COLOR = (216, 33, 0)
 
+DEFAULT_BAR_WIDTH = 14
+
 LATEX_HEADER = r"""\documentclass[12pt,a4paper,onecolumn,openright]{report}
 \usepackage[landscape]{geometry}
 \usepackage{xcolor}
@@ -42,7 +44,8 @@ def assemble_latex_chart(optimization_levels,
                          color_defs,
                          test_names,
                          data,
-                         embed=False):
+                         embed=False,
+                         bar_width=DEFAULT_BAR_WIDTH):
     """Assembles a LaTeX chart from the given components."""
     lines = []
     if not embed:
@@ -57,7 +60,7 @@ def assemble_latex_chart(optimization_levels,
         height = 8cm,
         major x tick style = transparent,
         ybar=2*\pgflinewidth,
-        bar width=14pt,
+        bar width=%dpt,
         ymajorgrids = true,
         ylabel = {Run time},
         symbolic x coords={%s},
@@ -72,7 +75,7 @@ def assemble_latex_chart(optimization_levels,
                 anchor=south east,
                 column sep=1ex
         }
-    ]""" % ','.join(map(encode_latex_string, test_names)))
+    ]""" % (bar_width, ','.join(map(encode_latex_string, test_names))))
     for color_name, points in data:
         lines.append(r"""
         \addplot[style={%s,fill=%s,mark=none}]
@@ -90,7 +93,10 @@ def assemble_latex_chart(optimization_levels,
     return '\n'.join(lines)
 
 
-def create_latex_chart(perf_data, sorted_opt_levels=None, embed=False):
+def create_latex_chart(perf_data,
+                       sorted_opt_levels=None,
+                       embed=False,
+                       bar_width=DEFAULT_BAR_WIDTH):
     """Creates a LaTeX chart for the given performance data."""
     if sorted_opt_levels is None:
         sorted_opt_levels = sort_by_runtime(perf_data)
@@ -112,7 +118,7 @@ def create_latex_chart(perf_data, sorted_opt_levels=None, embed=False):
                 test_names.append(name)
 
     return assemble_latex_chart(opt_levels, color_defs, test_names, data,
-                                embed)
+                                embed, bar_width)
 
 
 def get_mean_runtimes(perf_data):
@@ -221,7 +227,7 @@ def main():
         '-q',
         '--quantity',
         type=str,
-        help="The quantity to build a bar chart for. Defaults to '%s'" %
+        help="The quantity to build a bar chart for. Defaults to '%s'." %
         utils.TOTAL_TIME_QUANTITY,
         default=utils.TOTAL_TIME_QUANTITY)
     arg_parser.add_argument(
@@ -246,6 +252,13 @@ def main():
         const=True,
         help="Don't include a LaTeX document header and footer.",
         default=False)
+    arg_parser.add_argument(
+        '-b',
+        '--bar-width',
+        type=int,
+        help="The width, in points, of a bar on the bar chart. Defaults to '%s'."
+        % DEFAULT_BAR_WIDTH,
+        default=DEFAULT_BAR_WIDTH)
 
     args = arg_parser.parse_args()
 
@@ -279,7 +292,8 @@ def main():
         perf_data_dict = get_relative_measurements(perf_data_dict,
                                                    baseline_opt_level)
 
-    print(create_latex_chart(perf_data_dict, sorted_opt_levels, args.embed))
+    print(create_latex_chart(perf_data_dict, sorted_opt_levels, args.embed,
+                             args.bar_width))
 
 
 if __name__ == '__main__':