From 2e449ae1995d1ffec5e6efe4d616938715f8ca69 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 17 Jul 2017 22:43:42 +0200 Subject: [PATCH] [profiler] Profiler entry point name must now include the module name. 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 | 41 ++++++++++++------------------------ mono/metadata/profiler.h | 4 ++-- mono/profiler/aot.c | 6 +++--- mono/profiler/iomap.c | 4 ++-- mono/profiler/log.c | 19 +---------------- mono/profiler/vtune.c | 2 +- msvc/mono-profiler-vtune.def | 2 +- samples/profiler/sample.c | 2 +- samples/size/size.c | 2 +- 9 files changed, 26 insertions(+), 56 deletions(-) diff --git a/mono/metadata/profiler.c b/mono/metadata/profiler.c index 536749ce254..33bac7e505c 100644 --- a/mono/metadata/profiler.c +++ b/mono/metadata/profiler.c @@ -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); diff --git a/mono/metadata/profiler.h b/mono/metadata/profiler.h index 6dd1ea33633..5063431bc8b 100644 --- a/mono/metadata/profiler.h +++ b/mono/metadata/profiler.h @@ -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) * { * } * diff --git a/mono/profiler/aot.c b/mono/profiler/aot.c index d8ee9101098..af8ca335c02 100644 --- a/mono/profiler/aot.c +++ b/mono/profiler/aot.c @@ -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; diff --git a/mono/profiler/iomap.c b/mono/profiler/iomap.c index ff419be5d31..c2b48fa3ee3 100644 --- a/mono/profiler/iomap.c +++ b/mono/profiler/iomap.c @@ -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); diff --git a/mono/profiler/log.c b/mono/profiler/log.c index 847ee26184c..acf02fc3c6a 100644 --- a/mono/profiler/log.c +++ b/mono/profiler/log.c @@ -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; diff --git a/mono/profiler/vtune.c b/mono/profiler/vtune.c index 73148df4793..1f06bb81c8b 100644 --- a/mono/profiler/vtune.c +++ b/mono/profiler/vtune.c @@ -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) diff --git a/msvc/mono-profiler-vtune.def b/msvc/mono-profiler-vtune.def index d189fbfb5e7..5463b53b3f8 100644 --- a/msvc/mono-profiler-vtune.def +++ b/msvc/mono-profiler-vtune.def @@ -1,4 +1,4 @@ ; file generated by create-windef.pl LIBRARY mono-profiler-vtune.dll EXPORTS -mono_profiler_init +mono_profiler_init_vtune diff --git a/samples/profiler/sample.c b/samples/profiler/sample.c index 75e2f779590..bd0ee4f552f 100644 --- a/samples/profiler/sample.c +++ b/samples/profiler/sample.c @@ -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; diff --git a/samples/size/size.c b/samples/size/size.c index 86ec27dfd6d..40edb321a0a 100644 --- a/samples/size/size.c +++ b/samples/size/size.c @@ -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); -- 2.25.1