-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Blazor WebAssembly internal profiling infrastructure #23510
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 all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
92d7277
Infrastructure for capturing execution profile on JS side
SteveSandersonMS 0a3b07f
Capture some basic timings during DOM updates
SteveSandersonMS c2e17d4
Capturing coarsely-grained timings from .NET
SteveSandersonMS 79c9726
Capturing finely grained render process info in .NET
SteveSandersonMS 93b47d3
Refactor .NET-side code
SteveSandersonMS af23c76
Toggle capturing state in .NET from JS
SteveSandersonMS 22522cc
Only perform detailed .NET tracing when compiler flags are given
SteveSandersonMS 3c1abd7
Update src/Components/Components/src/Profiling/ComponentsProfiling.cs
SteveSandersonMS 420c852
Update nullability hint
SteveSandersonMS f1bf631
Should have included this in the previous commit
SteveSandersonMS c11ec27
Avoid error on server
SteveSandersonMS 6fba0cc
Avoid redundant comment
SteveSandersonMS 0b9b0dc
Update JS binaries
SteveSandersonMS 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
28 changes: 28 additions & 0 deletions
28
src/Components/Components/src/Profiling/ComponentsProfiling.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,28 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Microsoft.AspNetCore.Components.Profiling | ||
{ | ||
internal abstract class ComponentsProfiling | ||
{ | ||
// For now, this is only intended for use on Blazor WebAssembly, and will have no effect | ||
// when running on Blazor Server. The reason for having the ComponentsProfiling abstraction | ||
// is so that if we later have two different implementations (one for WebAssembly, one for | ||
// Server), the execution characteristics of calling Start/End will be unchanged and historical | ||
// perf data will still be comparable to newer data. | ||
public static readonly ComponentsProfiling Instance; | ||
|
||
static ComponentsProfiling() | ||
{ | ||
Instance = RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")) | ||
? new WebAssemblyComponentsProfiling() | ||
: (ComponentsProfiling)new NoOpComponentsProfiling(); | ||
} | ||
|
||
public abstract void Start([CallerMemberName] string? name = null); | ||
public abstract void End([CallerMemberName] string? name = null); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Components/Components/src/Profiling/NoOpComponentsProfiling.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,16 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.Components.Profiling | ||
{ | ||
internal class NoOpComponentsProfiling : ComponentsProfiling | ||
{ | ||
public override void Start(string? name) | ||
{ | ||
} | ||
|
||
public override void End(string? name) | ||
{ | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Components/Components/src/Profiling/WebAssemblyComponentsProfiling.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,41 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using WebAssembly.JSInterop; | ||
|
||
namespace Microsoft.AspNetCore.Components.Profiling | ||
{ | ||
// Later on, we will likely want to move this into the WebAssembly package. However it needs to | ||
// be inlined into the Components package directly until we're ready to make the underlying | ||
// ComponentsProfile abstraction into a public API. It's possible that this API will never become | ||
// public, or that it will be replaced by something more standard for .NET, if it's possible to | ||
// make that work performantly on WebAssembly. | ||
|
||
internal class WebAssemblyComponentsProfiling : ComponentsProfiling | ||
{ | ||
static bool IsCapturing = false; | ||
|
||
public static void SetCapturing(bool isCapturing) | ||
{ | ||
IsCapturing = isCapturing; | ||
} | ||
|
||
public override void Start(string? name) | ||
{ | ||
if (IsCapturing) | ||
{ | ||
InternalCalls.InvokeJSUnmarshalled<string, object, object, object>( | ||
out _, "_blazorProfileStart", name, null, null); | ||
} | ||
} | ||
|
||
public override void End(string? name) | ||
{ | ||
if (IsCapturing) | ||
{ | ||
InternalCalls.InvokeJSUnmarshalled<string, object, object, object>( | ||
out _, "_blazorProfileEnd", name, null, null); | ||
} | ||
} | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use
ProfilingStart
/ProfilingEnd
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I wanted to include this method in the coarse-grained timings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha! OK -- I see how this call is different now.