-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathAutoPilot.cs
More file actions
84 lines (72 loc) · 2.59 KB
/
Copy pathAutoPilot.cs
File metadata and controls
84 lines (72 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using Cysharp.Threading.Tasks;
using DCL.RealmNavigation;
using Global.AppArgs;
using System;
using UnityEngine;
using Profiler = UnityEngine.Profiling.Profiler;
namespace DCL.PerformanceAndDiagnostics.AutoPilot
{
public sealed class AutoPilot
{
private readonly IAppArgs appArgs;
private readonly ILoadingStatus loadingStatus;
public AutoPilot(IAppArgs appArgs, ILoadingStatus loadingStatus)
{
this.appArgs = appArgs;
this.loadingStatus = loadingStatus;
}
public async UniTask RunAsync()
{
var exitCode = 0;
var sessionStarted = false;
try
{
if (!appArgs.TryGetValue(AppArgsFlags.AUTOPILOT_CSV, out string csvFile))
return;
if (csvFile == null)
throw new Exception($"{nameof(csvFile)} is null");
appArgs.TryGetValue(AppArgsFlags.AUTOPILOT_SUMMARY, out string summaryFile);
while (loadingStatus.CurrentStage.Value != LoadingStatus.LoadingStage.Completed)
await UniTask.Yield();
if (appArgs.TryGetValue(AppArgsFlags.PROFILER_LOG_FILE,
out string logFile))
{
#if UNITY_EDITOR || DEVELOPMENT_BUILD
Profiler.logFile = logFile;
Profiler.enableBinaryLog = true;
Profiler.enabled = true;
#else
DCL.Diagnostics.ReportHub.LogWarning(
DCL.Diagnostics.ReportCategory.ALWAYS,
$"You set the --{AppArgsFlags.PROFILER_LOG_FILE} argument, but the profiler is only available in development builds.");
#endif
}
PerfSampler.Begin(csvFile, summaryFile);
sessionStarted = true;
await StandAtSpawnAsync();
PerfSampler.End();
sessionStarted = false;
}
catch (Exception ex)
{
exitCode = ex.HResult;
throw;
}
finally
{
if (sessionStarted)
PerfSampler.End();
Application.Quit(exitCode);
}
}
/// <summary>
/// The minimal performance test: stand at spawn for one minute.
/// </summary>
private static async UniTask StandAtSpawnAsync()
{
float startTime = Time.realtimeSinceStartup;
while (Time.realtimeSinceStartup - startTime < 90f)
await UniTask.Yield();
}
}
}