Skip to content

Commit 25df30d

Browse files
committed
feat(benchmark): Stop button that saves a partial report
Add BenchmarkProgress.RequestStop()/StopRequested and a 'CoreAI/Benchmarks/Stop Running Benchmark (save partial)' menu item. The suite loop checks the flag between scenario reps and breaks gracefully — the report for everything finished so far is still written (same path as the soft time-budget stop), instead of the whole run vanishing with no artifacts when Play mode is exited mid-scenario.
1 parent c917360 commit 25df30d

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

Assets/CoreAI/Runtime/Core/Features/Benchmarking/BenchmarkProgress.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ public static class BenchmarkProgress
3838
/// <summary>Fraction 0..1 for a progress bar.</summary>
3939
public static float Fraction => Total <= 0 ? 0f : (float)Completed / Total;
4040

41+
/// <summary>
42+
/// Cooperative stop flag. A Stop button sets it via <see cref="RequestStop"/>; the suite loop
43+
/// checks it between scenario reps and, when set, breaks GRACEFULLY — the report for everything
44+
/// finished so far is still written (same path as the soft time-budget stop), instead of the run
45+
/// vanishing with no artifacts when Play mode is exited mid-scenario.
46+
/// </summary>
47+
public static bool StopRequested { get; private set; }
48+
49+
/// <summary>Requests a graceful stop of the running suite (partial report is still saved).</summary>
50+
public static void RequestStop()
51+
{
52+
lock (Gate)
53+
{
54+
StopRequested = true;
55+
}
56+
}
57+
4158
/// <summary>
4259
/// True when the current scenario's elapsed/remaining wall-clock time is known and worth showing -
4360
/// a single long-running scenario (e.g. G6's free build alone, <see cref="Total"/> == 1) sits at a
@@ -66,6 +83,7 @@ public static void Begin(int total, string modelId)
6683
lock (Gate)
6784
{
6885
IsRunning = true;
86+
StopRequested = false;
6987
Total = total < 0 ? 0 : total;
7088
Completed = 0;
7189
ModelId = modelId ?? "";

Assets/CoreAIBenchmark/Tests/PlayMode/Benchmarks/GameCreationBenchmarkPlayModeTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,18 @@ public IEnumerator GameCreationBenchmark_Suite()
288288
int scenarioReps = scenario.RepsOverride ?? repetitions;
289289
for (int rep = 1; rep <= scenarioReps; rep++)
290290
{
291+
// Manual Stop button (BenchmarkProgress.RequestStop): break GRACEFULLY between reps so
292+
// the report for everything finished so far is still written, instead of losing the
293+
// whole run when Play mode is exited mid-scenario. Same graceful path as the budget gate.
294+
if (BenchmarkProgress.StopRequested)
295+
{
296+
budgetHit = true;
297+
Debug.LogWarning(
298+
$"[Benchmark] Stop requested after {report.Results.Count} scenario result(s); " +
299+
"stopping early and writing the report for everything finished so far.");
300+
break;
301+
}
302+
291303
// Start-gate on every rep (not just per scenario). The worst case for the NUnit
292304
// backstop is NOT one timeout: the retry loop below reruns a hard-failed attempt
293305
// up to maxAttempts times, each allowed the full per-scenario timeout (which the

Assets/CoreAiUnity/Tests/EditMode/GameCreationBenchmarkLauncher.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,28 @@ public static void OpenIndex()
203203
EditorUtility.RevealInFinder(index);
204204
}
205205

206+
[MenuItem("CoreAI/Benchmarks/Stop Running Benchmark (save partial)", priority = 90)]
207+
public static void StopRunningBenchmark()
208+
{
209+
if (!BenchmarkProgress.IsRunning)
210+
{
211+
EditorUtility.DisplayDialog("CoreAI Benchmark", "No benchmark is currently running.", "OK");
212+
return;
213+
}
214+
215+
// Cooperative stop: the suite loop breaks between scenario reps and still writes the report for
216+
// everything finished so far (partial), instead of the run vanishing with no artifacts.
217+
BenchmarkProgress.RequestStop();
218+
Debug.Log("[Benchmark] Stop requested — the suite will finish the current scenario, then save a "
219+
+ "partial report and exit.");
220+
}
221+
222+
[MenuItem("CoreAI/Benchmarks/Stop Running Benchmark (save partial)", validate = true)]
223+
public static bool StopRunningBenchmarkValidate()
224+
{
225+
return BenchmarkProgress.IsRunning && !BenchmarkProgress.StopRequested;
226+
}
227+
206228
[MenuItem("CoreAI/Benchmarks/Build Model Comparison Report", priority = 140)]
207229
public static void BuildComparisonReport()
208230
{

0 commit comments

Comments
 (0)