Skip to content

Conversation

@pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Jul 2, 2025

Fixes regression caused by #112352 that breaks --trace on mono VM.
Root cause is stack allocation inside of a loop for emit_fill_call_ctx of new SAMPLEPOINT_CONTEXT profiler event.

That event is not necessary for any of the other scenarios. And also samplepoint is not interesting trace event.

Fix

  • don't emit samplepoint for traces
  • remove bad implementation of SAMPLEPOINT_CONTEXT from mini_profiler_emit_samplepoint

@pavelsavara pavelsavara added this to the 10.0.0 milestone Jul 2, 2025
@pavelsavara pavelsavara requested a review from BrzVlad July 2, 2025 16:28
@pavelsavara pavelsavara self-assigned this Jul 2, 2025
@Copilot Copilot AI review requested due to automatic review settings July 2, 2025 16:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses a regression in the --trace option by adjusting the profiler instrumentation flags set during JIT compilation.

  • Removed samplepoint-related flags from cfg->prof_flags when --trace is enabled.
  • Ensures only enter/leave instrumentation is active under --trace.
Comments suppressed due to low confidence (2)

src/mono/mono/mini/mini.c:3456

  • Add a unit or integration test that verifies enabling --trace produces exactly the expected prof_flags (ENTER, ENTER_CONTEXT, LEAVE, LEAVE_CONTEXT) to guard against future regressions in flag composition.
	if (trace)

src/mono/mono/mini/mini.c:3458

  • [nitpick] Add or update a comment explaining why the samplepoint instrumentation flags were removed under --trace to clarify the intent for future maintainers.
			MONO_PROFILER_CALL_INSTRUMENTATION_ENTER | MONO_PROFILER_CALL_INSTRUMENTATION_ENTER_CONTEXT |

@BrzVlad
Copy link
Member

BrzVlad commented Jul 2, 2025

Could you add a small explanation for this ? Is tracing simply incompatible with samplepoint instrumentation ?

@pavelsavara
Copy link
Member Author

Could you add a small explanation for this ? Is tracing simply incompatible with samplepoint instrumentation ?

We discovered that the root cause it that MONO_PROFILER_CALL_INSTRUMENTATION_SAMPLEPOINT_CONTEXT allocates on the via emit_fill_call_ctx stack via localloc inside of the loop. Implementing it properly would take some effort.

Because the SAMPLEPOINT_CONTEXT feature is only new in Net10 previews and it's not used by the browser profiler, we could remove that instruction type.

@BrzVlad
Copy link
Member

BrzVlad commented Jul 3, 2025

Does MONO_PROFILER_CALL_INSTRUMENTATION_SAMPLEPOINT_CONTEXT still need to exist ? How exactly is it superior to the standard samplepoint instrumentation ?

@pavelsavara
Copy link
Member Author

Does MONO_PROFILER_CALL_INSTRUMENTATION_SAMPLEPOINT_CONTEXT still need to exist ? How exactly is it superior to the standard samplepoint instrumentation ?

It only needs to exist for the INTERP_PROFILER_RAISE macro to stay simple. Alternatively we could copy&paste that macro and make version without _CONTEXT concatenation. Do you prefer that ?

@BrzVlad
Copy link
Member

BrzVlad commented Jul 3, 2025

Yes, I would prefer to have it removed if it's an option that will not be used

@pavelsavara pavelsavara enabled auto-merge (squash) July 4, 2025 08:36
@pavelsavara
Copy link
Member Author

image

@pavelsavara
Copy link
Member Author

/ba-g CI timeouts

@pavelsavara pavelsavara merged commit 0dde205 into dotnet:main Jul 4, 2025
149 of 176 checks passed
@pavelsavara pavelsavara deleted the mono_fix_trace branch July 4, 2025 10:31
@github-actions github-actions bot locked and limited conversation to collaborators Aug 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants