Skip to content
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

[wasm-ep] Minimal diagnostic tracing configuration and sample #69158

Merged
merged 38 commits into from
May 19, 2022

Conversation

lambdageek
Copy link
Member

  • Adds a /p:WasmEnablePerfTracing=true configuration.

    In this configuration the runtime is built with threading (MonoWasmThreads property is true), but C# code is not allowed to start threads and doesn't use the portable thradpool (MonoWasmThreadsNoUser property is also true).

    The upshot is that EventPipe can start threads but user code is still single-threaded.

  • Adds a MONO.diagnostics interface in JavaScript. There's a single method for now createEventPipeSession which creates a session that can save a trace to a file on the virtual file system. JS code (or a user in a dev console) needs to call start() and stop() on the session object to begin collecting samples. For now there's no way to specify any configuration options other than the destination VFS file path for the trace file.

  • Adds a sample that runs an async task for five seconds and collects samples and then triggers a click() to download the trace file out of the browser.

@ghost
Copy link

ghost commented May 10, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details
  • Adds a /p:WasmEnablePerfTracing=true configuration.

    In this configuration the runtime is built with threading (MonoWasmThreads property is true), but C# code is not allowed to start threads and doesn't use the portable thradpool (MonoWasmThreadsNoUser property is also true).

    The upshot is that EventPipe can start threads but user code is still single-threaded.

  • Adds a MONO.diagnostics interface in JavaScript. There's a single method for now createEventPipeSession which creates a session that can save a trace to a file on the virtual file system. JS code (or a user in a dev console) needs to call start() and stop() on the session object to begin collecting samples. For now there's no way to specify any configuration options other than the destination VFS file path for the trace file.

  • Adds a sample that runs an async task for five seconds and collects samples and then triggers a click() to download the trace file out of the browser.

Author: lambdageek
Assignees: -
Labels:

arch-wasm, area-System.Diagnostics-mono

Milestone: -

@lambdageek
Copy link
Member Author

/cc @kg @lateralusX

@lambdageek
Copy link
Member Author

/cc @pavelsavara

@lambdageek lambdageek marked this pull request as ready for review May 10, 2022 20:50
two ways of retreiving the collected traces instead of exposing the
emscripten VFS directly.

Probably the Blob one is enough.  Is there any reason to also provide
a data URI?

update the sample to use URL.createObjectURL (session.getTraceBlob())
to create the download link
Copy link
Member

@lateralusX lateralusX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EventPipe bits looks good, just a couple of small comments/thoughts.

src/mono/mono/component/event_pipe-stub.c Outdated Show resolved Hide resolved
src/mono/mono/component/event_pipe-stub.c Outdated Show resolved Hide resolved
@lambdageek
Copy link
Member Author

Any other feedback?
/cc @lewing

@lambdageek
Copy link
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

globalThis.MONO = MONO;
console.log('after createDotnetRuntime')

const startWork = BINDING.bind_static_method("[Wasm.Browser.EventPipe.Sample] Sample.Test:StartAsyncWork");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we rely on the non-Main methods in the sample maybe just put a single line comment in Program.cs's Main to indicate that the reader should look in main.js for the juicy bits

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -114,3 +115,33 @@ export function getF32(offset: _MemOffset): number {
export function getF64(offset: _MemOffset): number {
return Module.HEAPF64[<any>offset >>> 3];
}

export function getCU64(offset: _MemOffset): cuint64.CUInt64 {
const lo = getI32(offset);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these actually be signed? It seems like they should be unsigned.

export declare type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use ArrayBufferView in place of this, though it has the downside of that interface inexplicably not having .length. Just an FYI, I'm fine with us defining a TypedArray alias (do the bigint arrays need to go in here too?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't change anything here. I think eslint just added or removed a newline.

@lambdageek
Copy link
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lewing lewing requested a review from radekdoulik May 18, 2022 15:17
Copy link
Member

@lewing lewing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@lambdageek lambdageek merged commit b15ff06 into dotnet:main May 19, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jun 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants