Assist on profiler module loading
authorAndi McClure <andi.mcclure@xamarin.com>
Thu, 31 Mar 2016 15:02:21 +0000 (11:02 -0400)
committerAndi McClure <andi.mcclure@xamarin.com>
Thu, 31 Mar 2016 15:02:21 +0000 (11:02 -0400)
- Add a MONO_PROFILER_LIB_DIR from which custom profilers are
  dynamically loaded, in case it is not the normal library path
- Modify mono/profiler make check to use MONO_PROFILER_LIB_DIR
  (this fixes a bug where it would sometimes load the wrong profiler)
- Add information about profiler loading to mono_trace

man/mono.1
mono/metadata/profiler.c
mono/profiler/ptestrunner.pl

index f29f4d1601ee83055ad10cd9599067f4042107ab..99d49e6f9299c891e85917532d9fc3d601e41dc6 100644 (file)
@@ -786,7 +786,8 @@ 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.
+be on your dynamic linker library path, or in the MONO_PROFILER_LIB_DIR
+path (see "RUNTIME OPTIONS" below).
 .PP 
 A list of other third party profilers is available from Mono's web
 site (www.mono-project.com/docs/advanced/performance-tips/)
@@ -1512,6 +1513,12 @@ libraries side-by-side with the main executable.
 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_RTC\fR
 Experimental RTC support in the statistical profiler: if the user has
index cdd11fda385f3b6a2b0a87469d2f955b067f5bed..28f7a2983125fa1f2e58ddf0a8466b67da05afe8 100644 (file)
@@ -23,6 +23,7 @@
 #include "mono/metadata/mono-config-dirs.h"
 #include "mono/io-layer/io-layer.h"
 #include "mono/utils/mono-dl.h"
+#include <mono/utils/mono-logger-internals.h>
 #include <string.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -1167,10 +1168,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);
+
        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);
                g_free (path);
                g_free (err);
                if (pmodule)
@@ -1249,7 +1253,10 @@ mono_profiler_load (const char *desc)
                }
                if (!load_embedded_profiler (desc, mname)) {
                        libname = g_strdup_printf ("mono-profiler-%s", mname);
-                       if (mono_config_get_assemblies_dir ())
+                       char *profiler_lib_dir = getenv ("MONO_PROFILER_LIB_DIR");
+                       if (profiler_lib_dir)
+                               res = load_profiler_from_directory (profiler_lib_dir, 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);
index 2113c25135f27c8e49cc8fc81588968c34d601f4..5215621c2fdf7f22e669d26a39579b1dcc3e319e 100755 (executable)
@@ -15,8 +15,7 @@ my $minibuilddir = $builddir . "/mono/mini";
 
 # Setup the execution environment
 # for the profiler module
-append_path ("LD_LIBRARY_PATH", $profbuilddir . "/.libs");
-append_path ("DYLD_LIBRARY_PATH", $profbuilddir . "/.libs");
+append_path ("MONO_PROFILER_LIB_DIR", $profbuilddir . "/.libs");
 append_path ("DYLD_LIBRARY_PATH", $minibuilddir . "/.libs");
 # for mprof-report
 append_path ("PATH", $profbuilddir);