Merge pull request #1174 from rhapsodyn/patch-1
[mono.git] / mono / metadata / profiler.c
index 5de7b8e9903351a59cd54f55c918c4a2ee216678..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
@@ -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)
+                                       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);