From 81dc899734004989cfe0133894989b4ad8dbdd20 Mon Sep 17 00:00:00 2001 From: monojenkins Date: Tue, 13 Oct 2020 08:13:45 -0400 Subject: [PATCH] Simplify enabling profiler support for embedders. (#43173) Adding --profile argument to mono_jit_parse_options. Can be used when embedding and not using parsing in driver.c. Add env variable MONO_PROFILE adding another possibility to pass profiler arguments to runtime. Co-authored-by: lateralusX --- src/mono/mono/mini/driver.c | 4 ++++ src/mono/mono/mini/mini-runtime.c | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/mini/driver.c b/src/mono/mono/mini/driver.c index 1b5c8f6..e7e0ed5 100644 --- a/src/mono/mono/mini/driver.c +++ b/src/mono/mono/mini/driver.c @@ -1882,6 +1882,10 @@ mono_jit_parse_options (int argc, char * argv[]) #else mono_use_llvm = TRUE; #endif + } else if (strcmp (argv [i], "--profile") == 0) { + mini_add_profiler_argument (NULL); + } else if (strncmp (argv [i], "--profile=", 10) == 0) { + mini_add_profiler_argument (argv [i] + 10); } else if (argv [i][0] == '-' && argv [i][1] == '-' && mini_parse_debug_option (argv [i] + 2)) { } else { fprintf (stderr, "Unsupported command line option: '%s'\n", argv [i]); diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index 4459b86..dd6f0e9 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -4309,7 +4309,7 @@ mini_add_profiler_argument (const char *desc) if (!profile_options) profile_options = g_ptr_array_new (); - g_ptr_array_add (profile_options, (gpointer) desc); + g_ptr_array_add (profile_options, (gpointer) g_strdup (desc)); } @@ -4563,6 +4563,12 @@ mini_init (const char *filename, const char *runtime_version) mono_profiler_state.context_get_result = mini_profiler_context_get_result; mono_profiler_state.context_free_buffer = mini_profiler_context_free_buffer; + if (g_hasenv ("MONO_PROFILE")) { + gchar *profile_env = g_getenv ("MONO_PROFILE"); + mini_add_profiler_argument (profile_env); + g_free (profile_env); + } + if (profile_options) for (guint i = 0; i < profile_options->len; i++) mono_profiler_load ((const char *) g_ptr_array_index (profile_options, i)); @@ -5083,8 +5089,11 @@ mini_cleanup (MonoDomain *domain) mono_profiler_cleanup (); - if (profile_options) + if (profile_options) { + for (guint i = 0; i < profile_options->len; ++i) + g_free (g_ptr_array_index (profile_options, i)); g_ptr_array_free (profile_options, TRUE); + } mono_icall_cleanup (); -- 2.7.4