X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fprofiler.c;h=36b864a60e1284849cb371d681efda1aa37b4421;hb=f9ae98ab88f522219cd6be6fd282ef30adbc5365;hp=a1e222fc1e66c2c8c39b26ac6bff50ab6c9aa88b;hpb=ea4e4a9ef6fc42570a23026adbe826cf7248290e;p=mono.git diff --git a/mono/metadata/profiler.c b/mono/metadata/profiler.c index a1e222fc1e6..36b864a60e1 100644 --- a/mono/metadata/profiler.c +++ b/mono/metadata/profiler.c @@ -11,6 +11,7 @@ #include #include #include +#include MonoProfilerState mono_profiler_state; @@ -20,24 +21,16 @@ typedef void (*MonoProfilerInitializer) (const char *); #define NEW_INITIALIZER_NAME "mono_profiler_init" static gboolean -load_profiler (MonoDl *module, const char *desc, const char *suffix) +load_profiler (MonoDl *module, const char *name, const char *desc) { if (!module) return FALSE; - char *old_name; - - if (suffix) - old_name = g_strdup_printf (OLD_INITIALIZER_NAME "_%s", suffix); - else - old_name = g_strdup_printf (OLD_INITIALIZER_NAME); - + char *err, *old_name = g_strdup_printf (OLD_INITIALIZER_NAME); MonoProfilerInitializer func; - char *err; - if (!(err = mono_dl_symbol (module, old_name, (gpointer) &func))) { - g_warning ("Found old-style startup symbol %s; profiler has not been migrated to the new API.", old_name); + mono_profiler_printf_err ("Found old-style startup symbol '%s' for the '%s' profiler; it has not been migrated to the new API.", old_name, name); g_free (old_name); return FALSE; } @@ -45,12 +38,7 @@ load_profiler (MonoDl *module, const char *desc, const char *suffix) g_free (err); g_free (old_name); - char *new_name; - - if (suffix) - new_name = g_strdup_printf (NEW_INITIALIZER_NAME "_%s", suffix); - else - new_name = g_strdup_printf (NEW_INITIALIZER_NAME); + char *new_name = g_strdup_printf (NEW_INITIALIZER_NAME "_%s", name); if ((err = mono_dl_symbol (module, new_name, (gpointer *) &func))) { g_free (err); @@ -66,7 +54,7 @@ load_profiler (MonoDl *module, const char *desc, const char *suffix) } static gboolean -load_profiler_from_executable (const char *desc, const char *name) +load_profiler_from_executable (const char *name, const char *desc) { char *err; @@ -81,16 +69,16 @@ load_profiler_from_executable (const char *desc, const char *name) MonoDl *module = mono_dl_open (NULL, MONO_DL_EAGER, &err); if (!module) { - g_warning ("Could not open main executable (%s).", err); + mono_profiler_printf_err ("Could not open main executable: %s", err); g_free (err); return FALSE; } - return load_profiler (module, desc, name); + return load_profiler (module, name, desc); } static gboolean -load_profiler_from_directory (const char *directory, const char *libname, const char *desc) +load_profiler_from_directory (const char *directory, const char *libname, const char *name, const char *desc) { char* path; void *iter = NULL; @@ -102,14 +90,14 @@ load_profiler_from_directory (const char *directory, const char *libname, const g_free (path); if (module) - return load_profiler (module, desc, NULL); + return load_profiler (module, name, desc); } return FALSE; } static gboolean -load_profiler_from_installation (const char *libname, const char *desc) +load_profiler_from_installation (const char *libname, const char *name, const char *desc) { char *err; MonoDl *module = mono_dl_open_runtime_lib (libname, MONO_DL_EAGER, &err); @@ -117,7 +105,7 @@ load_profiler_from_installation (const char *libname, const char *desc) g_free (err); if (module) - return load_profiler (module, desc, NULL); + return load_profiler (module, name, desc); return FALSE; } @@ -125,8 +113,6 @@ load_profiler_from_installation (const char *libname, const char *desc) void mono_profiler_load (const char *desc) { - mono_gc_base_init (); - if (!desc || !strcmp ("default", desc)) desc = "log:report"; @@ -139,18 +125,18 @@ mono_profiler_load (const char *desc) } else mname = g_strdup (desc); - if (!load_profiler_from_executable (desc, mname)) { + if (!load_profiler_from_executable (mname, desc)) { char *libname = g_strdup_printf ("mono-profiler-%s", mname); - gboolean res = load_profiler_from_installation (libname, desc); + gboolean res = load_profiler_from_installation (libname, mname, desc); if (!res && mono_config_get_assemblies_dir ()) - res = load_profiler_from_directory (mono_assembly_getrootdir (), libname, desc); + res = load_profiler_from_directory (mono_assembly_getrootdir (), libname, mname, desc); if (!res) - res = load_profiler_from_directory (NULL, libname, desc); + res = load_profiler_from_directory (NULL, libname, mname, desc); if (!res) - g_warning ("The '%s' profiler wasn't found in the main executable nor could it be loaded from '%s'.", mname, libname); + mono_profiler_printf_err ("The '%s' profiler wasn't found in the main executable nor could it be loaded from '%s'.", mname, libname); g_free (libname); } @@ -159,7 +145,7 @@ mono_profiler_load (const char *desc) } MonoProfilerHandle -mono_profiler_install (MonoProfiler *prof) +mono_profiler_create (MonoProfiler *prof) { MonoProfilerHandle handle = g_new0 (struct _MonoProfilerDesc, 1); @@ -326,7 +312,7 @@ mono_profiler_enable_sampling (MonoProfilerHandle handle) } mono_bool -mono_profiler_set_sample_mode (MonoProfilerHandle handle, MonoProfilerSampleMode mode, uint64_t freq) +mono_profiler_set_sample_mode (MonoProfilerHandle handle, MonoProfilerSampleMode mode, uint32_t freq) { if (handle != mono_profiler_state.sampling_owner) return FALSE; @@ -334,13 +320,13 @@ mono_profiler_set_sample_mode (MonoProfilerHandle handle, MonoProfilerSampleMode mono_profiler_state.sample_mode = mode; mono_profiler_state.sample_freq = freq; - mono_os_sem_post (&mono_profiler_state.sampling_semaphore); + mono_profiler_sampling_thread_post (); return TRUE; } mono_bool -mono_profiler_get_sample_mode (MonoProfilerHandle handle, MonoProfilerSampleMode *mode, uint64_t *freq) +mono_profiler_get_sample_mode (MonoProfilerHandle handle, MonoProfilerSampleMode *mode, uint32_t *freq) { if (mode) *mode = mono_profiler_state.sample_mode; @@ -358,7 +344,13 @@ mono_profiler_sampling_enabled (void) } void -mono_profiler_sampling_thread_sleep (void) +mono_profiler_sampling_thread_post (void) +{ + mono_os_sem_post (&mono_profiler_state.sampling_semaphore); +} + +void +mono_profiler_sampling_thread_wait (void) { mono_os_sem_wait (&mono_profiler_state.sampling_semaphore, MONO_SEM_FLAGS_NONE); } @@ -369,9 +361,7 @@ mono_profiler_enable_allocations (void) if (mono_profiler_state.startup_done) return FALSE; - mono_profiler_state.allocations = TRUE; - - return TRUE; + return mono_profiler_state.allocations = TRUE; } void @@ -380,8 +370,61 @@ mono_profiler_set_call_instrumentation_filter_callback (MonoProfilerHandle handl InterlockedWritePointer (&handle->call_instrumentation_filter, (gpointer) cb); } -gboolean -mono_profiler_should_instrument_method (MonoMethod *method, gboolean entry) +mono_bool +mono_profiler_enable_call_context_introspection (void) +{ + if (mono_profiler_state.startup_done) + return FALSE; + + mono_profiler_state.context_enable (); + + return mono_profiler_state.call_contexts = TRUE; +} + +void * +mono_profiler_call_context_get_this (MonoProfilerCallContext *context) +{ + if (!mono_profiler_state.call_contexts) + return NULL; + + return mono_profiler_state.context_get_this (context); +} + +void * +mono_profiler_call_context_get_argument (MonoProfilerCallContext *context, uint32_t position) +{ + if (!mono_profiler_state.call_contexts) + return NULL; + + return mono_profiler_state.context_get_argument (context, position); +} + +void * +mono_profiler_call_context_get_local (MonoProfilerCallContext *context, uint32_t position) +{ + if (!mono_profiler_state.call_contexts) + return NULL; + + return mono_profiler_state.context_get_local (context, position); +} + +void * +mono_profiler_call_context_get_result (MonoProfilerCallContext *context) +{ + if (!mono_profiler_state.call_contexts) + return NULL; + + return mono_profiler_state.context_get_result (context); +} + +void +mono_profiler_call_context_free_buffer (void *buffer) +{ + mono_profiler_state.context_free_buffer (buffer); +} + +MonoProfilerCallInstrumentationFlags +mono_profiler_get_call_instrumentation_flags (MonoMethod *method) { MonoProfilerCallInstrumentationFlags flags = MONO_PROFILER_CALL_INSTRUMENTATION_NONE; @@ -392,10 +435,7 @@ mono_profiler_should_instrument_method (MonoMethod *method, gboolean entry) flags |= cb (handle->prof, method); } - if (entry) - return flags & MONO_PROFILER_CALL_INSTRUMENTATION_PROLOGUE; - else - return flags & MONO_PROFILER_CALL_INSTRUMENTATION_EPILOGUE; + return flags; } void