2008-07-11 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / metadata / profiler.c
index 0f33a27214a9502f747b4174003f7420416cc9d1..8323e3984cfcae0522a6c33690a0f7d3a77f1cee 100644 (file)
@@ -59,6 +59,8 @@ static MonoProfileMethodFunc   method_free;
 static MonoProfileMethodResult man_unman_transition;
 static MonoProfileAllocFunc    allocation_cb;
 static MonoProfileStatFunc     statistical_cb;
+static MonoProfileStatCallChainFunc statistical_call_chain_cb;
+static int                     statistical_call_chain_depth;
 static MonoProfileMethodFunc   method_enter;
 static MonoProfileMethodFunc   method_leave;
 
@@ -203,6 +205,24 @@ mono_profiler_install_statistical (MonoProfileStatFunc callback)
        statistical_cb = callback;
 }
 
+void 
+mono_profiler_install_statistical_call_chain (MonoProfileStatCallChainFunc callback, int call_chain_depth) {
+       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;
+       }
+}
+
+int
+mono_profiler_stat_get_call_chain_depth (void) {
+       if (statistical_call_chain_cb != NULL) {
+               return statistical_call_chain_depth;
+       } else {
+               return 0;
+       }
+}
+
 void mono_profiler_install_exception (MonoProfileExceptionFunc throw_callback, MonoProfileMethodFunc exc_method_leave, MonoProfileExceptionClauseFunc clause_callback)
 {
        exception_throw_cb = throw_callback;
@@ -317,6 +337,13 @@ mono_profiler_stat_hit (guchar *ip, void *context)
                statistical_cb (current_profiler, ip, context);
 }
 
+void
+mono_profiler_stat_call_chain (int call_chain_depth, guchar **ips, void *context)
+{
+       if ((mono_profiler_events & MONO_PROFILE_STATISTICAL) && statistical_call_chain_cb)
+               statistical_call_chain_cb (current_profiler, call_chain_depth, ips, context);
+}
+
 void
 mono_profiler_exception_thrown (MonoObject *exception)
 {
@@ -889,7 +916,7 @@ output_profile (GList *funcs)
                m = method_get_name (p->method);
                fprintf (poutput, "########################\n");
                fprintf (poutput, "% 8.3f ", (double) (p->total * 1000));
-               fprintf (poutput, "%7" G_GUINT64_FORMAT " ", (unsigned long long)p->count);
+               fprintf (poutput, "%7" G_GUINT64_FORMAT " ", (guint64)p->count);
                fprintf (poutput, "% 8.3f ", (double) (p->total * 1000)/(double)p->count);
                fprintf (poutput, "  %s\n", m);
 
@@ -897,7 +924,7 @@ output_profile (GList *funcs)
                /* callers */
                output_callers (p);
        }
-       fprintf (poutput, "Total number of calls: %" G_GINT64_FORMAT "\n", (long long)total_calls);
+       fprintf (poutput, "Total number of calls: %" G_GINT64_FORMAT "\n", (gint64)total_calls);
 }
 
 typedef struct {
@@ -1407,6 +1434,8 @@ simple_shutdown (MonoProfiler *prof)
        char *str;
        gint32 see_shutdown_done;
        
+       mono_thread_attach(mono_get_root_domain());
+       
        // Make sure we execute simple_shutdown only once
        see_shutdown_done = InterlockedExchange(& simple_shutdown_done, TRUE);
        if (see_shutdown_done)