From a59a008bf7a5bdbdbf53909000307e51076b17f0 Mon Sep 17 00:00:00 2001 From: Andi McClure Date: Fri, 1 Apr 2016 15:39:38 -0400 Subject: [PATCH] Continued profiler loading cleanup (PR#2816 follow up) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - Back out MONO_PROFILER_LIB_DIR change - Profiler loading traces should use log mask “dll” not “asm” - mono_dl_open_runtime_lib should preempt standard paths when loading profiler - mono_dl_open_runtime_lib should check in profiler library directory - mono_dl_open_runtime_lib contained a memory leak - With above changes, ptestrunner.pl can remove some environment massaging --- man/mono.1 | 8 +------- mono/metadata/profiler.c | 14 ++++++-------- mono/profiler/ptestrunner.pl | 1 - mono/utils/mono-dl.c | 15 +++++++++++---- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/man/mono.1 b/man/mono.1 index f0df69e7e01..4c0d27d949b 100644 --- a/man/mono.1 +++ b/man/mono.1 @@ -786,8 +786,7 @@ to Mono, like this: .PP In the above sample Mono will load the user defined profiler from the shared library `mono-profiler-custom.so'. This profiler module must -be on your dynamic linker library path, or in the MONO_PROFILER_LIB_DIR -path (see "RUNTIME OPTIONS" below). +be on your dynamic linker library path. .PP A list of other third party profilers is available from Mono's web site (www.mono-project.com/docs/advanced/performance-tips/) @@ -1509,11 +1508,6 @@ For a complete description of recommended practices for application deployment, see http://www.mono-project.com/docs/getting-started/application-deployment/ .TP -\fBMONO_PROFILER_LIB_DIR\fR -Provides a search path to the runtime where to look for custom profilers. See the -section "CUSTOM PROFILERS" above for more information. Custom profilers will be -searched for in the MONO_PROFILER_LIB_DIR path before the standard library paths. -.TP \fBMONO_SHARED_DIR\fR If set its the directory where the ".wapi" handle state is stored. This is the directory where the Windows I/O Emulation layer stores its diff --git a/mono/metadata/profiler.c b/mono/metadata/profiler.c index d74a273d085..bb8579e7ad9 100644 --- a/mono/metadata/profiler.c +++ b/mono/metadata/profiler.c @@ -1161,6 +1161,7 @@ load_embedded_profiler (const char *desc, const char *name) return result; } +// TODO: Much of the library loading code here is custom. It would be better to merge this with mono-dl static gboolean load_profiler_from_directory (const char *directory, const char *libname, const char *desc) { @@ -1169,13 +1170,13 @@ load_profiler_from_directory (const char *directory, const char *libname, const char *err; void *iter; - mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY, "Attempting to load profiler %s from %s (desc %s)", libname, directory, desc); + mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT, "Attempting to load profiler %s from %s (desc %s)", libname, directory, desc); iter = NULL; err = NULL; while ((path = mono_dl_build_path (directory, libname, &iter))) { pmodule = mono_dl_open (path, MONO_DL_LAZY, &err); - mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY, "Attempting to load profiler: %s %ssuccessful, err: %s", path, pmodule?"":"not ", err); + mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT, "Attempting to load profiler: %s, %ssuccessful, err: %s", path, pmodule?"":"not ", err); g_free (path); g_free (err); if (pmodule) @@ -1186,10 +1187,11 @@ load_profiler_from_directory (const char *directory, const char *libname, const } static gboolean -load_profiler_from_mono_instalation (const char *libname, const char *desc) +load_profiler_from_mono_installation (const char *libname, const char *desc) { char *err = NULL; MonoDl *pmodule = mono_dl_open_runtime_lib (libname, MONO_DL_LAZY, &err); + mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT, "Attempting to load profiler from runtime libs: %s, %ssuccessful, err: %s", libname, pmodule?"":"not ", err); g_free (err); if (pmodule) return load_profiler (pmodule, desc, INITIALIZER_NAME); @@ -1254,15 +1256,11 @@ mono_profiler_load (const char *desc) } if (!load_embedded_profiler (desc, mname)) { libname = g_strdup_printf ("mono-profiler-%s", mname); - char *profiler_lib_dir = getenv ("MONO_PROFILER_LIB_DIR"); - if (profiler_lib_dir) - res = load_profiler_from_directory (profiler_lib_dir, libname, desc); + res = load_profiler_from_mono_installation (libname, desc); if (!res && mono_config_get_assemblies_dir ()) res = load_profiler_from_directory (mono_assembly_getrootdir (), libname, desc); if (!res) res = load_profiler_from_directory (NULL, libname, desc); - if (!res) - res = load_profiler_from_mono_instalation (libname, desc); if (!res) g_warning ("The '%s' profiler wasn't found in the main executable nor could it be loaded from '%s'.", mname, libname); g_free (libname); diff --git a/mono/profiler/ptestrunner.pl b/mono/profiler/ptestrunner.pl index 5215621c2fd..e6323460651 100755 --- a/mono/profiler/ptestrunner.pl +++ b/mono/profiler/ptestrunner.pl @@ -15,7 +15,6 @@ my $minibuilddir = $builddir . "/mono/mini"; # Setup the execution environment # for the profiler module -append_path ("MONO_PROFILER_LIB_DIR", $profbuilddir . "/.libs"); append_path ("DYLD_LIBRARY_PATH", $minibuilddir . "/.libs"); # for mprof-report append_path ("PATH", $profbuilddir); diff --git a/mono/utils/mono-dl.c b/mono/utils/mono-dl.c index 62493555a30..43116130309 100644 --- a/mono/utils/mono-dl.c +++ b/mono/utils/mono-dl.c @@ -402,28 +402,35 @@ mono_dl_open_runtime_lib (const char* lib_name, int flags, char **error_msg) if (binl != -1) { char *base; char *resolvedname, *name; + char *baseparent = NULL; buf [binl] = 0; resolvedname = mono_path_resolve_symlinks (buf); base = g_path_get_dirname (resolvedname); name = g_strdup_printf ("%s/.libs", base); runtime_lib = try_load (lib_name, name, flags, error_msg); g_free (name); + if (!runtime_lib) + baseparent = g_path_get_dirname (base); if (!runtime_lib) { - char *newbase = g_path_get_dirname (base); - name = g_strdup_printf ("%s/lib", newbase); + name = g_strdup_printf ("%s/lib", baseparent); runtime_lib = try_load (lib_name, name, flags, error_msg); g_free (name); } #ifdef __MACH__ if (!runtime_lib) { - char *newbase = g_path_get_dirname (base); - name = g_strdup_printf ("%s/Libraries", newbase); + name = g_strdup_printf ("%s/Libraries", baseparent); runtime_lib = try_load (lib_name, name, flags, error_msg); g_free (name); } #endif + if (!runtime_lib) { + name = g_strdup_printf ("%s/profiler/.libs", baseparent); + runtime_lib = try_load (lib_name, name, flags, error_msg); + g_free (name); + } g_free (base); g_free (resolvedname); + g_free (baseparent); } if (!runtime_lib) runtime_lib = try_load (lib_name, NULL, flags, error_msg); -- 2.25.1