in mozperftest_tools/mozperftest_tools/side_by_side.py [0:0]
def generate_step_chart(self, oldvid, newvid, vismetPath, prefix, metric, output):
print("Generating step chart for %s" % metric)
try:
from matplotlib import pyplot as plt
except Exception:
print("Please install matplotlib before using step charts")
raise
oldvid_metrics = json.loads(
subprocess.check_output(
[
"python",
vismetPath,
"--orange",
"--perceptual",
"--contentful",
"--force",
"--renderignore",
"5",
"--json",
"--viewport",
"--video",
oldvid,
]
)
)
newvid_metrics = json.loads(
subprocess.check_output(
[
"python",
vismetPath,
"--orange",
"--perceptual",
"--contentful",
"--force",
"--renderignore",
"5",
"--json",
"--viewport",
"--video",
newvid,
]
)
)
if metric.lower() == "perceptualspeedindex":
progress = "PerceptualSpeedIndexProgress"
metricName = "PerceptualSpeedIndex"
elif metric.lower() == "contentfulspeedindex":
progress = "ContentfulSpeedIndexProgress"
metricName = "ContentfulSpeedIndex"
else:
progress = "VisualProgress"
metricName = "SpeedIndex"
x = []
y = []
for pt in oldvid_metrics[progress].split(","):
x_val, y_val = pt.split("=")
x.append(int(x_val))
y.append(int(y_val))
plt.step(x, y, label="Before (%d)" % oldvid_metrics[metricName])
x = []
y = []
for pt in newvid_metrics[progress].split(","):
x_val, y_val = pt.split("=")
x.append(int(x_val))
y.append(int(y_val))
plt.step(x, y, label="After (%d)" % newvid_metrics[metricName])
plt.legend(loc="lower right")
plt.title("%s %s" % (prefix.rstrip("_"), metricName))
plt.savefig(str(output / "%s-%s-step.png" % (prefix.rstrip("_"), metric)))
plt.clf()