[sysprof] libsysprof-capture: translate jitmaps before samples



commit 8f18572499cc9464918d00daa5f1267e4e9e19cd
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 5 19:32:42 2019 -0700

    libsysprof-capture: translate jitmaps before samples
    
    So we have valid addresses to translate, we need to translate the jitmap
    before we translate samples. Otherwise we likely won't have anything to
    translate.

 .../sysprof-capture-writer-cat.c                   | 79 ++++++++++++++--------
 1 file changed, 50 insertions(+), 29 deletions(-)
---
diff --git a/src/libsysprof-capture/sysprof-capture-writer-cat.c 
b/src/libsysprof-capture/sysprof-capture-writer-cat.c
index 54523c5..a210220 100644
--- a/src/libsysprof-capture/sysprof-capture-writer-cat.c
+++ b/src/libsysprof-capture/sysprof-capture-writer-cat.c
@@ -111,7 +111,7 @@ translate_table_add (GArray  **tables,
                      guint64   src,
                      guint64   dst)
 {
-  TranslateItem item = { src, dst };
+  const TranslateItem item = { src, dst };
 
   if (tables[table] == NULL)
     tables[table] = g_array_new (FALSE, FALSE, sizeof (TranslateItem));
@@ -127,6 +127,9 @@ translate_table_translate (GArray  **tables,
   const TranslateItem *item;
   TranslateItem key = { src, 0 };
 
+  if ((src & SYSPROF_CAPTURE_JITMAP_MARK) == 0)
+    return src;
+
   if (!tables[table])
     return src;
 
@@ -161,6 +164,42 @@ sysprof_capture_writer_cat (SysprofCaptureWriter  *self,
   if (start_time < first_start_time)
     first_start_time = start_time;
 
+  /* First we need to find all the JIT maps so that we can translate
+   * addresses later on and have the correct value.
+   */
+  while (sysprof_capture_reader_peek_type (reader, &type))
+    {
+      g_autoptr(GHashTable) jitmap = NULL;
+      GHashTableIter iter;
+      const gchar *name;
+      guint64 addr;
+
+      if (type != SYSPROF_CAPTURE_FRAME_JITMAP)
+        {
+          if (!sysprof_capture_reader_skip (reader))
+            goto panic;
+          continue;
+        }
+
+      if (!(jitmap = sysprof_capture_reader_read_jitmap (reader)))
+        goto panic;
+
+      g_hash_table_iter_init (&iter, jitmap);
+      while (g_hash_table_iter_next (&iter, (gpointer *)&addr, (gpointer *)&name))
+        {
+          guint64 replace = sysprof_capture_writer_add_jitmap (self, name);
+          /* We need to keep a table of replacement addresses so that
+           * we can translate the samples into the destination address
+           * space that we synthesized for the address identifier.
+           */
+          translate_table_add (tables, TRANSLATE_ADDR, addr, replace);
+        }
+    }
+
+  translate_table_sort (tables, TRANSLATE_ADDR);
+
+  sysprof_capture_reader_reset (reader);
+
   while (sysprof_capture_reader_peek_type (reader, &type))
     {
       SysprofCaptureFrame fr;
@@ -324,34 +363,6 @@ sysprof_capture_writer_cat (SysprofCaptureWriter  *self,
             break;
           }
 
-        case SYSPROF_CAPTURE_FRAME_JITMAP:
-          {
-            GHashTable *jitmap;
-            GHashTableIter iter;
-            const gchar *name;
-            guint64 addr;
-
-            if (!(jitmap = sysprof_capture_reader_read_jitmap (reader)))
-              goto panic;
-
-            g_hash_table_iter_init (&iter, jitmap);
-            while (g_hash_table_iter_next (&iter, (gpointer *)&addr, (gpointer *)&name))
-              {
-                guint64 replace = sysprof_capture_writer_add_jitmap (self, name);
-                /* We need to keep a table of replacement addresses so that
-                 * we can translate the samples into the destination address
-                 * space that we synthesized for the address identifier.
-                 */
-                translate_table_add (tables, TRANSLATE_ADDR, addr, replace);
-              }
-
-            translate_table_sort (tables, TRANSLATE_ADDR);
-
-            g_hash_table_unref (jitmap);
-
-            break;
-          }
-
         case SYSPROF_CAPTURE_FRAME_SAMPLE:
           {
             const SysprofCaptureSample *frame;
@@ -455,7 +466,17 @@ sysprof_capture_writer_cat (SysprofCaptureWriter  *self,
             break;
           }
 
+        case SYSPROF_CAPTURE_FRAME_JITMAP:
+          /* We already did this */
+          if (!sysprof_capture_reader_skip (reader))
+            goto panic;
+          break;
+
         default:
+          /* Silently drop, which is better than looping. We could potentially
+           * copy this over using the raw bytes at some point.
+           */
+          sysprof_capture_reader_skip (reader);
           break;
         }
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]