2009-12-09 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / metadata / profiler.c
index b6087e7c3678bc3bd40b2317957fb6783030dec9..d8ae324f2b86ba0b1e806dfd752b92b27dcaf790 100644 (file)
@@ -56,12 +56,15 @@ static MonoProfileMethodFunc   jit_start;
 static MonoProfileMethodResult jit_end;
 static MonoProfileJitResult    jit_end2;
 static MonoProfileMethodFunc   method_free;
+static MonoProfileMethodFunc   method_start_invoke;
+static MonoProfileMethodFunc   method_end_invoke;
 static MonoProfileMethodResult man_unman_transition;
 static MonoProfileAllocFunc    allocation_cb;
 static MonoProfileMonitorFunc  monitor_event_cb;
 static MonoProfileStatFunc     statistical_cb;
 static MonoProfileStatCallChainFunc statistical_call_chain_cb;
 static int                     statistical_call_chain_depth;
+static MonoProfilerCallChainStrategy  statistical_call_chain_strategy;
 static MonoProfileMethodFunc   method_enter;
 static MonoProfileMethodFunc   method_leave;
 
@@ -183,6 +186,13 @@ mono_profiler_install_method_free (MonoProfileMethodFunc callback)
        method_free = callback;
 }
 
+void
+mono_profiler_install_method_invoke (MonoProfileMethodFunc start, MonoProfileMethodFunc end)
+{
+       method_start_invoke = start;
+       method_end_invoke = end;
+}
+
 void 
 mono_profiler_install_thread (MonoProfileThreadFunc start, MonoProfileThreadFunc end)
 {
@@ -215,12 +225,16 @@ mono_profiler_install_statistical (MonoProfileStatFunc callback)
 }
 
 void 
-mono_profiler_install_statistical_call_chain (MonoProfileStatCallChainFunc callback, int call_chain_depth) {
+mono_profiler_install_statistical_call_chain (MonoProfileStatCallChainFunc callback, int call_chain_depth, MonoProfilerCallChainStrategy call_chain_strategy) {
        statistical_call_chain_cb = callback;
        statistical_call_chain_depth = call_chain_depth;
        if (statistical_call_chain_depth > MONO_PROFILER_MAX_STAT_CALL_CHAIN_DEPTH) {
                statistical_call_chain_depth = MONO_PROFILER_MAX_STAT_CALL_CHAIN_DEPTH;
        }
+       statistical_call_chain_strategy = call_chain_strategy;
+       if ((statistical_call_chain_strategy >= MONO_PROFILER_CALL_CHAIN_INVALID) || (statistical_call_chain_strategy < MONO_PROFILER_CALL_CHAIN_NONE)) {
+               statistical_call_chain_strategy = MONO_PROFILER_CALL_CHAIN_NONE;
+       }
 }
 
 int
@@ -232,6 +246,15 @@ mono_profiler_stat_get_call_chain_depth (void) {
        }
 }
 
+MonoProfilerCallChainStrategy
+mono_profiler_stat_get_call_chain_strategy (void) {
+       if (statistical_call_chain_cb != NULL) {
+               return statistical_call_chain_strategy;
+       } else {
+               return MONO_PROFILER_CALL_CHAIN_NONE;
+       }
+}
+
 void mono_profiler_install_exception (MonoProfileExceptionFunc throw_callback, MonoProfileMethodFunc exc_method_leave, MonoProfileExceptionClauseFunc clause_callback)
 {
        exception_throw_cb = throw_callback;
@@ -325,6 +348,20 @@ mono_profiler_method_free (MonoMethod *method)
                method_free (current_profiler, method);
 }
 
+void
+mono_profiler_method_start_invoke (MonoMethod *method)
+{
+       if ((mono_profiler_events & MONO_PROFILE_METHOD_EVENTS) && method_start_invoke)
+               method_start_invoke (current_profiler, method);
+}
+
+void
+mono_profiler_method_end_invoke (MonoMethod *method)
+{
+       if ((mono_profiler_events & MONO_PROFILE_METHOD_EVENTS) && method_end_invoke)
+               method_end_invoke (current_profiler, method);
+}
+
 void 
 mono_profiler_code_transition (MonoMethod *method, int result)
 {
@@ -1509,7 +1546,7 @@ simple_shutdown (MonoProfiler *prof)
        char *str;
        gint32 see_shutdown_done;
 
-#ifndef PLATFORM_WIN32
+#ifndef HOST_WIN32
        mono_thread_attach(mono_get_root_domain());
 #endif
 
@@ -1650,7 +1687,7 @@ mono_profiler_load (const char *desc)
        }
 #endif
        {
-               MonoDl *pmodule;
+               MonoDl *pmodule = NULL;
                const char* col = strchr (desc, ':');
                char* libname;
                char* path;