From 06a601cb4caaf2af227875d8c68879a2c5ce226f Mon Sep 17 00:00:00 2001 From: David Yastremsky Date: Mon, 29 Jul 2024 16:39:43 -0700 Subject: [PATCH] Shorten filename parsing Run pre-commit hooks --- .../genai-perf/genai_perf/export_data/csv_exporter.py | 7 +++---- .../genai-perf/genai_perf/export_data/json_exporter.py | 9 +++++---- .../perf_analyzer/genai-perf/tests/test_csv_exporter.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/c++/perf_analyzer/genai-perf/genai_perf/export_data/csv_exporter.py b/src/c++/perf_analyzer/genai-perf/genai_perf/export_data/csv_exporter.py index 7633187ba..27a963034 100644 --- a/src/c++/perf_analyzer/genai-perf/genai_perf/export_data/csv_exporter.py +++ b/src/c++/perf_analyzer/genai-perf/genai_perf/export_data/csv_exporter.py @@ -63,10 +63,9 @@ def __init__(self, config: ExporterConfig): self._args = config.args def export(self) -> None: - filename = str(self._args.profile_export_file) - if filename.endswith(".json"): - filename = filename[:-5] - filename += "_genai_perf.csv" + filename = ( + self._output_dir / f"{self._args.profile_export_file.stem}_genai_perf.csv" + ) logger.info(f"Generating {filename}") with open(filename, mode="w", newline="") as f: diff --git a/src/c++/perf_analyzer/genai-perf/genai_perf/export_data/json_exporter.py b/src/c++/perf_analyzer/genai-perf/genai_perf/export_data/json_exporter.py index 2f61a7894..e1396b3a2 100644 --- a/src/c++/perf_analyzer/genai-perf/genai_perf/export_data/json_exporter.py +++ b/src/c++/perf_analyzer/genai-perf/genai_perf/export_data/json_exporter.py @@ -26,6 +26,7 @@ import json +import os from enum import Enum from typing import Dict @@ -50,10 +51,10 @@ def __init__(self, config: ExporterConfig): self._merge_stats_and_args() def export(self) -> None: - filename = str(self._args["profile_export_file"]) - if filename.endswith(".json"): - filename = filename[:-5] - filename += "_genai_perf.json" + prefix = os.path.splitext(os.path.basename(self._args["profile_export_file"]))[ + 0 + ] + filename = self._output_dir / f"{prefix}_genai_perf.json" logger.info(f"Generating {filename}") with open(str(filename), "w") as f: f.write(json.dumps(self._stats_and_args, indent=2)) diff --git a/src/c++/perf_analyzer/genai-perf/tests/test_csv_exporter.py b/src/c++/perf_analyzer/genai-perf/tests/test_csv_exporter.py index 9a94ec439..95bbfe254 100644 --- a/src/c++/perf_analyzer/genai-perf/tests/test_csv_exporter.py +++ b/src/c++/perf_analyzer/genai-perf/tests/test_csv_exporter.py @@ -133,7 +133,7 @@ def test_nonstreaming_llm_csv_output( """ artifacts_dir = "artifacts/model_name-openai-chat-concurrency1" custom_filename = "custom_export.json" - expected_filename = f"{artifacts_dir}/custom_export_genai_perf.csv" + expected_filename = f"custom_export_genai_perf.csv" argv = [ "genai-perf", "profile",