Skip to content

Commit 4878d65

Browse files
liyuying0000copybara-github
authored andcommitted
Use the correct column names when dumping to. .json file
PiperOrigin-RevId: 725725389 Change-Id: I3ffad37581b60fc73bc70887332797442f8222b4
1 parent 2eff3b8 commit 4878d65

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

fleetbench/parallel/parallel_bench_lib.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,22 @@ def SaveBenchmarkResults(self, df: pd.DataFrame) -> None:
455455
"""Saves benchmark results to a JSON file for predictiveness analysis."""
456456

457457
file_name = os.path.join(self.temp_root, "results.json")
458-
try:
459-
# Convert DataFrame to a list of dictionaries (one for each row)
460-
# Rename the column "Benchmark" to "Name"
461-
# TODO: This only works for open source benchmark version.
462-
df = df.rename(columns={"Benchmark": "name"})
463-
df = df.rename(columns={"WallTimes": "real_time"})
464-
df = df.rename(columns={"CPUTimes": "cpu_time"})
465-
data = df.reset_index().to_dict(orient="records")
466458

459+
# Convert DataFrame to a list of dictionaries (one for each row)
460+
# Rename the column "Benchmark" to "Name"
461+
# TODO: This only works for open source benchmark version.
462+
463+
# We use "Benchmark" column as the index, and rename it to "name"
464+
df.index.name = "name"
465+
df = df.rename(
466+
columns={
467+
"Mean_Wall_Time": "real_time",
468+
"Mean_CPU_Time": "cpu_time",
469+
}
470+
)
471+
data = df.reset_index().to_dict(orient="records")
472+
473+
try:
467474
with open(file_name, "w") as json_file:
468475
json.dump(
469476
data, json_file, indent=4

fleetbench/parallel/parallel_bench_lib_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ def test_generate_benchmark_report(self):
323323

324324
def test_save_benchmark_results(self):
325325
df = pd.DataFrame([
326-
{"Benchmark": "BM_Test1", "Duration": 1, "CPUTimes": 1},
327-
{"Benchmark": "BM_Test2", "Duration": 1, "CPUTimes": 2},
328-
])
326+
{"Benchmark": "BM_Test1", "Mean_Wall_Time": 1, "Mean_CPU_Time": 1},
327+
{"Benchmark": "BM_Test2", "Mean_Wall_Time": 1, "Mean_CPU_Time": 2},
328+
]).set_index("Benchmark")
329329

330330
self.pb.SaveBenchmarkResults(df)
331331
file_name = os.path.join(absltest.get_default_test_tmpdir(), "results.json")
@@ -335,8 +335,8 @@ def test_save_benchmark_results(self):
335335
self.assertEqual(
336336
data,
337337
[
338-
{"index": 0, "name": "BM_Test1", "Duration": 1, "cpu_time": 1},
339-
{"index": 1, "name": "BM_Test2", "Duration": 1, "cpu_time": 2},
338+
{"name": "BM_Test1", "real_time": 1, "cpu_time": 1},
339+
{"name": "BM_Test2", "real_time": 1, "cpu_time": 2},
340340
],
341341
)
342342

0 commit comments

Comments
 (0)