Skip to content

Commit f0b32c1

Browse files
[release/10.0-preview5][browser] EP profiler - identify top frame, positive PID (#115906)
* wip * make PID always positive, to fix VS issue --------- Co-authored-by: pavelsavara <[email protected]>
1 parent 99a4b70 commit f0b32c1

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

src/mono/browser/runtime/diagnostics/diagnostics-js.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ class DiagnosticSession extends DiagnosticConnectionBase implements IDiagnosticC
121121
if (this.diagClient?.onClose) {
122122
this.diagClient.onClose(this.messagesToSend);
123123
}
124+
if (this.diagClient?.onClosePromise) {
125+
this.diagClient.onClosePromise.resolve(this.messagesToSend);
126+
}
124127
if (this.messagesToSend.length === 0) {
125128
return 0;
126129
}

src/mono/browser/runtime/startup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import { runtimeList } from "./exports";
3434
import { nativeAbort, nativeExit } from "./run";
3535
import { replaceEmscriptenPThreadInit } from "./pthreads/worker-thread";
3636

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

3940
export function mono_wasm_process_current_pid ():number {
4041
return pid;

src/mono/mono/eventpipe/ep-rt-mono-runtime-provider.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ sample_current_thread_stack_trace ()
13801380
mono_jit_info_table_find_internal ((gpointer)data->stack_contents.stack_frames [frame_count], TRUE, FALSE);
13811381
}
13821382
uint32_t payload_data = ep_rt_val_uint32_t (data->payload_data);
1383-
ep_write_sample_profile_event (current_sampling_thread, current_sampling_event, NULL, &data->stack_contents, (uint8_t *)&payload_data, sizeof (payload_data));
1383+
ep_write_sample_profile_event (current_sampling_thread, current_sampling_event, current_sampling_thread, &data->stack_contents, (uint8_t *)&payload_data, sizeof (payload_data));
13841384
}
13851385
}
13861386

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

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

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

14121412
static double desired_sample_interval_ms;

src/mono/mono/mini/interp/interp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3960,9 +3960,12 @@ mono_interp_profiler_raise_tail_call (InterpFrame *frame, MonoMethod *new_method
39603960
(frame->imethod->prof_flags & MONO_PROFILER_CALL_INSTRUMENTATION_ ## name_upper ## _CONTEXT ))) { \
39613961
if (flag & TRACING_FLAG) \
39623962
mono_interp_trace_with_ctx (frame, mono_trace_ ## name_lower ## _method); \
3963-
if (flag & PROFILING_FLAG) \
3963+
if (flag & PROFILING_FLAG) { \
3964+
frame->state.ip = ip; \
39643965
mono_interp_profiler_raise_with_ctx (frame, mono_profiler_raise_method_ ## name_lower); \
3966+
} \
39653967
} else if ((flag & PROFILING_FLAG) && MONO_PROFILER_ENABLED (method_ ## name_lower)) { \
3968+
frame->state.ip = ip; \
39663969
mono_interp_profiler_raise (frame, mono_profiler_raise_method_ ## name_lower); \
39673970
}
39683971

src/mono/sample/wasm/browser-eventpipe/Wasm.Browser.EventPipe.Sample.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<Import Project="..\DefaultBrowserSample.targets" />
33
<PropertyGroup>
44
<WasmPerfTracing>true</WasmPerfTracing>
5-
<WasmPerfInstrumentation>N:Sample</WasmPerfInstrumentation>
5+
<WasmPerfInstrumentation>all</WasmPerfInstrumentation>
66
<MetricsSupport>true</MetricsSupport>
77
<EventSourceSupport>true</EventSourceSupport>
88
<!--
99
<RunAOTCompilation>true</RunAOTCompilation>
10+
-->
1011
<WasmNativeDebugSymbols>true</WasmNativeDebugSymbols>
1112
<WasmNativeStrip>false</WasmNativeStrip>
12-
-->
1313

1414
</PropertyGroup>
1515
<ItemGroup>

0 commit comments

Comments
 (0)