Patches from the Suse autobuild.
[mono.git] / mono / metadata / profiler.c
index f96e1db24de590798aca60ccaf574a982f449bbd..27eba5f606239b7596d957892eba8283dc04cf96 100644 (file)
@@ -54,6 +54,8 @@ static MonoProfileFunc shutdown_callback;
 static MonoProfileGCFunc        gc_event;
 static MonoProfileGCResizeFunc  gc_heap_resize;
 
+#define mono_profiler_coverage_lock() EnterCriticalSection (&profiler_coverage_mutex)
+#define mono_profiler_coverage_unlock() LeaveCriticalSection (&profiler_coverage_mutex)
 static CRITICAL_SECTION profiler_coverage_mutex;
 
 /* this is directly accessible to other mono libs. */
@@ -394,7 +396,7 @@ mono_profiler_coverage_alloc (MonoMethod *method, int entries)
                if (! (*coverage_filter_cb) (current_profiler, method))
                        return NULL;
 
-       EnterCriticalSection (&profiler_coverage_mutex);
+       mono_profiler_coverage_lock ();
        if (!coverage_hash)
                coverage_hash = g_hash_table_new (NULL, NULL);
 
@@ -403,7 +405,7 @@ mono_profiler_coverage_alloc (MonoMethod *method, int entries)
        res->entries = entries;
 
        g_hash_table_insert (coverage_hash, method, res);
-       LeaveCriticalSection (&profiler_coverage_mutex);
+       mono_profiler_coverage_unlock ();
 
        return res;
 }
@@ -414,9 +416,9 @@ mono_profiler_coverage_free (MonoMethod *method)
 {
        MonoProfileCoverageInfo* info;
 
-       EnterCriticalSection (&profiler_coverage_mutex);
+       mono_profiler_coverage_lock ();
        if (!coverage_hash) {
-               LeaveCriticalSection (&profiler_coverage_mutex);
+               mono_profiler_coverage_unlock ();
                return;
        }
 
@@ -425,7 +427,7 @@ mono_profiler_coverage_free (MonoMethod *method)
                g_free (info);
                g_hash_table_remove (coverage_hash, method);
        }
-       LeaveCriticalSection (&profiler_coverage_mutex);
+       mono_profiler_coverage_unlock ();
 }
 
 void 
@@ -438,9 +440,9 @@ mono_profiler_coverage_get (MonoProfiler *prof, MonoMethod *method, MonoProfileC
        MonoMethodHeader *header;
        MonoProfileCoverageEntry entry;
 
-       EnterCriticalSection (&profiler_coverage_mutex);
+       mono_profiler_coverage_lock ();
        info = g_hash_table_lookup (coverage_hash, method);
-       LeaveCriticalSection (&profiler_coverage_mutex);
+       mono_profiler_coverage_unlock ();
 
        if (!info)
                return;
@@ -631,8 +633,8 @@ struct _MethodCallProfile {
 struct _AllocInfo {
        AllocInfo *next;
        MonoClass *klass;
-       guint count;
-       guint mem;
+       guint64 count;
+       guint64 mem;
 };
 
 struct _CallerInfo {
@@ -704,7 +706,8 @@ method_get_name (MonoMethod* method)
        char *sig, *res;
        
        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,
+       res = g_strdup_printf ("%s%s%s::%s(%s)", method->klass->name_space,
+                       method->klass->name_space ? "." : "", method->klass->name,
                method->name, sig);
        g_free (sig);
        return res;
@@ -743,13 +746,16 @@ output_profile (GList *funcs)
 
 typedef struct {
        MethodProfile *mp;
-       guint count;
+       guint64 count;
 } NewobjProfile;
 
 static gint
 compare_newobj_profile (NewobjProfile *profa, NewobjProfile *profb)
 {
-       return (gint)profb->count - (gint)profa->count;
+       if (profb->count == profa->count)
+               return 0;
+       else
+               return profb->count > profa->count ? 1 : -1;
 }
 
 static void
@@ -757,7 +763,7 @@ build_newobj_profile (MonoClass *class, MethodProfile *mprof, GList **funcs)
 {
        NewobjProfile *prof = g_new (NewobjProfile, 1);
        AllocInfo *tmp;
-       guint count = 0;
+       guint64 count = 0;
        
        prof->mp = mprof;
        /* we use the total amount of memory to sort */
@@ -825,6 +831,11 @@ output_callers (MethodProfile *p) {
        }
 }
 
+/* This isn't defined on older glib versions and on some platforms */
+#ifndef G_GUINT64_FORMAT
+#define G_GUINT64_FORMAT "ul"
+#endif
+
 static void
 output_newobj_profile (GList *proflist)
 {
@@ -836,7 +847,7 @@ output_newobj_profile (GList *proflist)
        const char* isarray;
        char buf [256];
        char *m;
-       guint total = 0;
+       guint64 total = 0;
        GSList *sorted, *tmps;
 
        g_print ("\nAllocation profiler\n");
@@ -850,7 +861,7 @@ output_newobj_profile (GList *proflist)
                        continue;
                mp = p->mp;
                m = method_get_name (mp->method);
-               g_print ("########################\n%8d KB %s\n", p->count / 1024, m);
+               g_print ("########################\n%8" G_GUINT64_FORMAT " KB %s\n", (p->count / 1024), m);
                g_free (m);
                sorted = sort_alloc_list (mp->alloc_info);
                for (tmps = sorted; tmps; tmps = tmps->next) {
@@ -864,14 +875,14 @@ output_newobj_profile (GList *proflist)
                        } else {
                                isarray = "";
                        }
-                       g_snprintf (buf, sizeof (buf), "%s.%s%s",
-                               klass->name_space, klass->name, isarray);
-                       g_print ("    %8d KB %8d %-48s\n", ainfo->mem / 1024, ainfo->count, buf);
+                       g_snprintf (buf, sizeof (buf), "%s%%s%s",
+                               klass->name_space, klass->name_space ? "." : "", klass->name, isarray);
+                       g_print ("    %8" G_GUINT64_FORMAT " KB %8" G_GUINT64_FORMAT " %-48s\n", (ainfo->mem / 1024), ainfo->count, buf);
                }
                /* callers */
                output_callers (mp);
        }
-       g_print ("Total memory allocated: %d KB\n", total / 1024);
+       g_print ("Total memory allocated: %" G_GUINT64_FORMAT " KB\n", total / 1024);
 }
 
 static void