[mini] Initialize profiler in mini_init
authorAleksey Kliger <aleksey@xamarin.com>
Thu, 12 Jan 2017 18:48:15 +0000 (13:48 -0500)
committerAleksey Kliger (λgeek) <akliger@gmail.com>
Thu, 12 Jan 2017 20:31:20 +0000 (15:31 -0500)
Initializing the profiler later fixes a segfault with cooperative GC due to
thread info callbacks not being initialized.

mono/mini/driver.c
mono/mini/mini-runtime.c
mono/mini/mini.h

index 382246ff84bb7079ef90967c1f75fac7dffaa9f6..590607889fdd5451339d89c61b2e420cc90de2d8 100644 (file)
@@ -2013,8 +2013,7 @@ mono_main (int argc, char* argv[])
        mono_set_rootdir ();
 
        if (enable_profile) {
-               mono_profiler_load (profile_options);
-               mono_profiler_thread_name (MONO_NATIVE_THREAD_ID_TO_UINT (mono_native_thread_id_get ()), "Main");
+               mini_profiler_enable_with_options (profile_options);
        }
 
        mono_attach_parse_options (attach_options);
index 72b6df1f747c65d5a2ca5b04f59f7a7f11bccc22..3c006958f96ec51fad025b1cc88a52361fc6535d 100644 (file)
@@ -126,10 +126,16 @@ int valgrind_register;
 #endif
 GList* mono_aot_paths;
 
+static gboolean mini_enable_profiler = FALSE;
+static char* mini_profiler_options = NULL;
+
 static GSList *tramp_infos;
 
 static void register_icalls (void);
 
+static gboolean mini_profiler_enabled (void) { return mini_enable_profiler; }
+static const char* mini_profiler_get_options (void) {  return mini_profiler_options;  }
+
 gboolean
 mono_running_on_valgrind (void)
 {
@@ -3478,6 +3484,13 @@ mini_llvm_init (void)
 #endif
 }
 
+void
+mini_profiler_enable_with_options (const char* profile_options)
+{
+       mini_enable_profiler = TRUE;
+       mini_profiler_options = g_strdup (profile_options);
+}
+
 MonoDomain *
 mini_init (const char *filename, const char *runtime_version)
 {
@@ -3640,6 +3653,11 @@ mini_init (const char *filename, const char *runtime_version)
        mono_install_get_class_from_name (mono_aot_get_class_from_name);
        mono_install_jit_info_find_in_aot (mono_aot_find_jit_info);
 
+       if (mini_profiler_enabled ()) {
+               mono_profiler_load (mini_profiler_get_options ());
+               mono_profiler_thread_name (MONO_NATIVE_THREAD_ID_TO_UINT (mono_native_thread_id_get ()), "Main");
+       }
+
        if (debug_options.collect_pagefault_stats)
                mono_aot_set_make_unreadable (TRUE);
 
index 236c5528286c6fd4e75435dc378d7119275a75dc..568caffb40d89a28a3070712e7206d3a5ace6cdb 100644 (file)
@@ -2334,6 +2334,7 @@ MonoDomain* mini_init                      (const char *filename, const char *ru
 void        mini_cleanup                   (MonoDomain *domain);
 MONO_API MonoDebugOptions *mini_get_debug_options   (void);
 MONO_API gboolean    mini_parse_debug_option (const char *option);
+void        mini_profiler_enable_with_options (const char *profile_options);
 
 /* graph dumping */
 void mono_cfg_dump_create_context (MonoCompile *cfg);