aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/plot
diff options
context:
space:
mode:
authorRoss Brattain <ross.b.brattain@intel.com>2016-12-05 16:11:54 -0500
committerRoss Brattain <ross.b.brattain@intel.com>2017-01-12 18:25:04 -0800
commitf036e9898a69f5041f9cde02e3652c29e2de1643 (patch)
tree36e5eea75811bb640bb30f442f5a3c617e945909 /yardstick/plot
parent5f0b3d417244397b2d5e61c7a6ddd145f1d25046 (diff)
Add support for Python 3
Porting to Python3 using Openstack guidelines: https://wiki.openstack.org/wiki/Python3 This passes unittests on Python 3.5 and passes opnfv_smoke suite Updates: use six for urlparse and urlopen fix exception.message attribute removal run unittests on python3 use unitest.mock on python 3 fix open mock for vsperf fix float division by using delta/eplison comparison use unicode in StringIO use plugin/sample_config.yaml relative path from test case fixed apexlake unittests upgraded to mock 2.0.0 to match python3 unittest.mock features fixed flake8 issues implement safe JSON decode with oslo_serialization.jsonutils.dump_as_bytes() implement safe unicode encode/decode with oslo_utils.encodeutils heat: convert pub key file from bytes to unicode pkg_resources returns raw bytes, in python3 we have to decode this to utf-8 unicode so JSON can encode it for heat template JIRA: YARDSTICK-452 Change-Id: Ib80dd1d0c0eb0592acd832b82f6a7f8f7c20bfda Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Diffstat (limited to 'yardstick/plot')
-rw-r--r--yardstick/plot/plotter.py35
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()