Skip to content

Commit 1c13c8c

Browse files
committed
chore: bypass absolute import fail threshold if baseline also exceeds it
1 parent 6a972d8 commit 1c13c8c

1 file changed

Lines changed: 34 additions & 27 deletions

File tree

scripts/import_profiler/profiler.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,7 @@ def run_master(iterations, target_module, cpu=0, csv_path=None, clear_cache=True
240240
exit_code = 0
241241
final_messages = []
242242

243-
if fail_threshold is not None:
244-
if p50_time > fail_threshold:
245-
final_messages.append(f"FAILURE: Median import time ({p50_time:.2f} ms) exceeds the failure threshold ({fail_threshold} ms).")
246-
exit_code = 1
247-
else:
248-
final_messages.append(f"SUCCESS: Median import time ({p50_time:.2f} ms) is within the failure threshold ({fail_threshold} ms).")
249-
243+
baseline_p50 = None
250244
if diff_baseline:
251245
if os.path.exists(diff_baseline):
252246
baseline_times = []
@@ -255,32 +249,45 @@ def run_master(iterations, target_module, cpu=0, csv_path=None, clear_cache=True
255249
next(reader) # skip header
256250
for row in reader:
257251
baseline_times.append(float(row[1]))
258-
baseline_p50, _, _ = _calculate_percentiles(baseline_times)
259-
diff = p50_time - baseline_p50
260-
261-
diff_msg = (
262-
f"--- Diff vs Baseline ---\n"
263-
f"Baseline Median: {baseline_p50:.2f} ms\n"
264-
f"Current Median: {p50_time:.2f} ms\n"
265-
f"Difference: {diff:+.2f} ms"
266-
)
267-
final_messages.append(diff_msg)
252+
if baseline_times:
253+
baseline_p50, _, _ = _calculate_percentiles(baseline_times)
268254

269-
relative_diff_threshold = 0.15 * baseline_p50
270-
if diff > diff_threshold and diff > relative_diff_threshold:
271-
final_messages.append(
272-
f"FAILURE: Import time regression of {diff:.2f} ms exceeds both the absolute threshold ({diff_threshold} ms) "
273-
f"and the relative threshold ({relative_diff_threshold:.2f} ms, 15% of baseline Median)."
255+
if baseline_p50 is not None:
256+
diff = p50_time - baseline_p50
257+
258+
diff_msg = (
259+
f"--- Diff vs Baseline ---\n"
260+
f"Baseline Median: {baseline_p50:.2f} ms\n"
261+
f"Current Median: {p50_time:.2f} ms\n"
262+
f"Difference: {diff:+.2f} ms"
274263
)
275-
exit_code = 1
276-
else:
277-
if diff > diff_threshold:
278-
final_messages.append(f"SUCCESS: Import time regression of {diff:.2f} ms exceeds absolute threshold ({diff_threshold} ms) but is within relative threshold ({relative_diff_threshold:.2f} ms, 15%).")
264+
final_messages.append(diff_msg)
265+
266+
relative_diff_threshold = 0.15 * baseline_p50
267+
if diff > diff_threshold and diff > relative_diff_threshold:
268+
final_messages.append(
269+
f"FAILURE: Import time regression of {diff:.2f} ms exceeds both the absolute threshold ({diff_threshold} ms) "
270+
f"and the relative threshold ({relative_diff_threshold:.2f} ms, 15% of baseline Median)."
271+
)
272+
exit_code = 1
279273
else:
280-
final_messages.append("SUCCESS: Import time diff is within acceptable thresholds.")
274+
if diff > diff_threshold:
275+
final_messages.append(f"SUCCESS: Import time regression of {diff:.2f} ms exceeds absolute threshold ({diff_threshold} ms) but is within relative threshold ({relative_diff_threshold:.2f} ms, 15%).")
276+
else:
277+
final_messages.append("SUCCESS: Import time diff is within acceptable thresholds.")
281278
else:
282279
final_messages.append(f"WARNING: Baseline CSV {diff_baseline} not found. Skipping diff check.")
283280

281+
if fail_threshold is not None:
282+
if p50_time > fail_threshold:
283+
if baseline_p50 is not None and baseline_p50 > fail_threshold:
284+
final_messages.append(f"WARNING: Median import time ({p50_time:.2f} ms) exceeds the absolute failure threshold ({fail_threshold} ms), but the baseline ({baseline_p50:.2f} ms) also exceeded it. Bypassing absolute backstop failure.")
285+
else:
286+
final_messages.append(f"FAILURE: Median import time ({p50_time:.2f} ms) exceeds the failure threshold ({fail_threshold} ms).")
287+
exit_code = 1
288+
else:
289+
final_messages.append(f"SUCCESS: Median import time ({p50_time:.2f} ms) is within the failure threshold ({fail_threshold} ms).")
290+
284291
if final_messages:
285292
print("\n" + "\n".join(final_messages))
286293

0 commit comments

Comments
 (0)