Merge pull request #1174 from rhapsodyn/patch-1
[mono.git] / mono / metadata / profiler.c
index 4aadd1f98ee0e75c8045f5e9709ff5a4a59dde07..ea779238aa063df21656b422516b854df810bfaf 100644 (file)
@@ -1093,6 +1093,17 @@ load_profiler_from_directory (const char *directory, const char *libname, const
        return FALSE;
 }
 
+static gboolean
+load_profiler_from_mono_instalation (const char *libname, const char *desc)
+{
+       char *err = NULL;
+       MonoDl *pmodule = mono_dl_open_runtime_lib (libname, MONO_DL_LAZY, &err);
+       g_free (err);
+       if (pmodule)
+               return load_profiler (pmodule, desc, INITIALIZER_NAME);
+       return FALSE;
+}
+
 /**
  * mono_profiler_load:
  * @desc: arguments to configure the profiler
@@ -1141,7 +1152,7 @@ mono_profiler_load (const char *desc)
                const char* col = strchr (desc, ':');
                char* libname;
                char *mname;
-               gboolean res;
+               gboolean res = FALSE;
 
                if (col != NULL) {
                        mname = g_memdup (desc, col - desc + 1);
@@ -1151,14 +1162,17 @@ mono_profiler_load (const char *desc)
                }
                if (!load_embedded_profiler (desc, mname)) {
                        libname = g_strdup_printf ("mono-profiler-%s", mname);
-                       if (!load_profiler_from_directory (NULL, libname, desc))
+                       if (!load_profiler_from_directory (NULL, libname, desc)) {
+                               res = FALSE;
 #if defined (MONO_ASSEMBLIES)
                                res = load_profiler_from_directory (mono_assembly_getrootdir (), libname, desc);
-#else
-                               res = FALSE;
 #endif
                                if (!res)
-                                       g_warning ("The %s profiler wasn't found in the main executable nor could it be loaded from '%s'.", libname);
+                                       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);
                }
                g_free (mname);