[profiler] Profiler entry point name must now include the module name.
authorAlex Rønne Petersen <alexrp@xamarin.com>
Mon, 17 Jul 2017 20:43:42 +0000 (22:43 +0200)
committerAlex Rønne Petersen <alexrp@xamarin.com>
Mon, 17 Jul 2017 20:45:02 +0000 (22:45 +0200)
So mono_profiler_init becomes e.g. mono_profiler_init_log.

This allows us to link together multiple profilers into a single module and
load them selectively. This is especially useful for XA/XI/XM.

mono/metadata/profiler.c
mono/metadata/profiler.h
mono/profiler/aot.c
mono/profiler/iomap.c
mono/profiler/log.c
mono/profiler/vtune.c
msvc/mono-profiler-vtune.def
samples/profiler/sample.c
samples/size/size.c

index 536749ce254f7308a64cc12ca4534380e47284a7..33bac7e505ccb005e7ddc2deb8ba0503bb0ad319 100644 (file)
@@ -21,24 +21,16 @@ typedef void (*MonoProfilerInitializer) (const char *);
 #define NEW_INITIALIZER_NAME "mono_profiler_init"
 
 static gboolean
-load_profiler (MonoDl *module, const char *desc, const char *suffix)
+load_profiler (MonoDl *module, const char *name, const char *desc)
 {
        if (!module)
                return FALSE;
 
-       char *old_name;
-
-       if (suffix)
-               old_name = g_strdup_printf (OLD_INITIALIZER_NAME "_%s", suffix);
-       else
-               old_name = g_strdup_printf (OLD_INITIALIZER_NAME);
-
+       char *err, *old_name = g_strdup_printf (OLD_INITIALIZER_NAME);
        MonoProfilerInitializer func;
 
-       char *err;
-
        if (!(err = mono_dl_symbol (module, old_name, (gpointer) &func))) {
-               mono_profiler_printf_err ("Found old-style startup symbol %s for %s; profiler has not been migrated to the new API.", old_name, desc);
+               mono_profiler_printf_err ("Found old-style startup symbol '%s' for the '%s' profiler; it has not been migrated to the new API.", old_name, name);
                g_free (old_name);
                return FALSE;
        }
@@ -46,12 +38,7 @@ load_profiler (MonoDl *module, const char *desc, const char *suffix)
        g_free (err);
        g_free (old_name);
 
-       char *new_name;
-
-       if (suffix)
-               new_name = g_strdup_printf (NEW_INITIALIZER_NAME "_%s", suffix);
-       else
-               new_name = g_strdup_printf (NEW_INITIALIZER_NAME);
+       char *new_name = g_strdup_printf (NEW_INITIALIZER_NAME "_%s", name);
 
        if ((err = mono_dl_symbol (module, new_name, (gpointer *) &func))) {
                g_free (err);
@@ -67,7 +54,7 @@ load_profiler (MonoDl *module, const char *desc, const char *suffix)
 }
 
 static gboolean
-load_profiler_from_executable (const char *desc, const char *name)
+load_profiler_from_executable (const char *name, const char *desc)
 {
        char *err;
 
@@ -87,11 +74,11 @@ load_profiler_from_executable (const char *desc, const char *name)
                return FALSE;
        }
 
-       return load_profiler (module, desc, name);
+       return load_profiler (module, name, desc);
 }
 
 static gboolean
-load_profiler_from_directory (const char *directory, const char *libname, const char *desc)
+load_profiler_from_directory (const char *directory, const char *libname, const char *name, const char *desc)
 {
        char* path;
        void *iter = NULL;
@@ -103,14 +90,14 @@ load_profiler_from_directory (const char *directory, const char *libname, const
                g_free (path);
 
                if (module)
-                       return load_profiler (module, desc, NULL);
+                       return load_profiler (module, name, desc);
        }
 
        return FALSE;
 }
 
 static gboolean
-load_profiler_from_installation (const char *libname, const char *desc)
+load_profiler_from_installation (const char *libname, const char *name, const char *desc)
 {
        char *err;
        MonoDl *module = mono_dl_open_runtime_lib (libname, MONO_DL_EAGER, &err);
@@ -118,7 +105,7 @@ load_profiler_from_installation (const char *libname, const char *desc)
        g_free (err);
 
        if (module)
-               return load_profiler (module, desc, NULL);
+               return load_profiler (module, name, desc);
 
        return FALSE;
 }
@@ -138,15 +125,15 @@ mono_profiler_load (const char *desc)
        } else
                mname = g_strdup (desc);
 
-       if (!load_profiler_from_executable (desc, mname)) {
+       if (!load_profiler_from_executable (mname, desc)) {
                char *libname = g_strdup_printf ("mono-profiler-%s", mname);
-               gboolean res = load_profiler_from_installation (libname, desc);
+               gboolean res = load_profiler_from_installation (libname, mname, desc);
 
                if (!res && mono_config_get_assemblies_dir ())
-                       res = load_profiler_from_directory (mono_assembly_getrootdir (), libname, desc);
+                       res = load_profiler_from_directory (mono_assembly_getrootdir (), libname, mname, desc);
 
                if (!res)
-                       res = load_profiler_from_directory (NULL, libname, desc);
+                       res = load_profiler_from_directory (NULL, libname, mname, desc);
 
                if (!res)
                        mono_profiler_printf_err ("The '%s' profiler wasn't found in the main executable nor could it be loaded from '%s'.", mname, libname);
index 6dd1ea336335a0abcf290c4d67623d7f70ea6718..5063431bc8bf1b2ed2a7b21e5a8e0b8a007e78fd 100644 (file)
@@ -27,9 +27,9 @@ MONO_BEGIN_DECLS
  * the module after it has been loaded. If the specified module has already
  * been loaded, this function has no effect.
  *
- * A module should declare an entry point like so:
+ * A module called foo should declare an entry point like so:
  *
- * void mono_profiler_init (const char *desc)
+ * void mono_profiler_init_foo (const char *desc)
  * {
  * }
  *
index d8ee9101098f67d52d0bb356143ea6bae784e5e2..af8ca335c025520ed7bd817d680aa99fa1bac38c 100644 (file)
@@ -112,14 +112,14 @@ match_option (const char* p, const char *opt, char **rval)
 }
 
 void
-mono_profiler_init (const char *desc);
+mono_profiler_init_aot (const char *desc);
 
 /**
- * mono_profiler_init:
+ * mono_profiler_init_aot:
  * the entry point
  */
 void
-mono_profiler_init (const char *desc)
+mono_profiler_init_aot (const char *desc)
 {
        MonoProfiler *prof;
        const char *p;
index ff419be5d31f42bd5d4e17c1621de9062dc20916..c2b48fa3ee31d8c946e29a1ead9988d9cbc595ae 100644 (file)
@@ -92,7 +92,7 @@ static inline gchar *build_hint (SavedString *head);
 static inline gchar *build_hint_from_stack (MonoDomain *domain, void **stack, gint stack_entries);
 static inline void store_string_location (MonoProfiler *prof, const gchar *string, guint32 hash, size_t len);
 static void mono_portability_remember_string (MonoProfiler *prof, MonoDomain *domain, MonoString *str);
-void mono_profiler_init (const char *desc);
+void mono_profiler_init_iomap (const char *desc);
 
 static void mismatched_stats_foreach_func (gpointer key, gpointer value, gpointer user_data)
 {
@@ -531,7 +531,7 @@ static void profiler_shutdown (MonoProfiler *prof)
        mono_os_mutex_destroy (&mismatched_files_section);
 }
 
-void mono_profiler_init (const char *desc)
+void mono_profiler_init_iomap (const char *desc)
 {
        MonoProfiler *prof = g_new0 (MonoProfiler, 1);
 
index 847ee26184cb93824366892581ba1eee5685eeb6..acf02fc3c6a6c4fac46f705cc2dfe72820426beb 100644 (file)
@@ -4626,28 +4626,11 @@ create_profiler (const char *args, const char *filename, GPtrArray *filters)
        log_profiler.startup_time = current_time ();
 }
 
-/*
- * declaration to silence the compiler: this is the entry point that
- * mono will load from the shared library and call.
- */
-extern void
-mono_profiler_init (const char *desc);
-
-extern void
+MONO_API void
 mono_profiler_init_log (const char *desc);
 
-/*
- * this is the entry point that will be used when the profiler
- * is embedded inside the main executable.
- */
 void
 mono_profiler_init_log (const char *desc)
-{
-       mono_profiler_init (desc);
-}
-
-void
-mono_profiler_init (const char *desc)
 {
        GPtrArray *filters = NULL;
 
index 73148df47936ac2bc9a0432beadfddf0a71c9b8a..1f06bb81c8b3c44ac931127e7aa15000fd38fbae 100644 (file)
@@ -161,7 +161,7 @@ code_buffer_new (MonoProfiler *prof, void *buffer, int size, MonoProfilerCodeBuf
 
 /* the entry point */
 void
-mono_profiler_init (const char *desc)
+mono_profiler_init_vtune (const char *desc)
 {
        iJIT_IsProfilingActiveFlags flags = iJIT_IsProfilingActive();
        if (flags == iJIT_SAMPLING_ON)
index d189fbfb5e7c16b4e90bccdadb0c4ca3af709ad5..5463b53b3f8def9e80b47a5664b45c045bcf7695 100644 (file)
@@ -1,4 +1,4 @@
 ; file generated by create-windef.pl
 LIBRARY mono-profiler-vtune.dll
 EXPORTS
-mono_profiler_init
+mono_profiler_init_vtune
index 75e2f779590a3d43267625f2650644de75be969c..bd0ee4f552f53e8067716642f5ddc6edf97d09be 100644 (file)
@@ -43,7 +43,7 @@ sample_instrumentation_filter (MonoProfiler *prof, MonoMethod *method)
 
 /* the entry point */
 void
-mono_profiler_init (const char *desc)
+mono_profiler_init_sample (const char *desc)
 {
        MonoProfiler *prof;
 
index 86ec27dfd6da4fe6942232aa351e4003c6283b5f..40edb321a0a0d77695610bb74c567d3f50eabba5 100644 (file)
@@ -131,7 +131,7 @@ void install_icall (MonoProfiler *prof, MonoMethod *method, MonoJitInfo* jinfo)
 }
 
 void
-mono_profiler_init (const char *desc)
+mono_profiler_init_size (const char *desc)
 {
        MonoProfilerHandle handle = mono_profiler_install (NULL);
        mono_profiler_set_jit_done_callback (handle, install_icall);