Skip to content

Commit 4f042f6

Browse files
committed
<function> add plot part for latency
1 parent bed8a88 commit 4f042f6

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

benchmark/basic_performance/scripts/plot/bw_latency_plot.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@
2525
#
2626

2727
import os
28+
import sys
2829

2930
import matplotlib.pyplot as plt
3031
import pandas as pd
31-
try:
32-
from loguru import logger # type: ignore
33-
except ModuleNotFoundError: # pragma: no cover
34-
import logging
35-
36-
logging.basicConfig(level=logging.INFO)
37-
logger = logging.getLogger(__name__)
32+
from loguru import logger
3833

3934

4035
# Define plotting functions
@@ -52,6 +47,7 @@ def plot_bandwidth_vs_latency_and_save(df, output_file, title_prefix):
5247
plt.title(f"{title_prefix}: Measured Latency vs Total Bandwidth")
5348
plt.xlabel("Total Bandwidth (GiB/s)")
5449
plt.ylabel("Measured Latency (ns)")
50+
plt.ylim(0, 2500)
5551
plt.legend()
5652
plt.grid(True)
5753
plt.savefig(output_file)
@@ -167,6 +163,7 @@ def plot_threads_vs_bw_latency_and_save(df, output_file, title_prefix):
167163
ax_bw.set_ylabel("Bandwidth (GiB/s)", color="tab:blue")
168164
ax_lat.set_ylabel("Latency (ns)", color="tab:red")
169165
ax_lat.set_ylim(0, 2500)
166+
ax_bw.set_ylim(0, 80)
170167

171168
ax_bw.tick_params(axis="y", labelcolor="tab:blue")
172169
ax_lat.tick_params(axis="y", labelcolor="tab:red")
@@ -227,3 +224,34 @@ def plot_bw_latency(base_dir):
227224
plot_threads_vs_bandwidth_and_save(store_data, store_output_files["threads_vs_bandwidth"], "STORE")
228225
plot_threads_vs_latency_and_save(store_data, store_output_files["threads_vs_latency"], "STORE")
229226
plot_threads_vs_bw_latency_and_save(store_data, store_output_files["threads_vs_bw_latency"], "STORE")
227+
228+
229+
def _main(argv: list[str]) -> int:
230+
if len(argv) < 2:
231+
logger.error(
232+
"Usage: python bw_latency_plot.py <result_dir_1> [<result_dir_2> ...]\n"
233+
"Each result_dir must contain parsed_result_logs.csv"
234+
)
235+
return 2
236+
237+
had_error = False
238+
for base_dir in argv[1:]:
239+
base_dir = os.path.abspath(base_dir)
240+
csv_path = os.path.join(base_dir, "parsed_result_logs.csv")
241+
if not os.path.exists(csv_path):
242+
logger.error(f"Missing parsed_result_logs.csv: {csv_path}")
243+
had_error = True
244+
continue
245+
246+
logger.info(f"Plotting from: {csv_path}")
247+
try:
248+
plot_bw_latency(base_dir)
249+
except Exception as e:
250+
logger.exception(f"Failed to plot for {base_dir}: {e}")
251+
had_error = True
252+
253+
return 1 if had_error else 0
254+
255+
256+
if __name__ == "__main__":
257+
raise SystemExit(_main(sys.argv))

0 commit comments

Comments
 (0)