Skip to content

Commit b89a852

Browse files
liyuying0000copybara-github
authored andcommitted
Fixes issue where benchmark names were lost when converting a Pandas DataFrame to a list of dictionaries. Now includes benchmark names as a key within each dictionary.
PiperOrigin-RevId: 721641743 Change-Id: I0bbc012ce39a936c14ef6cfe507aeb83e136ebf9
1 parent 64ea2f2 commit b89a852

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

fleetbench/parallel/parallel_bench_lib.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,7 @@ def SaveBenchmarkResults(self, df: pd.DataFrame) -> None:
462462
df = df.rename(columns={"Benchmark": "name"})
463463
df = df.rename(columns={"WallTimes": "real_time"})
464464
df = df.rename(columns={"CPUTimes": "cpu_time"})
465-
466-
data = df.to_dict(orient="records")
465+
data = df.reset_index().to_dict(orient="records")
467466

468467
with open(file_name, "w") as json_file:
469468
json.dump(
@@ -521,7 +520,7 @@ def GeneratePerfCounterDataFrame(
521520

522521
perf_counters_results = (
523522
perf_counters_results.groupby("Benchmark").agg(**aggregations).round(3)
524-
).reset_index()
523+
)
525524
return perf_counters_results
526525

527526
def ConvertToDataFrame(self) -> pd.DataFrame:

fleetbench/parallel/parallel_bench_lib_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def test_generate_perf_counter_dataframe(self):
285285
expected_df = pd.DataFrame([
286286
{"Benchmark": "test_benchmark1", "instructions": 130.0, "cycles": 3.0},
287287
{"Benchmark": "test_benchmark2", "instructions": 200.0, "cycles": 2.0},
288-
])
288+
]).set_index("Benchmark")
289289
pd.testing.assert_frame_equal(df, expected_df)
290290

291291
def test_generate_benchmark_report(self):
@@ -335,8 +335,8 @@ def test_save_benchmark_results(self):
335335
self.assertEqual(
336336
data,
337337
[
338-
{"name": "BM_Test1", "Duration": 1, "cpu_time": 1},
339-
{"name": "BM_Test2", "Duration": 1, "cpu_time": 2},
338+
{"index": 0, "name": "BM_Test1", "Duration": 1, "cpu_time": 1},
339+
{"index": 1, "name": "BM_Test2", "Duration": 1, "cpu_time": 2},
340340
],
341341
)
342342

0 commit comments

Comments
 (0)