From aa06797eb5c1c880c47280e366f2ba6764d82df5 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Sat, 13 Nov 2021 14:30:09 -0500 Subject: [PATCH] [mono] Add a 'inline_method' profiler event. (#61454) Emit it in the interpreter when a method is inlined or replaced with an intrinsic. This is needed so the AOT profiler can track these methods. --- src/mono/mono/metadata/profiler-events.h | 2 ++ src/mono/mono/mini/interp/transform.c | 11 +++++++++-- src/mono/mono/profiler/aot.c | 7 +++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/metadata/profiler-events.h b/src/mono/mono/metadata/profiler-events.h index c7ab3f66d516d..20300bff65f1c 100644 --- a/src/mono/mono/metadata/profiler-events.h +++ b/src/mono/mono/metadata/profiler-events.h @@ -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) diff --git a/src/mono/mono/mini/interp/transform.c b/src/mono/mono/mini/interp/transform.c index 476f98eecbe46..01012510aed28 100644 --- a/src/mono/mono/mini/interp/transform.c +++ b/src/mono/mono/mini/interp/transform.c @@ -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); @@ -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")) { @@ -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); @@ -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 */ @@ -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); diff --git a/src/mono/mono/profiler/aot.c b/src/mono/mono/profiler/aot.c index 71be9f1fdcaaa..7988d23b058d0 100644 --- a/src/mono/mono/profiler/aot.c +++ b/src/mono/mono/profiler/aot.c @@ -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) { @@ -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