示例#1
0
/**
 * mono_profiler_load:
 * @desc: arguments to configure the profiler
 *
 * Invoke this method to initialize the profiler.   This will drive the
 * loading of the internal ("default") or any external profilers.
 *
 * This routine is invoked by Mono's driver, but must be called manually
 * if you embed Mono into your application.
 */
void 
mono_profiler_load (const char *desc)
{
	mono_gc_base_init ();

#ifndef DISABLE_PROFILER
	if (!desc || (strcmp ("default", desc) == 0) || (strncmp (desc, "default:", 8) == 0)) {
		mono_profiler_install_simple (desc);
		return;
	}
#else
	if (!desc) {
		desc = "default";
	}
#endif
	{
		MonoDl *pmodule = NULL;
		const char* col = strchr (desc, ':');
		char* libname;
		char* path;
		char *mname;
		char *err;
		void *iter;
		if (col != NULL) {
			mname = g_memdup (desc, col - desc + 1);
			mname [col - desc] = 0;
		} else {
			mname = g_strdup (desc);
		}
		libname = g_strdup_printf ("mono-profiler-%s", mname);
		iter = NULL;
		err = NULL;
		while ((path = mono_dl_build_path (NULL, libname, &iter))) {
			g_free (err);
			pmodule = mono_dl_open (path, MONO_DL_LAZY, &err);
			if (pmodule) {
				ProfilerInitializer func;
				if ((err = mono_dl_symbol (pmodule, INITIALIZER_NAME, (gpointer *)&func))) {
					g_warning ("Cannot find initializer function %s in profiler module: %s (%s)", INITIALIZER_NAME, libname, err);
					g_free (err);
					err = NULL;
				} else {
					func (desc);
				}
				break;
			}
			g_free (path);
		}
		if (!pmodule) {
			g_warning ("Error loading profiler module '%s': %s", libname, err);
			g_free (err);
		}
		g_free (libname);
		g_free (mname);
		g_free (path);
	}
}
示例#2
0
文件: mono-debug.c 项目: Andrea/mono
/*
 * Initialize debugging support.
 *
 * This method must be called after loading corlib,
 * but before opening the application's main assembly because we need to set some
 * callbacks here.
 */
void
mono_debug_init (MonoDebugFormat format)
{
	g_assert (!mono_debug_initialized);

	if (_mono_debug_using_mono_debugger)
		format = MONO_DEBUG_FORMAT_DEBUGGER;

	mono_debug_initialized = TRUE;
	mono_debug_format = format;

	/*
	 * This must be called before mono_debugger_initialize(), because the
	 * latter registers GC roots.
	 */
	mono_gc_base_init ();

	mono_debugger_initialize (_mono_debug_using_mono_debugger);

	mono_debugger_lock ();

	mono_symbol_table = g_new0 (MonoSymbolTable, 1);
	mono_symbol_table->magic = MONO_DEBUGGER_MAGIC;
	mono_symbol_table->version = MONO_DEBUGGER_MAJOR_VERSION;
	mono_symbol_table->total_size = sizeof (MonoSymbolTable);

	mono_debug_handles = g_hash_table_new_full
		(NULL, NULL, NULL, (GDestroyNotify) free_debug_handle);

	data_table_hash = g_hash_table_new_full (
		NULL, NULL, NULL, (GDestroyNotify) free_data_table);

	mono_debugger_class_init_func = mono_debug_add_type;
	mono_debugger_class_loaded_methods_func = mono_debugger_class_initialized;
	mono_install_assembly_load_hook (mono_debug_add_assembly, NULL);

	mono_symbol_table->global_data_table = create_data_table (NULL);

	mono_debugger_unlock ();
}
示例#3
0
文件: profiler.c 项目: RavenB/mono
/**
 * mono_profiler_load:
 * @desc: arguments to configure the profiler
 *
 * Invoke this method to initialize the profiler.   This will drive the
 * loading of the internal ("default") or any external profilers.
 *
 * This routine is invoked by Mono's driver, but must be called manually
 * if you embed Mono into your application.
 */
void 
mono_profiler_load (const char *desc)
{
	char *cdesc = NULL;
	mono_gc_base_init ();

	if (!desc || (strcmp ("default", desc) == 0)) {
		desc = "log:report";
	}
	/* we keep command-line compat with the old version here */
	if (strncmp (desc, "default:", 8) == 0) {
		gchar **args, **ptr;
		GString *str = g_string_new ("log:report");
		args = g_strsplit (desc + 8, ",", -1);
		for (ptr = args; ptr && *ptr; ptr++) {
			const char *arg = *ptr;

			if (!strcmp (arg, "time"))
				g_string_append (str, ",calls");
			else if (!strcmp (arg, "alloc"))
				g_string_append (str, ",alloc");
			else if (!strcmp (arg, "stat"))
				g_string_append (str, ",sample");
			else if (!strcmp (arg, "jit"))
				continue; /* accept and do nothing */
			else if (strncmp (arg, "file=", 5) == 0) {
				g_string_append_printf (str, ",output=%s", arg + 5);
			} else {
				fprintf (stderr, "profiler : Unknown argument '%s'.\n", arg);
				return;
			}
		}
		desc = cdesc = g_string_free (str, FALSE);
	}
	{
		const char* col = strchr (desc, ':');
		char* libname;
		char *mname;
		gboolean res = FALSE;

		if (col != NULL) {
			mname = g_memdup (desc, col - desc + 1);
			mname [col - desc] = 0;
		} else {
			mname = g_strdup (desc);
		}
		if (!load_embedded_profiler (desc, mname)) {
			libname = g_strdup_printf ("mono-profiler-%s", mname);
			if (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);
		}
		g_free (mname);
	}
	g_free (cdesc);
}