[sysprof/wip/chergert/mem-preload] memprof: allow free to capture frames/size if known



commit 8c5c25b751abbe210365eafce0e5706b11555de2
Author: Christian Hergert <chergert redhat com>
Date:   Wed Feb 5 10:02:42 2020 -0800

    memprof: allow free to capture frames/size if known

 src/libsysprof-capture/sysprof-capture-reader.c    |  14 +-
 src/libsysprof-capture/sysprof-capture-reader.h    |  98 +++---
 src/libsysprof-capture/sysprof-capture-types.h     |  17 +-
 .../sysprof-capture-writer-cat.c                   |   8 +-
 src/libsysprof-capture/sysprof-capture-writer.c    |  33 +-
 src/libsysprof-capture/sysprof-capture-writer.h    | 336 +++++++++++----------
 src/libsysprof/preload/sysprof-memory-collector.c  |   4 +-
 src/libsysprof/sysprof-memprof-profile.c           |   4 +-
 src/tests/allocs-by-size.c                         |   2 +-
 src/tests/cross-thread-frees.c                     |   4 +-
 src/tests/memory-stack-stash.c                     |   2 +-
 src/tests/test-capture.c                           |   2 +-
 src/tools/sysprof-dump.c                           |   4 +-
 13 files changed, 268 insertions(+), 260 deletions(-)
---
diff --git a/src/libsysprof-capture/sysprof-capture-reader.c b/src/libsysprof-capture/sysprof-capture-reader.c
index 925cedd..6867194 100644
--- a/src/libsysprof-capture/sysprof-capture-reader.c
+++ b/src/libsysprof-capture/sysprof-capture-reader.c
@@ -1353,10 +1353,10 @@ sysprof_capture_reader_find_file (SysprofCaptureReader *self,
   return NULL;
 }
 
-const SysprofCaptureMemoryAlloc *
+const SysprofCaptureAllocation *
 sysprof_capture_reader_read_memory_alloc (SysprofCaptureReader *self)
 {
-  SysprofCaptureMemoryAlloc *ma;
+  SysprofCaptureAllocation *ma;
 
   g_assert (self != NULL);
   g_assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
@@ -1365,7 +1365,7 @@ sysprof_capture_reader_read_memory_alloc (SysprofCaptureReader *self)
   if (!sysprof_capture_reader_ensure_space_for (self, sizeof *ma))
     return NULL;
 
-  ma = (SysprofCaptureMemoryAlloc *)(gpointer)&self->buf[self->pos];
+  ma = (SysprofCaptureAllocation *)(gpointer)&self->buf[self->pos];
 
   sysprof_capture_reader_bswap_frame (self, &ma->frame);
 
@@ -1389,7 +1389,7 @@ sysprof_capture_reader_read_memory_alloc (SysprofCaptureReader *self)
   if (!sysprof_capture_reader_ensure_space_for (self, ma->frame.len))
     return NULL;
 
-  ma = (SysprofCaptureMemoryAlloc *)(gpointer)&self->buf[self->pos];
+  ma = (SysprofCaptureAllocation *)(gpointer)&self->buf[self->pos];
 
   if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
     {
@@ -1402,14 +1402,14 @@ sysprof_capture_reader_read_memory_alloc (SysprofCaptureReader *self)
   return ma;
 }
 
-const SysprofCaptureMemoryFree *
+const SysprofCaptureAllocation *
 sysprof_capture_reader_read_memory_free (SysprofCaptureReader *self)
 {
-  SysprofCaptureMemoryFree *mf;
+  SysprofCaptureAllocation *mf;
 
   g_assert (self != NULL);
 
-  mf = (SysprofCaptureMemoryFree *)
+  mf = (SysprofCaptureAllocation *)
     sysprof_capture_reader_read_basic (self,
                                        SYSPROF_CAPTURE_FRAME_MEMORY_FREE,
                                        sizeof *mf - sizeof (SysprofCaptureFrame));
diff --git a/src/libsysprof-capture/sysprof-capture-reader.h b/src/libsysprof-capture/sysprof-capture-reader.h
index 10b34d0..4f3ee6a 100644
--- a/src/libsysprof-capture/sysprof-capture-reader.h
+++ b/src/libsysprof-capture/sysprof-capture-reader.h
@@ -64,90 +64,90 @@ G_BEGIN_DECLS
 typedef struct _SysprofCaptureReader SysprofCaptureReader;
 
 SYSPROF_AVAILABLE_IN_ALL
-SysprofCaptureReader                   *sysprof_capture_reader_new                 (const gchar              
*filename,
-                                                                                    GError                  
**error);
+SysprofCaptureReader               *sysprof_capture_reader_new                 (const gchar               
*filename,
+                                                                                GError                   
**error);
 SYSPROF_AVAILABLE_IN_ALL
-SysprofCaptureReader                   *sysprof_capture_reader_new_from_fd         (int                      
 fd,
-                                                                                    GError                  
**error);
+SysprofCaptureReader               *sysprof_capture_reader_new_from_fd         (int                        
fd,
+                                                                                GError                   
**error);
 SYSPROF_AVAILABLE_IN_ALL
-SysprofCaptureReader                   *sysprof_capture_reader_copy                (SysprofCaptureReader     
*self);
+SysprofCaptureReader               *sysprof_capture_reader_copy                (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-SysprofCaptureReader                   *sysprof_capture_reader_ref                 (SysprofCaptureReader     
*self);
+SysprofCaptureReader               *sysprof_capture_reader_ref                 (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-void                                    sysprof_capture_reader_unref               (SysprofCaptureReader     
*self);
+void                                sysprof_capture_reader_unref               (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-gint                                    sysprof_capture_reader_get_byte_order      (SysprofCaptureReader     
*self);
+gint                                sysprof_capture_reader_get_byte_order      (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-const gchar                            *sysprof_capture_reader_get_filename        (SysprofCaptureReader     
*self);
+const gchar                        *sysprof_capture_reader_get_filename        (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-const gchar                            *sysprof_capture_reader_get_time            (SysprofCaptureReader     
*self);
+const gchar                        *sysprof_capture_reader_get_time            (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-gint64                                  sysprof_capture_reader_get_start_time      (SysprofCaptureReader     
*self);
+gint64                              sysprof_capture_reader_get_start_time      (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-gint64                                  sysprof_capture_reader_get_end_time        (SysprofCaptureReader     
*self);
+gint64                              sysprof_capture_reader_get_end_time        (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-gboolean                                sysprof_capture_reader_skip                (SysprofCaptureReader     
*self);
+gboolean                            sysprof_capture_reader_skip                (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-gboolean                                sysprof_capture_reader_peek_type           (SysprofCaptureReader     
*self,
-                                                                                    SysprofCaptureFrameType  
*type);
+gboolean                            sysprof_capture_reader_peek_type           (SysprofCaptureReader      
*self,
+                                                                                SysprofCaptureFrameType   
*type);
 SYSPROF_AVAILABLE_IN_ALL
-gboolean                                sysprof_capture_reader_peek_frame          (SysprofCaptureReader     
*self,
-                                                                                    SysprofCaptureFrame      
*frame);
+gboolean                            sysprof_capture_reader_peek_frame          (SysprofCaptureReader      
*self,
+                                                                                SysprofCaptureFrame       
*frame);
 SYSPROF_AVAILABLE_IN_ALL
-const SysprofCaptureLog                *sysprof_capture_reader_read_log            (SysprofCaptureReader     
*self);
+const SysprofCaptureLog            *sysprof_capture_reader_read_log            (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-const SysprofCaptureMap                *sysprof_capture_reader_read_map            (SysprofCaptureReader     
*self);
+const SysprofCaptureMap            *sysprof_capture_reader_read_map            (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-const SysprofCaptureMark               *sysprof_capture_reader_read_mark           (SysprofCaptureReader     
*self);
+const SysprofCaptureMark           *sysprof_capture_reader_read_mark           (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-const SysprofCaptureMetadata           *sysprof_capture_reader_read_metadata       (SysprofCaptureReader     
*self);
+const SysprofCaptureMetadata       *sysprof_capture_reader_read_metadata       (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-const SysprofCaptureExit               *sysprof_capture_reader_read_exit           (SysprofCaptureReader     
*self);
+const SysprofCaptureExit           *sysprof_capture_reader_read_exit           (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-const SysprofCaptureFork               *sysprof_capture_reader_read_fork           (SysprofCaptureReader     
*self);
+const SysprofCaptureFork           *sysprof_capture_reader_read_fork           (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-const SysprofCaptureTimestamp          *sysprof_capture_reader_read_timestamp      (SysprofCaptureReader     
*self);
+const SysprofCaptureTimestamp      *sysprof_capture_reader_read_timestamp      (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-const SysprofCaptureProcess            *sysprof_capture_reader_read_process        (SysprofCaptureReader     
*self);
+const SysprofCaptureProcess        *sysprof_capture_reader_read_process        (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-const SysprofCaptureSample             *sysprof_capture_reader_read_sample         (SysprofCaptureReader     
*self);
+const SysprofCaptureSample         *sysprof_capture_reader_read_sample         (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-GHashTable                             *sysprof_capture_reader_read_jitmap         (SysprofCaptureReader     
*self);
+GHashTable                         *sysprof_capture_reader_read_jitmap         (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-const SysprofCaptureCounterDefine      *sysprof_capture_reader_read_counter_define (SysprofCaptureReader     
*self);
+const SysprofCaptureCounterDefine  *sysprof_capture_reader_read_counter_define (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-const SysprofCaptureCounterSet         *sysprof_capture_reader_read_counter_set    (SysprofCaptureReader     
*self);
+const SysprofCaptureCounterSet     *sysprof_capture_reader_read_counter_set    (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-const SysprofCaptureFileChunk          *sysprof_capture_reader_read_file           (SysprofCaptureReader     
*self);
+const SysprofCaptureFileChunk      *sysprof_capture_reader_read_file           (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_3_36
-const SysprofCaptureMemoryAlloc        *sysprof_capture_reader_read_memory_alloc   (SysprofCaptureReader     
*self);
+const SysprofCaptureAllocation     *sysprof_capture_reader_read_memory_alloc   (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_3_36
-const SysprofCaptureMemoryFree         *sysprof_capture_reader_read_memory_free    (SysprofCaptureReader     
*self);
+const SysprofCaptureAllocation     *sysprof_capture_reader_read_memory_free    (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-gboolean                                sysprof_capture_reader_reset               (SysprofCaptureReader     
*self);
+gboolean                            sysprof_capture_reader_reset               (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-gboolean                                sysprof_capture_reader_splice              (SysprofCaptureReader     
*self,
-                                                                                    SysprofCaptureWriter     
*dest,
-                                                                                    GError                  
**error);
+gboolean                            sysprof_capture_reader_splice              (SysprofCaptureReader      
*self,
+                                                                                SysprofCaptureWriter      
*dest,
+                                                                                GError                   
**error);
 SYSPROF_AVAILABLE_IN_ALL
-gboolean                                sysprof_capture_reader_save_as             (SysprofCaptureReader     
*self,
-                                                                                    const gchar              
*filename,
-                                                                                    GError                  
**error);
+gboolean                            sysprof_capture_reader_save_as             (SysprofCaptureReader      
*self,
+                                                                                const gchar               
*filename,
+                                                                                GError                   
**error);
 SYSPROF_AVAILABLE_IN_ALL
-gboolean                                sysprof_capture_reader_get_stat            (SysprofCaptureReader     
*self,
-                                                                                    SysprofCaptureStat       
*st_buf);
+gboolean                            sysprof_capture_reader_get_stat            (SysprofCaptureReader      
*self,
+                                                                                SysprofCaptureStat        
*st_buf);
 SYSPROF_AVAILABLE_IN_ALL
-void                                    sysprof_capture_reader_set_stat            (SysprofCaptureReader     
*self,
-                                                                                    const SysprofCaptureStat 
*st_buf);
+void                                sysprof_capture_reader_set_stat            (SysprofCaptureReader      
*self,
+                                                                                const SysprofCaptureStat  
*st_buf);
 SYSPROF_AVAILABLE_IN_ALL
-const SysprofCaptureFileChunk          *sysprof_capture_reader_find_file           (SysprofCaptureReader     
*self,
-                                                                                    const gchar              
*path);
+const SysprofCaptureFileChunk      *sysprof_capture_reader_find_file           (SysprofCaptureReader      
*self,
+                                                                                const gchar               
*path);
 SYSPROF_AVAILABLE_IN_ALL
-gchar                                 **sysprof_capture_reader_list_files          (SysprofCaptureReader     
*self);
+gchar                             **sysprof_capture_reader_list_files          (SysprofCaptureReader      
*self);
 SYSPROF_AVAILABLE_IN_ALL
-gboolean                                sysprof_capture_reader_read_file_fd        (SysprofCaptureReader     
*self,
-                                                                                    const gchar              
*path,
-                                                                                    gint                     
 fd);
+gboolean                            sysprof_capture_reader_read_file_fd        (SysprofCaptureReader      
*self,
+                                                                                const gchar               
*path,
+                                                                                gint                       
fd);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofCaptureReader, sysprof_capture_reader_unref)
 
diff --git a/src/libsysprof-capture/sysprof-capture-types.h b/src/libsysprof-capture/sysprof-capture-types.h
index f6e939e..13e2eed 100644
--- a/src/libsysprof-capture/sysprof-capture-types.h
+++ b/src/libsysprof-capture/sysprof-capture-types.h
@@ -319,20 +319,11 @@ typedef struct
   SysprofCaptureFrame   frame;
   SysprofCaptureAddress alloc_addr;
   gint64                alloc_size;
+  gint32                tid;
   guint32               n_addrs : 16;
   guint32               padding1 : 16;
-  gint32                tid;
   SysprofCaptureAddress addrs[0];
-} SysprofCaptureMemoryAlloc
-SYSPROF_ALIGNED_END(1);
-
-SYSPROF_ALIGNED_BEGIN(1)
-typedef struct
-{
-  SysprofCaptureFrame   frame;
-  SysprofCaptureAddress alloc_addr;
-  gint32                tid;
-} SysprofCaptureMemoryFree
+} SysprofCaptureAllocation
 SYSPROF_ALIGNED_END(1);
 
 G_STATIC_ASSERT (sizeof (SysprofCaptureFileHeader) == 256);
@@ -352,8 +343,8 @@ G_STATIC_ASSERT (sizeof (SysprofCaptureMark) == 96);
 G_STATIC_ASSERT (sizeof (SysprofCaptureMetadata) == 64);
 G_STATIC_ASSERT (sizeof (SysprofCaptureLog) == 64);
 G_STATIC_ASSERT (sizeof (SysprofCaptureFileChunk) == 284);
-G_STATIC_ASSERT (sizeof (SysprofCaptureMemoryAlloc) == 48);
-G_STATIC_ASSERT ((G_STRUCT_OFFSET (SysprofCaptureMemoryAlloc, addrs) % 8) == 0);
+G_STATIC_ASSERT (sizeof (SysprofCaptureAllocation) == 48);
+G_STATIC_ASSERT ((G_STRUCT_OFFSET (SysprofCaptureAllocation, addrs) % 8) == 0);
 
 static inline gint
 sysprof_capture_address_compare (SysprofCaptureAddress a,
diff --git a/src/libsysprof-capture/sysprof-capture-writer-cat.c 
b/src/libsysprof-capture/sysprof-capture-writer-cat.c
index 2ea6e32..b699d1e 100644
--- a/src/libsysprof-capture/sysprof-capture-writer-cat.c
+++ b/src/libsysprof-capture/sysprof-capture-writer-cat.c
@@ -478,7 +478,7 @@ sysprof_capture_writer_cat (SysprofCaptureWriter  *self,
           break;
 
         case SYSPROF_CAPTURE_FRAME_MEMORY_ALLOC: {
-          const SysprofCaptureMemoryAlloc *frame;
+          const SysprofCaptureAllocation *frame;
 
           if (!(frame = sysprof_capture_reader_read_memory_alloc (reader)))
             goto panic;
@@ -496,7 +496,7 @@ sysprof_capture_writer_cat (SysprofCaptureWriter  *self,
         }
 
         case SYSPROF_CAPTURE_FRAME_MEMORY_FREE: {
-          const SysprofCaptureMemoryFree *frame;
+          const SysprofCaptureAllocation *frame;
 
           if (!(frame = sysprof_capture_reader_read_memory_free (reader)))
             goto panic;
@@ -506,7 +506,9 @@ sysprof_capture_writer_cat (SysprofCaptureWriter  *self,
                                                   frame->frame.cpu,
                                                   frame->frame.pid,
                                                   frame->tid,
-                                                  frame->alloc_addr);
+                                                  frame->alloc_addr,
+                                                  frame->addrs,
+                                                  frame->n_addrs);
           break;
         }
 
diff --git a/src/libsysprof-capture/sysprof-capture-writer.c b/src/libsysprof-capture/sysprof-capture-writer.c
index d4d691b..9005471 100644
--- a/src/libsysprof-capture/sysprof-capture-writer.c
+++ b/src/libsysprof-capture/sysprof-capture-writer.c
@@ -1529,14 +1529,14 @@ sysprof_capture_writer_add_memory_alloc (SysprofCaptureWriter        *self,
                                          const SysprofCaptureAddress *addrs,
                                          guint                        n_addrs)
 {
-  SysprofCaptureMemoryAlloc *ev;
+  SysprofCaptureAllocation *ev;
   gsize len;
 
   g_assert (self != NULL);
 
   len = sizeof *ev + (n_addrs * sizeof (SysprofCaptureAddress));
 
-  ev = (SysprofCaptureMemoryAlloc *)sysprof_capture_writer_allocate (self, &len);
+  ev = (SysprofCaptureAllocation *)sysprof_capture_writer_allocate (self, &len);
   if (!ev)
     return FALSE;
 
@@ -1550,8 +1550,10 @@ sysprof_capture_writer_add_memory_alloc (SysprofCaptureWriter        *self,
   ev->alloc_addr = alloc_addr;
   ev->n_addrs = n_addrs;
   ev->tid = tid;
+  ev->padding1 = 0;
 
-  memcpy (ev->addrs, addrs, (n_addrs * sizeof (SysprofCaptureAddress)));
+  if (n_addrs > 0)
+    memcpy (ev->addrs, addrs, (n_addrs * sizeof (SysprofCaptureAddress)));
 
   self->stat.frame_count[SYSPROF_CAPTURE_FRAME_MEMORY_ALLOC]++;
 
@@ -1567,13 +1569,13 @@ sysprof_capture_writer_add_memory_alloc_with_backtrace (SysprofCaptureWriter  *s
                                                         SysprofCaptureAddress  alloc_addr,
                                                         gsize                  alloc_size)
 {
-  SysprofCaptureMemoryAlloc *ev;
+  SysprofCaptureAllocation *ev;
   gsize len;
 
   g_assert (self != NULL);
 
   len = sizeof *ev + (MAX_UNWIND_DEPTH * sizeof (SysprofCaptureAddress));
-  ev = (SysprofCaptureMemoryAlloc *)sysprof_capture_writer_allocate (self, &len);
+  ev = (SysprofCaptureAllocation *)sysprof_capture_writer_allocate (self, &len);
   if (!ev)
     return FALSE;
 
@@ -1638,14 +1640,18 @@ sysprof_capture_writer_add_memory_free (SysprofCaptureWriter        *self,
                                         gint                         cpu,
                                         gint32                       pid,
                                         gint32                       tid,
-                                        SysprofCaptureAddress        alloc_addr)
+                                        SysprofCaptureAddress        alloc_addr,
+                                        const SysprofCaptureAddress *addrs,
+                                        guint                        n_addrs)
 {
-  SysprofCaptureMemoryFree *ev;
-  gsize len = sizeof *ev;
+  SysprofCaptureAllocation *ev;
+  gsize len;
 
   g_assert (self != NULL);
 
-  ev = (SysprofCaptureMemoryFree *)sysprof_capture_writer_allocate (self, &len);
+  len = sizeof *ev + (n_addrs * sizeof (SysprofCaptureAddress));
+
+  ev = (SysprofCaptureAllocation *)sysprof_capture_writer_allocate (self, &len);
   if (!ev)
     return FALSE;
 
@@ -1655,9 +1661,14 @@ sysprof_capture_writer_add_memory_free (SysprofCaptureWriter        *self,
                                      pid,
                                      time,
                                      SYSPROF_CAPTURE_FRAME_MEMORY_FREE);
-
-  ev->tid = tid;
+  ev->alloc_size = 0;
   ev->alloc_addr = alloc_addr;
+  ev->n_addrs = n_addrs;
+  ev->tid = tid;
+  ev->padding1 = 0;
+
+  if (n_addrs > 0)
+    memcpy (ev->addrs, addrs, (n_addrs * sizeof (SysprofCaptureAddress)));
 
   self->stat.frame_count[SYSPROF_CAPTURE_FRAME_MEMORY_FREE]++;
 
diff --git a/src/libsysprof-capture/sysprof-capture-writer.h b/src/libsysprof-capture/sysprof-capture-writer.h
index e651ae7..2eaeeab 100644
--- a/src/libsysprof-capture/sysprof-capture-writer.h
+++ b/src/libsysprof-capture/sysprof-capture-writer.h
@@ -64,178 +64,180 @@ G_BEGIN_DECLS
 typedef struct _SysprofCaptureWriter SysprofCaptureWriter;
 
 SYSPROF_AVAILABLE_IN_ALL
-SysprofCaptureWriter *sysprof_capture_writer_new_from_env    (gsize                              
buffer_size);
-SYSPROF_AVAILABLE_IN_ALL
-SysprofCaptureWriter *sysprof_capture_writer_new             (const gchar                       *filename,
-                                                              gsize                              
buffer_size);
-SYSPROF_AVAILABLE_IN_ALL
-SysprofCaptureWriter *sysprof_capture_writer_new_from_fd     (int                                fd,
-                                                              gsize                              
buffer_size);
-SYSPROF_AVAILABLE_IN_ALL
-gsize                 sysprof_capture_writer_get_buffer_size (SysprofCaptureWriter              *self);
-SYSPROF_AVAILABLE_IN_ALL
-SysprofCaptureWriter *sysprof_capture_writer_ref             (SysprofCaptureWriter              *self);
-SYSPROF_AVAILABLE_IN_ALL
-void                  sysprof_capture_writer_unref           (SysprofCaptureWriter              *self);
-SYSPROF_AVAILABLE_IN_ALL
-void                  sysprof_capture_writer_stat            (SysprofCaptureWriter              *self,
-                                                              SysprofCaptureStat                *stat);
-SYSPROF_AVAILABLE_IN_ALL
-void                  sysprof_capture_writer_set_flush_delay (SysprofCaptureWriter              *self,
-                                                              GMainContext                      
*main_context,
-                                                              guint                              
timeout_seconds);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_add_file        (SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid,
-                                                              const gchar                       *path,
-                                                              gboolean                           is_last,
-                                                              const guint8                      *data,
-                                                              gsize                              data_len);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_add_file_fd     (SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid,
-                                                              const gchar                       *path,
-                                                              gint                               fd);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_add_map         (SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid,
-                                                              guint64                            start,
-                                                              guint64                            end,
-                                                              guint64                            offset,
-                                                              guint64                            inode,
-                                                              const gchar                       *filename);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_add_mark        (SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid,
-                                                              guint64                            duration,
-                                                              const gchar                       *group,
-                                                              const gchar                       *name,
-                                                              const gchar                       *message);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_add_metadata    (SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid,
-                                                              const gchar                       *id,
-                                                              const gchar                       *metadata,
-                                                              gssize                             
metadata_len);
-SYSPROF_AVAILABLE_IN_ALL
-guint64               sysprof_capture_writer_add_jitmap      (SysprofCaptureWriter              *self,
-                                                              const gchar                       *name);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_add_process     (SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid,
-                                                              const gchar                       *cmdline);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_add_sample      (SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid,
-                                                              gint32                             tid,
-                                                              const SysprofCaptureAddress       *addrs,
-                                                              guint                              n_addrs);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_add_fork        (SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid,
-                                                              gint32                             child_pid);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_add_exit        (SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_add_timestamp   (SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_define_counters (SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid,
-                                                              const SysprofCaptureCounter       *counters,
-                                                              guint                              n_counters);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_set_counters    (SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid,
-                                                              const guint                       
*counters_ids,
-                                                              const SysprofCaptureCounterValue  *values,
-                                                              guint                              n_counters);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_add_log         (SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid,
-                                                              GLogLevelFlags                     severity,
-                                                              const gchar                       *domain,
-                                                              const gchar                       *message);
+SysprofCaptureWriter *sysprof_capture_writer_new_from_env                    (gsize                          
    buffer_size);
+SYSPROF_AVAILABLE_IN_ALL
+SysprofCaptureWriter *sysprof_capture_writer_new                             (const gchar                    
   *filename,
+                                                                              gsize                          
    buffer_size);
+SYSPROF_AVAILABLE_IN_ALL
+SysprofCaptureWriter *sysprof_capture_writer_new_from_fd                     (int                            
    fd,
+                                                                              gsize                          
    buffer_size);
+SYSPROF_AVAILABLE_IN_ALL
+gsize                 sysprof_capture_writer_get_buffer_size                 (SysprofCaptureWriter           
   *self);
+SYSPROF_AVAILABLE_IN_ALL
+SysprofCaptureWriter *sysprof_capture_writer_ref                             (SysprofCaptureWriter           
   *self);
+SYSPROF_AVAILABLE_IN_ALL
+void                  sysprof_capture_writer_unref                           (SysprofCaptureWriter           
   *self);
+SYSPROF_AVAILABLE_IN_ALL
+void                  sysprof_capture_writer_stat                            (SysprofCaptureWriter           
   *self,
+                                                                              SysprofCaptureStat             
   *stat);
+SYSPROF_AVAILABLE_IN_ALL
+void                  sysprof_capture_writer_set_flush_delay                 (SysprofCaptureWriter           
   *self,
+                                                                              GMainContext                   
   *main_context,
+                                                                              guint                          
    timeout_seconds);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_add_file                        (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid,
+                                                                              const gchar                    
   *path,
+                                                                              gboolean                       
    is_last,
+                                                                              const guint8                   
   *data,
+                                                                              gsize                          
    data_len);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_add_file_fd                     (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid,
+                                                                              const gchar                    
   *path,
+                                                                              gint                           
    fd);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_add_map                         (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid,
+                                                                              guint64                        
    start,
+                                                                              guint64                        
    end,
+                                                                              guint64                        
    offset,
+                                                                              guint64                        
    inode,
+                                                                              const gchar                    
   *filename);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_add_mark                        (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid,
+                                                                              guint64                        
    duration,
+                                                                              const gchar                    
   *group,
+                                                                              const gchar                    
   *name,
+                                                                              const gchar                    
   *message);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_add_metadata                    (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid,
+                                                                              const gchar                    
   *id,
+                                                                              const gchar                    
   *metadata,
+                                                                              gssize                         
    metadata_len);
+SYSPROF_AVAILABLE_IN_ALL
+guint64               sysprof_capture_writer_add_jitmap                      (SysprofCaptureWriter           
   *self,
+                                                                              const gchar                    
   *name);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_add_process                     (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid,
+                                                                              const gchar                    
   *cmdline);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_add_sample                      (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid,
+                                                                              gint32                         
    tid,
+                                                                              const SysprofCaptureAddress    
   *addrs,
+                                                                              guint                          
    n_addrs);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_add_fork                        (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid,
+                                                                              gint32                         
    child_pid);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_add_exit                        (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_add_timestamp                   (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_define_counters                 (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid,
+                                                                              const SysprofCaptureCounter    
   *counters,
+                                                                              guint                          
    n_counters);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_set_counters                    (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid,
+                                                                              const guint                    
   *counters_ids,
+                                                                              const 
SysprofCaptureCounterValue  *values,
+                                                                              guint                          
    n_counters);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_add_log                         (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid,
+                                                                              GLogLevelFlags                 
    severity,
+                                                                              const gchar                    
   *domain,
+                                                                              const gchar                    
   *message);
 SYSPROF_AVAILABLE_IN_3_36
-gboolean              sysprof_capture_writer_add_memory_alloc(SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid,
-                                                              gint32                             tid,
-                                                              SysprofCaptureAddress              alloc_addr,
-                                                              gsize                              alloc_size,
-                                                              const SysprofCaptureAddress       *addrs,
-                                                              guint                              n_addrs);
+gboolean              sysprof_capture_writer_add_memory_alloc                (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid,
+                                                                              gint32                         
    tid,
+                                                                              SysprofCaptureAddress          
    alloc_addr,
+                                                                              gsize                          
    alloc_size,
+                                                                              const SysprofCaptureAddress    
   *addrs,
+                                                                              guint                          
    n_addrs);
 SYSPROF_AVAILABLE_IN_3_36
-gboolean              sysprof_capture_writer_add_memory_alloc_with_backtrace (SysprofCaptureWriter  *self,
-                                                                              gint64                 time,
-                                                                              gint                   cpu,
-                                                                              gint32                 pid,
-                                                                              gint32                 tid,
-                                                                              SysprofCaptureAddress  
alloc_addr,
-                                                                              gsize                  
alloc_size);
+gboolean              sysprof_capture_writer_add_memory_alloc_with_backtrace (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid,
+                                                                              gint32                         
    tid,
+                                                                              SysprofCaptureAddress          
    alloc_addr,
+                                                                              gsize                          
    alloc_size);
 SYSPROF_AVAILABLE_IN_3_36
-gboolean              sysprof_capture_writer_add_memory_free (SysprofCaptureWriter              *self,
-                                                              gint64                             time,
-                                                              gint                               cpu,
-                                                              gint32                             pid,
-                                                              gint32                             tid,
-                                                              SysprofCaptureAddress              alloc_addr);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_flush           (SysprofCaptureWriter              *self);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_save_as         (SysprofCaptureWriter              *self,
-                                                              const gchar                       *filename,
-                                                              GError                           **error);
-SYSPROF_AVAILABLE_IN_ALL
-guint                 sysprof_capture_writer_request_counter (SysprofCaptureWriter              *self,
-                                                              guint                              n_counters);
-SYSPROF_AVAILABLE_IN_ALL
-SysprofCaptureReader *sysprof_capture_writer_create_reader   (SysprofCaptureWriter              *self,
-                                                              GError                           **error);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_splice          (SysprofCaptureWriter              *self,
-                                                              SysprofCaptureWriter              *dest,
-                                                              GError                           **error);
-SYSPROF_AVAILABLE_IN_ALL
-gboolean              sysprof_capture_writer_cat             (SysprofCaptureWriter              *self,
-                                                              SysprofCaptureReader              *reader,
-                                                              GError                           **error);
+gboolean              sysprof_capture_writer_add_memory_free                 (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    time,
+                                                                              gint                           
    cpu,
+                                                                              gint32                         
    pid,
+                                                                              gint32                         
    tid,
+                                                                              SysprofCaptureAddress          
    alloc_addr,
+                                                                              const SysprofCaptureAddress    
   *addrs,
+                                                                              guint                          
    n_addrs);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_flush                           (SysprofCaptureWriter           
   *self);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_save_as                         (SysprofCaptureWriter           
   *self,
+                                                                              const gchar                    
   *filename,
+                                                                              GError                         
  **error);
+SYSPROF_AVAILABLE_IN_ALL
+guint                 sysprof_capture_writer_request_counter                 (SysprofCaptureWriter           
   *self,
+                                                                              guint                          
    n_counters);
+SYSPROF_AVAILABLE_IN_ALL
+SysprofCaptureReader *sysprof_capture_writer_create_reader                   (SysprofCaptureWriter           
   *self,
+                                                                              GError                         
  **error);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_splice                          (SysprofCaptureWriter           
   *self,
+                                                                              SysprofCaptureWriter           
   *dest,
+                                                                              GError                         
  **error);
+SYSPROF_AVAILABLE_IN_ALL
+gboolean              sysprof_capture_writer_cat                             (SysprofCaptureWriter           
   *self,
+                                                                              SysprofCaptureReader           
   *reader,
+                                                                              GError                         
  **error);
 G_GNUC_INTERNAL
-gboolean              _sysprof_capture_writer_splice_from_fd (SysprofCaptureWriter              *self,
-                                                              int                                fd,
-                                                              GError                           **error) 
G_GNUC_INTERNAL;
+gboolean              _sysprof_capture_writer_splice_from_fd                 (SysprofCaptureWriter           
   *self,
+                                                                              int                            
    fd,
+                                                                              GError                         
  **error) G_GNUC_INTERNAL;
 G_GNUC_INTERNAL
-gboolean              _sysprof_capture_writer_set_time_range (SysprofCaptureWriter              *self,
-                                                              gint64                             start_time,
-                                                              gint64                             end_time) 
G_GNUC_INTERNAL;
+gboolean              _sysprof_capture_writer_set_time_range                 (SysprofCaptureWriter           
   *self,
+                                                                              gint64                         
    start_time,
+                                                                              gint64                         
    end_time) G_GNUC_INTERNAL;
 
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofCaptureWriter, sysprof_capture_writer_unref)
diff --git a/src/libsysprof/preload/sysprof-memory-collector.c 
b/src/libsysprof/preload/sysprof-memory-collector.c
index 16a12e1..2b3d19c 100644
--- a/src/libsysprof/preload/sysprof-memory-collector.c
+++ b/src/libsysprof/preload/sysprof-memory-collector.c
@@ -168,7 +168,9 @@ track_free (void *ptr)
                                           sched_getcpu (),
                                           pid,
                                           gettid(),
-                                          GPOINTER_TO_SIZE (ptr));
+                                          GPOINTER_TO_SIZE (ptr),
+                                          NULL, /* TODO: Too slow for now */
+                                          0);
   G_UNLOCK (writer);
 }
 
diff --git a/src/libsysprof/sysprof-memprof-profile.c b/src/libsysprof/sysprof-memprof-profile.c
index 5422b3d..3a14423 100644
--- a/src/libsysprof/sysprof-memprof-profile.c
+++ b/src/libsysprof/sysprof-memprof-profile.c
@@ -228,7 +228,7 @@ cursor_foreach_cb (const SysprofCaptureFrame *frame,
   if (frame->type == SYSPROF_CAPTURE_FRAME_MEMORY_FREE)
     {
 #if 0
-      const SysprofCaptureMemoryFree *ev = (const SysprofCaptureMemoryFree *)frame;
+      const SysprofCaptureAllocation *ev = (const SysprofCaptureAllocation *)frame;
 
       raxRemove (g->rax,
                  (guint8 *)&ev->alloc_addr,
@@ -254,7 +254,7 @@ cursor_foreach_cb (const SysprofCaptureFrame *frame,
   /* Handle memory allocations */
   if (frame->type == SYSPROF_CAPTURE_FRAME_MEMORY_ALLOC)
     {
-      const SysprofCaptureMemoryAlloc *ev = (const SysprofCaptureMemoryAlloc *)frame;
+      const SysprofCaptureAllocation *ev = (const SysprofCaptureAllocation *)frame;
       SysprofAddressContext last_context = SYSPROF_ADDRESS_CONTEXT_NONE;
       const gchar *cmdline;
       StackNode *node;
diff --git a/src/tests/allocs-by-size.c b/src/tests/allocs-by-size.c
index 227862e..7f8836f 100644
--- a/src/tests/allocs-by-size.c
+++ b/src/tests/allocs-by-size.c
@@ -64,7 +64,7 @@ allocs_by_size (SysprofCaptureReader *reader)
     {
       if (type == SYSPROF_CAPTURE_FRAME_MEMORY_ALLOC)
         {
-          const SysprofCaptureMemoryAlloc *ev = sysprof_capture_reader_read_memory_alloc (reader);
+          const SysprofCaptureAllocation *ev = sysprof_capture_reader_read_memory_alloc (reader);
 
           if (ev == NULL)
             break;
diff --git a/src/tests/cross-thread-frees.c b/src/tests/cross-thread-frees.c
index b24d7e8..56cb495 100644
--- a/src/tests/cross-thread-frees.c
+++ b/src/tests/cross-thread-frees.c
@@ -70,7 +70,7 @@ cross_thread_frees (SysprofCaptureReader *reader)
     {
       if (type == SYSPROF_CAPTURE_FRAME_MEMORY_ALLOC)
         {
-          const SysprofCaptureMemoryAlloc *ev = sysprof_capture_reader_read_memory_alloc (reader);
+          const SysprofCaptureAllocation *ev = sysprof_capture_reader_read_memory_alloc (reader);
 
           if (ev == NULL)
             break;
@@ -82,7 +82,7 @@ cross_thread_frees (SysprofCaptureReader *reader)
         }
       else if (type == SYSPROF_CAPTURE_FRAME_MEMORY_FREE)
         {
-          const SysprofCaptureMemoryFree *ev = sysprof_capture_reader_read_memory_free (reader);
+          const SysprofCaptureAllocation *ev = sysprof_capture_reader_read_memory_free (reader);
           gpointer key = GINT_TO_POINTER (ev->alloc_addr);
           Stack *stack;
 
diff --git a/src/tests/memory-stack-stash.c b/src/tests/memory-stack-stash.c
index e6ec1a1..38184bc 100644
--- a/src/tests/memory-stack-stash.c
+++ b/src/tests/memory-stack-stash.c
@@ -38,7 +38,7 @@ memory_stack_stash (SysprofCaptureReader *reader)
     {
       if (type == SYSPROF_CAPTURE_FRAME_MEMORY_ALLOC)
         {
-          const SysprofCaptureMemoryAlloc *ev = sysprof_capture_reader_read_memory_alloc (reader);
+          const SysprofCaptureAllocation *ev = sysprof_capture_reader_read_memory_alloc (reader);
 
           if (ev == NULL)
             break;
diff --git a/src/tests/test-capture.c b/src/tests/test-capture.c
index 3102788..8c90a44 100644
--- a/src/tests/test-capture.c
+++ b/src/tests/test-capture.c
@@ -936,7 +936,7 @@ test_writer_memory_alloc_free (void)
 
   for (guint i = 0; i < 20; i++)
     {
-      const SysprofCaptureMemoryAlloc *ev;
+      const SysprofCaptureAllocation *ev;
 
       ev = sysprof_capture_reader_read_memory_alloc (reader);
       g_assert_nonnull (ev);
diff --git a/src/tools/sysprof-dump.c b/src/tools/sysprof-dump.c
index fe3da77..497f09e 100644
--- a/src/tools/sysprof-dump.c
+++ b/src/tools/sysprof-dump.c
@@ -301,7 +301,7 @@ main (gint argc,
 
         case SYSPROF_CAPTURE_FRAME_MEMORY_ALLOC:
           {
-            const SysprofCaptureMemoryAlloc *ev = sysprof_capture_reader_read_memory_alloc (reader);
+            const SysprofCaptureAllocation *ev = sysprof_capture_reader_read_memory_alloc (reader);
             gdouble ptime = (ev->frame.time - begin_time) / (gdouble)SYSPROF_NSEC_PER_SEC;
 
             g_print ("MALLOC: pid=%d tid=%d addr=0x%"G_GINT64_MODIFIER"x size=%"G_GUINT64_FORMAT" 
time=%"G_GINT64_FORMAT" (%lf)\n",
@@ -313,7 +313,7 @@ main (gint argc,
 
         case SYSPROF_CAPTURE_FRAME_MEMORY_FREE:
           {
-            const SysprofCaptureMemoryFree *ev = sysprof_capture_reader_read_memory_free (reader);
+            const SysprofCaptureAllocation *ev = sysprof_capture_reader_read_memory_free (reader);
             gdouble ptime = (ev->frame.time - begin_time) / (gdouble)SYSPROF_NSEC_PER_SEC;
 
             g_print ("FREE: pid=%d tid=%d addr=0x%"G_GINT64_MODIFIER"x time=%"G_GINT64_FORMAT" (%lf)\n",


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