diff options
Diffstat (limited to 'yardstick/plot/plotter.py')
-rw-r--r-- | yardstick/plot/plotter.py | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/yardstick/plot/plotter.py b/yardstick/plot/plotter.py index 4cbbdfe74..4e65303dc 100644 --- a/yardstick/plot/plotter.py +++ b/yardstick/plot/plotter.py @@ -16,13 +16,19 @@ $ yardstick-plot -i /tmp/yardstick.out -o /tmp/plots/ ''' +from __future__ import absolute_import +from __future__ import print_function + import argparse -import json import os import sys import time -import matplotlib.pyplot as plt + import matplotlib.lines as mlines +import matplotlib.pyplot as plt +from oslo_serialization import jsonutils +from six.moves import range +from six.moves import zip class Parser(object): @@ -44,7 +50,7 @@ class Parser(object): prog='yardstick-plot', description="A tool for visualizing results from yardstick. " "Currently supports plotting graphs for output files " - "from tests: " + str(self.data.keys()) + "from tests: " + str(list(self.data.keys())) ) parser.add_argument( '-i', '--input', @@ -65,7 +71,7 @@ class Parser(object): self.scenarios[record["runner_id"]] = obj_name return runner_object = self.scenarios[record["runner_id"]] - for test_type in self.data.keys(): + for test_type in self.data: if test_type in runner_object: self.data[test_type].append(record) @@ -80,17 +86,17 @@ class Parser(object): if self.args.input: input_file = self.args.input else: - print("No input file specified, reading from %s" - % self.default_input_loc) + print(("No input file specified, reading from %s" + % self.default_input_loc)) input_file = self.default_input_loc try: with open(input_file) as f: for line in f: - record = json.loads(line) + record = jsonutils.loads(line) self._add_record(record) except IOError as e: - print(os.strerror(e.errno)) + print((os.strerror(e.errno))) sys.exit(1) @@ -126,7 +132,7 @@ class Plotter(object): os.makedirs(self.output_folder) new_file = os.path.join(self.output_folder, file_name) plt.savefig(new_file) - print("Saved graph to " + new_file) + print(("Saved graph to " + new_file)) def _plot_ping(self, records): '''ping test result interpretation and visualization on the graph''' @@ -143,7 +149,7 @@ class Plotter(object): if len(rtts) == 1: plt.bar(1, rtts[0], 0.35, color=self.colors[0]) else: - plt.plot(seqs, rtts, self.colors[0]+'-') + plt.plot(seqs, rtts, self.colors[0] + '-') self._construct_legend(['rtt']) plt.xlabel("sequence number") @@ -164,13 +170,13 @@ class Plotter(object): received[i] = 0.0 plt.axvline(flows[i], color='r') - ppm = [1000000.0*(i - j)/i for i, j in zip(sent, received)] + ppm = [1000000.0 * (i - j) / i for i, j in zip(sent, received)] # If there is a single data-point then display a bar-chart if len(ppm) == 1: plt.bar(1, ppm[0], 0.35, color=self.colors[0]) else: - plt.plot(flows, ppm, self.colors[0]+'-') + plt.plot(flows, ppm, self.colors[0] + '-') self._construct_legend(['ppm']) plt.xlabel("number of flows") @@ -191,7 +197,7 @@ class Plotter(object): for i, val in enumerate(intervals): if val: for j, _ in enumerate(intervals): - kbps.append(val[j]['sum']['bits_per_second']/1000) + kbps.append(val[j]['sum']['bits_per_second'] / 1000) seconds.append(seconds[-1] + val[j]['sum']['seconds']) else: kbps.append(0.0) @@ -202,7 +208,7 @@ class Plotter(object): plt.axvline(seconds[-1], color='r') self._construct_legend(['bandwidth']) - plt.plot(seconds[1:], kbps[1:], self.colors[0]+'-') + plt.plot(seconds[1:], kbps[1:], self.colors[0] + '-') plt.xlabel("time in seconds") plt.ylabel("bandwidth in Kb/s") @@ -312,5 +318,6 @@ def main(): print("Plotting graph(s)") plotter.plot() + if __name__ == '__main__': main() |