2005-07-21 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mono / metadata / profiler.c
index 86bd62cd80029efa0f874d2b44b318d563699d0a..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>
@@ -377,6 +378,7 @@ mono_profiler_gc_event (MonoGCEvent event, int 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;
 }
@@ -701,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);
@@ -728,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);
 
@@ -736,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 {
@@ -1156,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);
@@ -1200,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;
@@ -1250,6 +1253,7 @@ simple_shutdown (MonoProfiler *prof)
        g_list_free (profile);
 
        g_free (prof_addresses);
+       prof_addresses = NULL;
        g_hash_table_destroy (prof_table);
 }
 
@@ -1258,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++) {
@@ -1282,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;