in mozperftest_tools/mozperftest_tools/profile_enhancer.py [0:0]
def run(self, profile_before, profile_after):
"""
This method will go through the visual metrics in both
profiles to try to find all areas where there is either
a regression or improvement and mark them into a new
profile in the given output directory.
"""
profile_before = pathlib.Path(profile_before).resolve()
with profile_before.open() as f:
data_before = json.load(f)
profile_after = pathlib.Path(profile_after).resolve()
with profile_after.open() as f:
data_after = json.load(f)
gecko_main, start_time = self.get_geckomain_thread(data_after)
# Calculate regression ranges
vismets_before = data_before["meta"].get("visualMetrics", None)
vismets_after = data_after["meta"].get("visualMetrics", None)
# Calculate a regression/improvment range for each visual progress metric
psi_changes = self.detect_changes(
vismets_before.get("PerceptualSpeedIndexProgress", []),
vismets_after.get("PerceptualSpeedIndexProgress", [])
)
print(psi_changes)
csi_changes = self.detect_changes(
vismets_before.get("ContentfulSpeedIndexProgress", []),
vismets_after.get("ContentfulSpeedIndexProgress", [])
)
print(csi_changes)
si_changes = self.detect_changes(
vismets_before.get("VisualProgress", []),
vismets_after.get("VisualProgress", [])
)
print(si_changes)
# Insert the change markers into the after profile
perfchange_name_ind = self.insert_into_string_table(gecko_main)
test_cat_ind = self.get_test_category(data_after)
diff = start_time - data_after["meta"]["startTime"]
for prog_type, changes in [
("PerceptualSpeedIndex", psi_changes),
("ContenfulSpeedIndex", csi_changes),
("SpeedIndex", si_changes)
]:
for change in changes:
print(f"{prog_type}: {change}")
gecko_main["markers"]["data"].append(
[
perfchange_name_ind,
change["start"] - diff,
change["end"] - diff,
1,
test_cat_ind,
{
"type": "Task",
"name": f"{prog_type} - {change['type']}",
}
]
)
# Save the data
profile_after_name = profile_after.name.split(".")[0]
res = pathlib.Path(self.output_dir, f"{profile_after_name}-enhanced.json.gz")
print(f"Saving enhanced profile to {str(res.resolve())}")
with res.open("w") as f:
json.dump(data_after, f)