Coverage for mlos_bench/mlos_bench/config/environments/apps/redis/scripts/local/process_redis_results.py: 38%
8 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 00:44 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 00:44 +0000
1#!/usr/bin/env python3
2#
3# Copyright (c) Microsoft Corporation.
4# Licensed under the MIT License.
5#
6"""Script for post-processing redis-benchmark results."""
8import argparse
10import pandas as pd
13def _main(input_file: str, output_file: str) -> None:
14 """Re-shape Redis benchmark CSV results from wide to long."""
15 df_wide = pd.read_csv(input_file)
17 # Format the results from wide to long
18 # The target is columns of metric and value to act as key-value pairs.
19 df_long = (
20 df_wide.melt(id_vars=["test"])
21 .assign(metric=lambda df: df["test"] + "_" + df["variable"])
22 .drop(columns=["test", "variable"])
23 .loc[:, ["metric", "value"]]
24 )
26 # Add a default `score` metric to the end of the dataframe.
27 df_long = pd.concat(
28 [
29 df_long,
30 pd.DataFrame({"metric": ["score"], "value": [df_long.value[df_long.index.max()]]}),
31 ]
32 )
34 df_long.to_csv(output_file, index=False)
35 print(f"Converted: {input_file} -> {output_file}")
36 # print(df_long)
39if __name__ == "__main__":
40 parser = argparse.ArgumentParser(description="Post-process Redis benchmark results.")
41 parser.add_argument(
42 "input",
43 help="Redis benchmark results (downloaded from a remote VM).",
44 )
45 parser.add_argument(
46 "output",
47 help="Converted Redis benchmark data (to be consumed by OS Autotune framework).",
48 )
49 args = parser.parse_args()
50 _main(args.input, args.output)