-
Notifications
You must be signed in to change notification settings - Fork 17
feat: loading benchmark analytic #9494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d82591b
fix: add loading benchmark analytics
lorenzo-ranciaffi 169a65b
lowercase stage name
lorenzo-ranciaffi 20115c6
scene hash element
lorenzo-ranciaffi 2648fc7
Merge branch 'dev' into fix/loading-benchmark-analytic
lorenzo-ranciaffi 47e43a3
Merge branch 'dev' into fix/loading-benchmark-analytic
lorenzo-ranciaffi 91b50bc
skip auth screen
lorenzo-ranciaffi 4faa0af
jarvis review
lorenzo-ranciaffi 599dfd4
jarvis review
lorenzo-ranciaffi 57abb13
Merge branch 'dev' into fix/loading-benchmark-analytic
lorenzo-ranciaffi 77ee632
Merge branch 'dev' into fix/loading-benchmark-analytic
lorenzo-ranciaffi b79bb73
add platform label
lorenzo-ranciaffi 1fbbc51
changed platform label
lorenzo-ranciaffi 69081a1
code review
lorenzo-ranciaffi 07842d0
Merge branch 'dev' into fix/loading-benchmark-analytic
lorenzo-ranciaffi d53e0b7
benchmark flag allowed as deeplink param for whitelisted world
lorenzo-ranciaffi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Explorer/Assets/DCL/PerformanceAndDiagnostics/LoadingTimes.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
Explorer/Assets/DCL/PerformanceAndDiagnostics/LoadingTimes/DCL.Plugins.LoadingTimes.asmref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "reference": "GUID:fc4fd35fb877e904d8cedee73b2256f6" | ||
| } |
7 changes: 7 additions & 0 deletions
7
...er/Assets/DCL/PerformanceAndDiagnostics/LoadingTimes/DCL.Plugins.LoadingTimes.asmref.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
155 changes: 155 additions & 0 deletions
155
Explorer/Assets/DCL/PerformanceAndDiagnostics/LoadingTimes/LoadingTimeBenchmark.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| using Cysharp.Threading.Tasks; | ||
| using DCL.Diagnostics; | ||
| using DCL.PerformanceAndDiagnostics.Analytics; | ||
| using DCL.RealmNavigation; | ||
| using DCL.Utility; | ||
| using ECS.SceneLifeCycle; | ||
| using Newtonsoft.Json.Linq; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using UnityEngine; | ||
| using Utility; | ||
|
|
||
| namespace DCL.LoadingTimes | ||
| { | ||
| /// <summary> | ||
| /// CI-only benchmark of the startup loading stages: reports their durations to analytics and quits the client. | ||
| /// </summary> | ||
| public sealed class LoadingTimeBenchmark : IDisposable | ||
| { | ||
| private const string STAGE_PREFIX = "loading_stage_"; | ||
| private const string START_LABEL = "start_time_s"; | ||
| private const string STOP_LABEL = "stop_time_s"; | ||
| private const string DURATION_LABEL = "duration_s"; | ||
| private const string SCENE_HASH_LABEL = "scene_hash"; | ||
| private const string PLATFORM_LABEL = "platform"; | ||
|
|
||
| #if UNITY_STANDALONE_OSX | ||
| private const string PLATFORM_VALUE = "mac"; | ||
| #else | ||
| private const string PLATFORM_VALUE = "win"; | ||
| #endif | ||
|
|
||
| // The loading begins with the process, where realtimeSinceStartup is 0. | ||
| private const float APP_START_TIME = 0f; | ||
|
|
||
| // The analytics service dispatches on a background pump, quitting right away kills the request. | ||
| private static readonly TimeSpan ANALYTICS_DELIVERY_GRACE = TimeSpan.FromSeconds(5); | ||
|
|
||
| private readonly List<StageMeasure> measures = new ((int)LoadingStatus.LoadingStage.Completed + 1); | ||
| private readonly CancellationTokenSource cts = new (); | ||
|
|
||
| private readonly ILoadingStatus loadingStatus; | ||
| private readonly IAnalyticsController analytics; | ||
| private readonly IScenesCache scenesCache; | ||
|
|
||
| private bool reportRequestFired; | ||
|
|
||
| public LoadingTimeBenchmark(ILoadingStatus loadingStatus, IAnalyticsController analytics, IScenesCache scenesCache) | ||
| { | ||
| this.loadingStatus = loadingStatus; | ||
| this.analytics = analytics; | ||
| this.scenesCache = scenesCache; | ||
|
|
||
| // Init is set before this subscription exists, so it can only be measured from the app start. | ||
| measures.Add(new StageMeasure | ||
| { | ||
| Stage = LoadingStatus.LoadingStage.Init, | ||
| StartTime = APP_START_TIME, | ||
| StopTime = APP_START_TIME, | ||
| }); | ||
|
|
||
| loadingStatus.CurrentStageMut.OnUpdate += OnStageUpdated; | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
|
lorenzo-ranciaffi marked this conversation as resolved.
|
||
| loadingStatus.CurrentStageMut.OnUpdate -= OnStageUpdated; | ||
| cts.SafeCancelAndDispose(); | ||
| } | ||
|
|
||
| private void OnStageUpdated(LoadingStatus.LoadingStage stage) | ||
| { | ||
| if (reportRequestFired) return; | ||
|
|
||
| AddSample(stage); | ||
|
|
||
| if (stage != LoadingStatus.LoadingStage.Completed) return; | ||
|
|
||
| reportRequestFired = true; | ||
| ReportAndQuitAsync(scenesCache.CurrentScene.Value?.Info.Name).Forget(); | ||
| } | ||
|
|
||
| private void AddSample(LoadingStatus.LoadingStage stage) | ||
| { | ||
| float time = UnityEngine.Time.realtimeSinceStartup; | ||
|
|
||
| StageMeasure previous = measures[^1]; | ||
|
lorenzo-ranciaffi marked this conversation as resolved.
|
||
| previous.StopTime = time; | ||
| measures[^1] = previous; | ||
|
|
||
| measures.Add(new StageMeasure | ||
| { | ||
| Stage = stage, | ||
| StartTime = time, | ||
| StopTime = time, | ||
| }); | ||
| } | ||
|
|
||
| private JObject PayloadSnapshot(string? sceneHash) | ||
| { | ||
| float stopTime = measures[^1].StopTime; | ||
|
|
||
| var payload = new JObject | ||
| { | ||
| { SCENE_HASH_LABEL, sceneHash }, | ||
| { PLATFORM_LABEL, PLATFORM_VALUE }, | ||
| { START_LABEL, APP_START_TIME }, | ||
| { STOP_LABEL, stopTime }, | ||
| { DURATION_LABEL, stopTime - APP_START_TIME }, | ||
| }; | ||
|
|
||
| foreach (StageMeasure measure in measures) | ||
| payload[$"{STAGE_PREFIX}{measure.Stage.ToString().ToLower()}"] = new JObject | ||
| { | ||
| { START_LABEL, measure.StartTime }, | ||
| { STOP_LABEL, measure.StopTime }, | ||
| { DURATION_LABEL, measure.StopTime - measure.StartTime }, | ||
| }; | ||
|
|
||
| return payload; | ||
| } | ||
|
|
||
| private async UniTaskVoid ReportAndQuitAsync(string? sceneHash) | ||
| { | ||
| try | ||
| { | ||
| JObject payload = PayloadSnapshot(sceneHash); | ||
|
|
||
| analytics.Track(AnalyticsEvents.Profiling.LOADING_TIMES, payload, true); | ||
| ReportHub.LogProductionInfo(payload.ToString()); | ||
|
|
||
| await UniTask.Delay(ANALYTICS_DELIVERY_GRACE, cancellationToken: cts.Token); | ||
| } | ||
| catch (OperationCanceledException) | ||
| { | ||
| // Disposal means the shutdown is already under way, quitting again would be redundant. | ||
| return; | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| ReportHub.LogException(e, ReportCategory.ANALYTICS); | ||
| } | ||
|
|
||
| ExitUtils.Exit(); | ||
| } | ||
|
|
||
| private struct StageMeasure | ||
| { | ||
| public LoadingStatus.LoadingStage Stage; | ||
| public float StartTime; | ||
| public float StopTime; | ||
| } | ||
| } | ||
| } | ||
3 changes: 3 additions & 0 deletions
3
Explorer/Assets/DCL/PerformanceAndDiagnostics/LoadingTimes/LoadingTimeBenchmark.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.