Skip to content

[browser] EP profiler - identify top frame, positive PID #115825

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 3 commits into from
May 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/mono/browser/runtime/diagnostics/diagnostics-js.ts
Original file line number Diff line number Diff line change
@@ -121,6 +121,9 @@ class DiagnosticSession extends DiagnosticConnectionBase implements IDiagnosticC
if (this.diagClient?.onClose) {
this.diagClient.onClose(this.messagesToSend);
}
if (this.diagClient?.onClosePromise) {
this.diagClient.onClosePromise.resolve(this.messagesToSend);
}
if (this.messagesToSend.length === 0) {
return 0;
}
3 changes: 2 additions & 1 deletion src/mono/browser/runtime/startup.ts
Original file line number Diff line number Diff line change
@@ -34,7 +34,8 @@ import { runtimeList } from "./exports";
import { nativeAbort, nativeExit } from "./run";
import { replaceEmscriptenPThreadInit } from "./pthreads/worker-thread";

const pid = (globalThis.performance?.timeOrigin ?? Date.now()) | 0;
// make pid positive 31bit integer based on startup time
const pid = ((globalThis.performance?.timeOrigin ?? Date.now()) | 0) & 0x7FFFFFFF;

export function mono_wasm_process_current_pid ():number {
return pid;
6 changes: 3 additions & 3 deletions src/mono/mono/eventpipe/ep-rt-mono-runtime-provider.c
Original file line number Diff line number Diff line change
@@ -1380,7 +1380,7 @@ sample_current_thread_stack_trace ()
mono_jit_info_table_find_internal ((gpointer)data->stack_contents.stack_frames [frame_count], TRUE, FALSE);
}
uint32_t payload_data = ep_rt_val_uint32_t (data->payload_data);
ep_write_sample_profile_event (current_sampling_thread, current_sampling_event, NULL, &data->stack_contents, (uint8_t *)&payload_data, sizeof (payload_data));
ep_write_sample_profile_event (current_sampling_thread, current_sampling_event, current_sampling_thread, &data->stack_contents, (uint8_t *)&payload_data, sizeof (payload_data));
}
}

@@ -1391,7 +1391,7 @@ ep_write_empty_profile_event ()
MonoThreadInfo *thread_info = mono_thread_info_current ();
SampleProfileStackWalkData stack_walk_data;
SampleProfileStackWalkData *data= &stack_walk_data;
MONO_INIT_CONTEXT_FROM_FUNC (&ctx, sample_current_thread_stack_trace);
MONO_INIT_CONTEXT_FROM_FUNC (&ctx, ep_write_empty_profile_event);

data->thread_id = ep_rt_thread_id_t_to_uint64_t (mono_thread_info_get_tid (thread_info));
data->thread_ip = (uintptr_t)MONO_CONTEXT_GET_IP (&ctx);
@@ -1406,7 +1406,7 @@ ep_write_empty_profile_event ()
data->payload_data = EP_SAMPLE_PROFILER_SAMPLE_TYPE_EXTERNAL;

uint32_t payload_data = ep_rt_val_uint32_t (data->payload_data);
ep_write_sample_profile_event (current_sampling_thread, current_sampling_event, NULL, &data->stack_contents, (uint8_t *)&payload_data, sizeof (payload_data));
ep_write_sample_profile_event (current_sampling_thread, current_sampling_event, current_sampling_thread, &data->stack_contents, (uint8_t *)&payload_data, sizeof (payload_data));
}

static double desired_sample_interval_ms;
5 changes: 4 additions & 1 deletion src/mono/mono/mini/interp/interp.c
Original file line number Diff line number Diff line change
@@ -3960,9 +3960,12 @@ mono_interp_profiler_raise_tail_call (InterpFrame *frame, MonoMethod *new_method
(frame->imethod->prof_flags & MONO_PROFILER_CALL_INSTRUMENTATION_ ## name_upper ## _CONTEXT ))) { \
if (flag & TRACING_FLAG) \
mono_interp_trace_with_ctx (frame, mono_trace_ ## name_lower ## _method); \
if (flag & PROFILING_FLAG) \
if (flag & PROFILING_FLAG) { \
frame->state.ip = ip; \
mono_interp_profiler_raise_with_ctx (frame, mono_profiler_raise_method_ ## name_lower); \
} \
} else if ((flag & PROFILING_FLAG) && MONO_PROFILER_ENABLED (method_ ## name_lower)) { \
frame->state.ip = ip; \
mono_interp_profiler_raise (frame, mono_profiler_raise_method_ ## name_lower); \
}

Original file line number Diff line number Diff line change
@@ -2,14 +2,14 @@
<Import Project="..\DefaultBrowserSample.targets" />
<PropertyGroup>
<WasmPerfTracing>true</WasmPerfTracing>
<WasmPerfInstrumentation>N:Sample</WasmPerfInstrumentation>
<WasmPerfInstrumentation>all</WasmPerfInstrumentation>
<MetricsSupport>true</MetricsSupport>
<EventSourceSupport>true</EventSourceSupport>
<!--
<RunAOTCompilation>true</RunAOTCompilation>
-->
<WasmNativeDebugSymbols>true</WasmNativeDebugSymbols>
<WasmNativeStrip>false</WasmNativeStrip>
-->

</PropertyGroup>
<ItemGroup>
Loading
Oops, something went wrong.