2009-12-11 Marek Habersack <mhabersack@novell.com>
authorMarek Habersack <grendel@twistedcode.net>
Fri, 11 Dec 2009 21:21:54 +0000 (21:21 -0000)
committerMarek Habersack <grendel@twistedcode.net>
Fri, 11 Dec 2009 21:21:54 +0000 (21:21 -0000)
* object.c (mono_ldstr, mono_ldstr_metadata_sig): added calls to
mono_profiler_string_allocation

mono-profiler-iomap.c - improved output and enabled locking when storing string location.

svn path=/trunk/mono/; revision=148153

mono/metadata/ChangeLog
mono/metadata/object.c
mono/profiler/mono-profiler-iomap.c

index da5496d05aadc8c16d152a417400ffbee5ccb482..c958fc71eb6a8c765b82ecf265d9432188376b9a 100644 (file)
@@ -1,5 +1,8 @@
 2009-12-11  Marek Habersack  <mhabersack@novell.com>
 
+       * object.c (mono_ldstr, mono_ldstr_metadata_sig): added calls to
+       mono_profiler_string_allocation
+
        * string-icalls.c (ves_icall_System_String_InternalAllocateStr):
        if string profiling is enabled, call
        mono_profiler_string_allocation
index 09f26962c4cdac55d3ccbf1151daa73b89d60d0f..2be93565176f64230368c9cf8eb9fab519e4920f 100644 (file)
@@ -5049,7 +5049,10 @@ mono_ldstr (MonoDomain *domain, MonoImage *image, guint32 idx)
        MONO_ARCH_SAVE_REGS;
 
        if (image->dynamic) {
-               return mono_lookup_dynamic_token (image, MONO_TOKEN_STRING | idx, NULL);
+               MonoString *str = mono_lookup_dynamic_token (image, MONO_TOKEN_STRING | idx, NULL);
+               if (mono_profiler_events & MONO_PROFILE_STRING_ALLOC)
+                       mono_profiler_string_allocation (domain, str);
+               return str;
        } else {
                if (!mono_verifier_verify_string_signature (image, idx, NULL))
                        return NULL; /*FIXME we should probably be raising an exception here*/
@@ -5096,6 +5099,9 @@ mono_ldstr_metadata_sig (MonoDomain *domain, const char* sig)
        mono_g_hash_table_insert (domain->ldstr_table, o, o);
        ldstr_unlock ();
 
+       if (mono_profiler_events & MONO_PROFILE_STRING_ALLOC)
+               mono_profiler_string_allocation (domain, o);
+
        return o;
 }
 
index ef129b05efad049b41dc5d4336e2594119e75402..876606f101168119536829cd82009005902264da 100644 (file)
@@ -22,6 +22,7 @@
 #include <mono/metadata/loader.h>
 #include <mono/io-layer/mono-mutex.h>
 
+#define LOCATION_INDENT "        "
 #define BACKTRACE_SIZE 64
 
 typedef struct _MonoStackBacktraceInfo 
@@ -94,13 +95,14 @@ static void mismatched_stats_foreach_func (gpointer key, gpointer value, gpointe
        StringLocation *location;
        MonoProfiler *prof = (MonoProfiler*)user_data;
        guint32 hash;
+       gboolean bannerShown = FALSE;
 
        hash = do_calc_string_hash (0, stats->requestedName);
        fprintf (stdout,
                 "    Count: %u\n"
-                "Requested: %s (hash: 0x%X)\n"
-                "   Actual: %s (hash: 0x%X)\n",
-                stats->count, stats->requestedName, hash, stats->actualName, do_calc_string_hash (0, stats->actualName));
+                "Requested: %s\n"
+                "   Actual: %s\n",
+                stats->count, stats->requestedName, stats->actualName);
 
        if (!prof->may_have_locations) {
                fprintf (stdout, "\n");
@@ -108,12 +110,17 @@ static void mismatched_stats_foreach_func (gpointer key, gpointer value, gpointe
        }
 
        location = g_hash_table_lookup (prof->string_locations_hash, &hash);
-       if (location)
-               fprintf (stdout, "Locations:\n");
-
        while (location) {
-               fprintf (stdout, "    %s", location->hint);
+               if (location->hint && strlen (location->hint) > 0) {
+                       if (!bannerShown) {
+                               fprintf (stdout, "Locations:\n");
+                               bannerShown = TRUE;
+                       }
+                       fprintf (stdout, "%s", location->hint);
+               }
                location = location->next;
+               if (location)
+                       fprintf (stdout, LOCATION_INDENT "--\n");
        }
 
        fprintf (stdout, "\n");
@@ -349,10 +356,10 @@ static inline gchar *build_hint_from_stack (MonoDomain *domain, void **stack, gi
                        methodName = mono_method_full_name (method, TRUE);
 
                        if (location) {
-                               append_report (&trace, "        %s in %s:%u\n", methodName, location->source_file, location->row);
+                               append_report (&trace, LOCATION_INDENT "%s in %s:%u\n", methodName, location->source_file, location->row);
                                mono_debug_free_source_location (location);
                        } else
-                               append_report (&trace, "        %s\n", methodName);
+                               append_report (&trace, LOCATION_INDENT "%s\n", methodName);
                        g_free (methodName);
                }
 
@@ -367,10 +374,10 @@ static inline gchar *build_hint_from_stack (MonoDomain *domain, void **stack, gi
                methodName = mono_method_full_name (selectedMethod, TRUE);
 
                if (location) {
-                       hint = g_strdup_printf ("%s in %s:%u\n", methodName, location->source_file, location->row);
+                       hint = g_strdup_printf (LOCATION_INDENT "%s in %s:%u\n", methodName, location->source_file, location->row);
                        mono_debug_free_source_location (location);
                } else
-                       hint = g_strdup_printf ("%s\n", methodName);
+                       hint = g_strdup_printf (LOCATION_INDENT "%s\n", methodName);
                g_free (methodName);
        }
 
@@ -439,25 +446,19 @@ static void mono_portability_remember_string (MonoProfiler *prof, MonoDomain *do
 {
        SavedString *head, *entry;
 
-       /* fprintf (stdout, "%s (%p, %p, %p)\n", __func__, prof, str, klass); */
-       if (!str || !domain || !runtime_initialized) {
-               /* fprintf (stdout, "\truntime not initialized or str null\n"); */
-               /* fflush (stdout); */
+       if (!str || !domain || !runtime_initialized)
                return;
-       }
 
        entry = (SavedString*)g_malloc0 (sizeof (SavedString));
        entry->string = str;
        entry->domain = domain;
        entry->stack_entries = mono_stack_backtrace (prof, domain, entry->stack, BACKTRACE_SIZE);
-       /* fprintf (stdout, "\tstack_entries == %u\n", entry->stack_entries); */
-       /* fflush (stdout); */
        if (entry->stack_entries == 0) {
                g_free (entry);
                return;
        }
-       
-       //mono_mutex_lock (&mismatched_files_section);
+
+       mono_mutex_lock (&mismatched_files_section);
        head = (SavedString*)g_hash_table_lookup (prof->saved_strings_hash, (gpointer)str);
        if (head) {
                while (head->next)
@@ -465,7 +466,7 @@ static void mono_portability_remember_string (MonoProfiler *prof, MonoDomain *do
                head->next = entry;
        } else
                g_hash_table_insert (prof->saved_strings_hash, (gpointer)str, (gpointer)entry);
-       //mono_mutex_unlock (&mismatched_files_section);
+       mono_mutex_unlock (&mismatched_files_section);
 }
 
 static void mono_portability_iomap_event (MonoProfiler *prof, const char *report, const char *pathname, const char *new_pathname)