Skip to content

Commit aa06797

Browse files
authored
[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.
1 parent 26a6f55 commit aa06797

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/mono/mono/metadata/profiler-events.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,5 @@ MONO_PROFILER_EVENT_1(thread_exited, ThreadExited, uintptr_t, tid)
106106
MONO_PROFILER_EVENT_2(thread_name, ThreadName, uintptr_t, tid, const char *, name)
107107

108108
MONO_PROFILER_EVENT_2(sample_hit, SampleHit, const mono_byte *, ip, const void *, context)
109+
110+
MONO_PROFILER_EVENT_2(inline_method, InlineMethod, MonoMethod *, method, MonoMethod *, inlined_method)

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,6 +2936,7 @@ interp_inline_method (TransformData *td, MonoMethod *target_method, MonoMethodHe
29362936
td->last_ins->next = NULL;
29372937
UnlockedIncrement (&mono_interp_stats.inline_failures);
29382938
} else {
2939+
MONO_PROFILER_RAISE (inline_method, (td->rtm->method, target_method));
29392940
if (td->verbose_level)
29402941
g_print ("Inline end method %s.%s\n", m_class_get_name (target_method->klass), target_method->name);
29412942
UnlockedIncrement (&mono_interp_stats.inlined_methods);
@@ -3240,8 +3241,10 @@ interp_transform_call (TransformData *td, MonoMethod *method, MonoMethod *target
32403241
}
32413242

32423243
/* Intrinsics */
3243-
if (target_method && interp_handle_intrinsics (td, target_method, constrained_class, csignature, readonly, &op))
3244+
if (target_method && interp_handle_intrinsics (td, target_method, constrained_class, csignature, readonly, &op)) {
3245+
MONO_PROFILER_RAISE (inline_method, (td->rtm->method, target_method));
32443246
return TRUE;
3247+
}
32453248

32463249
if (constrained_class) {
32473250
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
32693272
g_print (" : %s::%s. %s (%p)\n", target_method->klass->name, target_method->name, mono_signature_full_name (target_method->signature), target_method);
32703273
#endif
32713274
/* Intrinsics: Try again, it could be that `mono_get_method_constrained_with_method` resolves to a method that we can substitute */
3272-
if (target_method && interp_handle_intrinsics (td, target_method, constrained_class, csignature, readonly, &op))
3275+
if (target_method && interp_handle_intrinsics (td, target_method, constrained_class, csignature, readonly, &op)) {
3276+
MONO_PROFILER_RAISE (inline_method, (td->rtm->method, target_method));
32733277
return TRUE;
3278+
}
32743279

32753280
return_val_if_nok (error, FALSE);
32763281
mono_class_setup_vtable (target_method->klass);
@@ -5770,6 +5775,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
57705775
!strcmp (m_class_get_name (m->klass), "ByReference`1") &&
57715776
!strcmp (m->name, ".ctor")) {
57725777
/* public ByReference(ref T value) */
5778+
MONO_PROFILER_RAISE (inline_method, (td->rtm->method, m));
57735779
g_assert (csignature->hasthis && csignature->param_count == 1);
57745780
td->sp--;
57755781
/* 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,
57845790
csignature->params [0]->type == MONO_TYPE_PTR &&
57855791
!type_has_references (mono_method_get_context (m)->class_inst->type_argv [0])) {
57865792
/* ctor frequently used with ReadOnlySpan over static arrays */
5793+
MONO_PROFILER_RAISE (inline_method, (td->rtm->method, m));
57875794
interp_add_ins (td, MINT_INTRINS_SPAN_CTOR);
57885795
td->sp -= 2;
57895796
interp_ins_set_sregs2 (td->last_ins, td->sp [0].local, td->sp [1].local);

src/mono/mono/profiler/aot.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ prof_jit_done (MonoProfiler *prof, MonoMethod *method, MonoJitInfo *jinfo)
8181
mono_os_mutex_unlock (&prof->mutex);
8282
}
8383

84+
static void
85+
prof_inline_method (MonoProfiler *prof, MonoMethod *method, MonoMethod *inlined_method)
86+
{
87+
prof_jit_done (prof, inlined_method, NULL);
88+
}
89+
8490
static void
8591
usage (void)
8692
{
@@ -396,6 +402,7 @@ mono_profiler_init_aot (const char *desc)
396402
MonoProfilerHandle handle = mono_profiler_create (&aot_profiler);
397403
mono_profiler_set_runtime_initialized_callback (handle, runtime_initialized);
398404
mono_profiler_set_jit_done_callback (handle, prof_jit_done);
405+
mono_profiler_set_inline_method_callback (handle, prof_inline_method);
399406
}
400407

401408
static void

0 commit comments

Comments
 (0)