Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
[browser] samplepoint instrumentation into Mono profiler#112352
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
3417db1449be73e7ae514b5df7cd8134a3cf86d001ea00205ea8bf7f07b79f735beefcba8528b388647b271c7f5fe2ac7e147ff0e4be7e98a3d753be65b4d88cef96deae960282584cea9d2a8427e5489d517eb7cf07bc2c2fc83ee00fc071c8c0aba1ba8e883b49cdFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -90,6 +90,7 @@ function injectDependencies() { | ||
| `enablePerfTracing: ${FEATURE_PERFTRACING ? "true" : "false"}, ` + | ||
| `enableAotProfiler: ${ENABLE_AOT_PROFILER ? "true" : "false"}, ` + | ||
| `enableBrowserProfiler: ${ENABLE_BROWSER_PROFILER ? "true" : "false"}, ` + | ||
| `enablePerfTracing: ${ENABLE_BROWSER_PROFILER ? "true" : "false"}, ` + | ||
pavelsavara marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| `enableLogProfiler: ${ENABLE_LOG_PROFILER ? "true" : "false"}, ` + | ||
| `runAOTCompilation: ${RUN_AOT_COMPILATION ? "true" : "false"}, ` + | ||
| `wasmEnableThreads: ${USE_PTHREADS ? "true" : "false"}, ` + | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,6 +7,7 @@ import { ENVIRONMENT_IS_WEB, mono_assert, runtimeHelpers } from "./globals"; | ||
| import { MonoMethod, AOTProfilerOptions, BrowserProfilerOptions, LogProfilerOptions } from "./types/internal"; | ||
| import { profiler_c_functions as cwraps } from "./cwraps"; | ||
| import { utf8ToString } from "./strings"; | ||
| import { free } from "./memory"; | ||
| // Initialize the AOT profiler with OPTIONS. | ||
| // Requires the AOT profiler to be linked into the app. | ||
| @@ -32,7 +33,13 @@ export function mono_wasm_init_browser_profiler (options: BrowserProfilerOptions | ||
| mono_assert(runtimeHelpers.emscriptenBuildOptions.enableBrowserProfiler, "Browser profiler is not enabled, please use <WasmProfilers>browser;</WasmProfilers> in your project file."); | ||
| if (options == null) | ||
| options = {}; | ||
| const arg = "browser:"; | ||
| let arg = "browser:"; | ||
| if (typeof options.callSpec === "string") { | ||
| arg += `callspec=${options.callSpec},`; | ||
| } | ||
| if (typeof options.sampleIntervalMs === "number") { | ||
| arg += `interval=${options.sampleIntervalMs},`; | ||
| } | ||
| cwraps.mono_wasm_profiler_init_browser(arg); | ||
| } | ||
| @@ -76,6 +83,7 @@ export function startMeasure (): TimeStamp { | ||
| export function endMeasure (start: TimeStamp, block: string, id?: string) { | ||
| if (runtimeHelpers.enablePerfMeasure && start) { | ||
| // API is slightly different between web and Nodejs | ||
| const options = ENVIRONMENT_IS_WEB | ||
| ? { start: start as any } | ||
| : { startTime: start as any }; | ||
| @@ -84,28 +92,27 @@ export function endMeasure (start: TimeStamp, block: string, id?: string) { | ||
| } | ||
| } | ||
| const stackFrames: number[] = []; | ||
| export function mono_wasm_profiler_enter (): void { | ||
| if (runtimeHelpers.enablePerfMeasure) { | ||
| stackFrames.push(globalThis.performance.now()); | ||
| } | ||
| export function mono_wasm_profiler_now (): number { | ||
| return globalThis.performance.now(); | ||
| } | ||
| export function mono_wasm_profiler_free_method (method: MonoMethod): void { | ||
| methodNames.delete(method as any); | ||
| } | ||
| const methodNames: Map<number, string> = new Map(); | ||
| export function mono_wasm_profiler_leave (method: MonoMethod): void { | ||
| if (runtimeHelpers.enablePerfMeasure) { | ||
| const start = stackFrames.pop(); | ||
| const options = ENVIRONMENT_IS_WEB | ||
| ? { start: start } | ||
| : { startTime: start }; | ||
| let methodName = methodNames.get(method as any); | ||
| if (!methodName) { | ||
| const chars = cwraps.mono_wasm_method_get_name(method); | ||
| methodName = utf8ToString(chars); | ||
| methodNames.set(method as any, methodName); | ||
| } | ||
| globalThis.performance.measure(methodName, options); | ||
| export function mono_wasm_profiler_record (method: MonoMethod, start: number): void { | ||
| const options = ENVIRONMENT_IS_WEB | ||
pavelsavara marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ? { start: start } | ||
| : { startTime: start }; | ||
| let methodName = methodNames.get(method as any); | ||
| if (!methodName) { | ||
| const chars = cwraps.mono_wasm_method_get_name_ex(method); | ||
| methodName = utf8ToString(chars); | ||
| methodNames.set(method as any, methodName); | ||
pavelsavara marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| free(chars as any); | ||
| } | ||
| globalThis.performance.measure(methodName, options); | ||
| } | ||
| /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
If you hand out ownership of this pointer and expect others to free it, it shouldn't be const.