2005-07-21 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mono / metadata / profiler.c
index efa5f2a0f38feb4197bddf376fec197da20f9113..99d9020465db414eb3f92a1cf949286404a79991 100644 (file)
@@ -5,6 +5,7 @@
 #include "mono/metadata/mono-debug.h"
 #include "mono/metadata/class-internals.h"
 #include "mono/metadata/domain-internals.h"
+#include "mono/metadata/gc-internal.h"
 #include "mono/io-layer/io-layer.h"
 #include <string.h>
 #include <sys/time.h>
@@ -50,6 +51,9 @@ static MonoProfileCoverageFilterFunc coverage_filter_cb;
 
 static MonoProfileFunc shutdown_callback;
 
+static MonoProfileGCFunc        gc_event;
+static MonoProfileGCResizeFunc  gc_heap_resize;
+
 static CRITICAL_SECTION profiler_coverage_mutex;
 
 /* this is directly accessible to other mono libs. */
@@ -357,6 +361,28 @@ mono_profiler_shutdown (void)
                shutdown_callback (current_profiler);
 }
 
+void
+mono_profiler_gc_heap_resize (gint64 new_size)
+{
+       if ((mono_profiler_events & MONO_PROFILE_GC) && gc_heap_resize)
+               gc_heap_resize (current_profiler, new_size);
+}
+
+void
+mono_profiler_gc_event (MonoGCEvent event, int generation)
+{
+       if ((mono_profiler_events & MONO_PROFILE_GC) && gc_event)
+               gc_event (current_profiler, event, generation);
+}
+
+void
+mono_profiler_install_gc (MonoProfileGCFunc callback, MonoProfileGCResizeFunc heap_resize_callback)
+{
+       mono_gc_enable_events ();
+       gc_event = callback;
+       gc_heap_resize = heap_resize_callback;
+}
+
 static GHashTable *coverage_hash = NULL;
 
 MonoProfileCoverageInfo* 
@@ -677,7 +703,7 @@ method_get_name (MonoMethod* method)
 {
        char *sig, *res;
        
-       sig = mono_signature_get_desc (method->signature, FALSE);
+       sig = mono_signature_get_desc (mono_method_signature (method), FALSE);
        res = g_strdup_printf ("%s.%s::%s(%s)", method->klass->name_space, method->klass->name,
                method->name, sig);
        g_free (sig);
@@ -704,7 +730,7 @@ output_profile (GList *funcs)
                m = method_get_name (p->method);
                printf ("########################\n");
                printf ("% 8.3f ", (double) (p->total * 1000));
-               printf ("%7llu ", p->count);
+               printf ("%7llu ", (unsigned long long)p->count);
                printf ("% 8.3f ", (double) (p->total * 1000)/(double)p->count);
                printf ("  %s\n", m);
 
@@ -712,7 +738,7 @@ output_profile (GList *funcs)
                /* callers */
                output_callers (p);
        }
-       printf ("Total number of calls: %lld\n", total_calls);
+       printf ("Total number of calls: %lld\n", (long long)total_calls);
 }
 
 typedef struct {
@@ -1132,8 +1158,9 @@ stat_prof_report (void)
        char *mn;
        gpointer ip;
        GList *tmp, *sorted = NULL;
+       int pcount = ++ prof_counts;
 
-       prof_counts ++;
+       prof_counts = MAX_PROF_SAMPLES;
        for (i = 0; i < count; ++i) {
                ip = prof_addresses [i];
                ji = mono_jit_info_table_find (mono_domain_get (), ip);
@@ -1176,7 +1203,7 @@ stat_prof_report (void)
                if (c > 1)
                        g_free (mn);
        }
-       g_print ("prof counts: total/unmanaged: %d/%d\n", prof_counts, prof_ucounts);
+       g_print ("prof counts: total/unmanaged: %d/%d\n", pcount, prof_ucounts);
        g_hash_table_foreach (prof_table, (GHFunc)prof_foreach, &sorted);
        for (tmp = sorted; tmp; tmp = tmp->next) {
                double perc;
@@ -1226,6 +1253,7 @@ simple_shutdown (MonoProfiler *prof)
        g_list_free (profile);
 
        g_free (prof_addresses);
+       prof_addresses = NULL;
        g_hash_table_destroy (prof_table);
 }
 
@@ -1234,19 +1262,19 @@ mono_profiler_install_simple (const char *desc)
 {
        MonoProfiler *prof;
        gchar **args, **ptr;
-       MonoProfileFlags flags = MONO_PROFILE_JIT_COMPILATION;
+       MonoProfileFlags flags = 0;
 
        MONO_TIMER_STARTUP;
 
        if (!desc)
-               desc = "alloc,time";
+               desc = "alloc,time,jit";
 
        if (desc) {
                /* Parse options */
                if (strstr (desc, ":"))
                        desc = strstr (desc, ":") + 1;
                else
-                       desc = "alloc,time";
+                       desc = "alloc,time,jit";
                args = g_strsplit (desc, ",", -1);
 
                for (ptr = args; ptr && *ptr; ptr++) {
@@ -1258,6 +1286,8 @@ mono_profiler_install_simple (const char *desc)
                                flags |= MONO_PROFILE_ALLOCATIONS;
                        else if (!strcmp (arg, "stat"))
                                flags |= MONO_PROFILE_STATISTICAL | MONO_PROFILE_APPDOMAIN_EVENTS;
+                       else if (!strcmp (arg, "jit"))
+                               flags |= MONO_PROFILE_JIT_COMPILATION;
                        else {
                                fprintf (stderr, "profiler : Unknown argument '%s'.\n", arg);
                                return;