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

[mono] Add a 'inline_method' profiler event. #61454

Merged
merged 1 commit into from
Nov 13, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/mono/mono/metadata/profiler-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,5 @@ MONO_PROFILER_EVENT_1(thread_exited, ThreadExited, uintptr_t, tid)
MONO_PROFILER_EVENT_2(thread_name, ThreadName, uintptr_t, tid, const char *, name)

MONO_PROFILER_EVENT_2(sample_hit, SampleHit, const mono_byte *, ip, const void *, context)

MONO_PROFILER_EVENT_2(inline_method, InlineMethod, MonoMethod *, method, MonoMethod *, inlined_method)
11 changes: 9 additions & 2 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -2936,6 +2936,7 @@ interp_inline_method (TransformData *td, MonoMethod *target_method, MonoMethodHe
td->last_ins->next = NULL;
UnlockedIncrement (&mono_interp_stats.inline_failures);
} else {
MONO_PROFILER_RAISE (inline_method, (td->rtm->method, target_method));
if (td->verbose_level)
g_print ("Inline end method %s.%s\n", m_class_get_name (target_method->klass), target_method->name);
UnlockedIncrement (&mono_interp_stats.inlined_methods);
Expand Down Expand Up @@ -3240,8 +3241,10 @@ interp_transform_call (TransformData *td, MonoMethod *method, MonoMethod *target
}

/* Intrinsics */
if (target_method && interp_handle_intrinsics (td, target_method, constrained_class, csignature, readonly, &op))
if (target_method && interp_handle_intrinsics (td, target_method, constrained_class, csignature, readonly, &op)) {
MONO_PROFILER_RAISE (inline_method, (td->rtm->method, target_method));
return TRUE;
}

if (constrained_class) {
if (m_class_is_enumtype (constrained_class) && !strcmp (target_method->name, "GetHashCode")) {
Expand Down Expand Up @@ -3269,8 +3272,10 @@ interp_transform_call (TransformData *td, MonoMethod *method, MonoMethod *target
g_print (" : %s::%s. %s (%p)\n", target_method->klass->name, target_method->name, mono_signature_full_name (target_method->signature), target_method);
#endif
/* Intrinsics: Try again, it could be that `mono_get_method_constrained_with_method` resolves to a method that we can substitute */
if (target_method && interp_handle_intrinsics (td, target_method, constrained_class, csignature, readonly, &op))
if (target_method && interp_handle_intrinsics (td, target_method, constrained_class, csignature, readonly, &op)) {
MONO_PROFILER_RAISE (inline_method, (td->rtm->method, target_method));
return TRUE;
}

return_val_if_nok (error, FALSE);
mono_class_setup_vtable (target_method->klass);
Expand Down Expand Up @@ -5770,6 +5775,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
!strcmp (m_class_get_name (m->klass), "ByReference`1") &&
!strcmp (m->name, ".ctor")) {
/* public ByReference(ref T value) */
MONO_PROFILER_RAISE (inline_method, (td->rtm->method, m));
g_assert (csignature->hasthis && csignature->param_count == 1);
td->sp--;
/* We already have the vt on top of the stack. Just do a dummy mov that should be optimized out */
Expand All @@ -5784,6 +5790,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
csignature->params [0]->type == MONO_TYPE_PTR &&
!type_has_references (mono_method_get_context (m)->class_inst->type_argv [0])) {
/* ctor frequently used with ReadOnlySpan over static arrays */
MONO_PROFILER_RAISE (inline_method, (td->rtm->method, m));
interp_add_ins (td, MINT_INTRINS_SPAN_CTOR);
td->sp -= 2;
interp_ins_set_sregs2 (td->last_ins, td->sp [0].local, td->sp [1].local);
Expand Down
7 changes: 7 additions & 0 deletions src/mono/mono/profiler/aot.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ prof_jit_done (MonoProfiler *prof, MonoMethod *method, MonoJitInfo *jinfo)
mono_os_mutex_unlock (&prof->mutex);
}

static void
prof_inline_method (MonoProfiler *prof, MonoMethod *method, MonoMethod *inlined_method)
{
prof_jit_done (prof, inlined_method, NULL);
}

static void
usage (void)
{
Expand Down Expand Up @@ -396,6 +402,7 @@ mono_profiler_init_aot (const char *desc)
MonoProfilerHandle handle = mono_profiler_create (&aot_profiler);
mono_profiler_set_runtime_initialized_callback (handle, runtime_initialized);
mono_profiler_set_jit_done_callback (handle, prof_jit_done);
mono_profiler_set_inline_method_callback (handle, prof_inline_method);
}

static void
Expand Down