]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Add various bin-related trace path flags
authorDJ Delorie <dj@delorie.com>
Thu, 21 Jul 2016 19:33:27 +0000 (15:33 -0400)
committerDJ Delorie <dj@delorie.com>
Thu, 21 Jul 2016 19:33:27 +0000 (15:33 -0400)
malloc/malloc.c
malloc/mtrace.h
malloc/trace_dump.c

index 975373117414f577769a7c98f91eaaf6fec9b246..dad7921f8e6d5046d913cd46007837203c2fdc89 100644 (file)
@@ -1192,6 +1192,13 @@ __mtb_trace_entry (uint32_t type, size_t size, void *ptr1)
   trace_ptr->path_mmap = 0;
   trace_ptr->path_munmap = 0;
   trace_ptr->path_m_f_realloc = 0;
+  trace_ptr->path_hook = 0;
+  trace_ptr->path_unsorted_add = 0;
+  trace_ptr->path_unsorted_remove = 0;
+  trace_ptr->path_unsorted_empty = 0;
+  trace_ptr->path_fastbin_add = 0;
+  trace_ptr->path_fastbin_remove = 0;
+  trace_ptr->path_malloc_consolidate = 0;
   trace_ptr->path = 0;
   trace_ptr->ptr1 = ptr1;
   trace_ptr->ptr2 = 0;
@@ -4284,6 +4291,7 @@ _int_malloc (mstate av, size_t bytes)
                }
            }
 #endif
+          __MTB_TRACE_PATH(fastbin_remove);
           void *p = chunk2mem (victim);
           alloc_perturb (p, bytes);
           return p;
@@ -4415,6 +4423,7 @@ _int_malloc (mstate av, size_t bytes)
       int iters = 0;
       while ((victim = unsorted_chunks (av)->bk) != unsorted_chunks (av))
         {
+          __MTB_TRACE_PATH(unsorted_remove);
           bck = victim->bk;
           if (__builtin_expect (victim->size <= 2 * SIZE_SZ, 0)
               || __builtin_expect (victim->size > av->system_mem, 0))
@@ -4436,6 +4445,7 @@ _int_malloc (mstate av, size_t bytes)
               (unsigned long) (size) > (unsigned long) (nb + MINSIZE))
             {
               /* split and reattach remainder */
+             __MTB_TRACE_PATH(unsorted_add);
               remainder_size = size - nb;
               remainder = chunk_at_offset (victim, nb);
               unsorted_chunks (av)->bk = unsorted_chunks (av)->fd = remainder;
@@ -4574,6 +4584,9 @@ _int_malloc (mstate av, size_t bytes)
           if (++iters >= MAX_ITERS)
             break;
         }
+      if (unsorted_chunks (av)->bk == unsorted_chunks (av))
+       __MTB_TRACE_PATH(unsorted_empty);
+
 
 #if USE_TCACHE
       /* If all the small chunks we found ended up cached, return one now.  */
@@ -4625,6 +4638,7 @@ _int_malloc (mstate av, size_t bytes)
                   remainder = chunk_at_offset (victim, nb);
                   /* We cannot assume the unsorted list is empty and therefore
                      have to perform a complete insert here.  */
+                 __MTB_TRACE_PATH(unsorted_add);
                   bck = unsorted_chunks (av);
                   fwd = bck->fd;
          if (__glibc_unlikely (fwd->bk != bck))
@@ -4737,6 +4751,7 @@ _int_malloc (mstate av, size_t bytes)
 
                   /* We cannot assume the unsorted list is empty and therefore
                      have to perform a complete insert here.  */
+                 __MTB_TRACE_PATH(unsorted_add);
                   bck = unsorted_chunks (av);
                   fwd = bck->fd;
          if (__glibc_unlikely (fwd->bk != bck))
@@ -4959,6 +4974,7 @@ _int_free (mstate av, mchunkptr p, int have_lock)
     fb = &fastbin (av, idx);
 
     /* Atomically link P to its fastbin: P->FD = *FB; *FB = P;  */
+    __MTB_TRACE_PATH(fastbin_add);
     mchunkptr old = *fb, old2;
     unsigned int old_idx = ~0u;
     do
@@ -5056,6 +5072,7 @@ _int_free (mstate av, mchunkptr p, int have_lock)
        been given one chance to be used in malloc.
       */
 
+      __MTB_TRACE_PATH(unsorted_add);
       bck = unsorted_chunks(av);
       fwd = bck->fd;
       if (__glibc_unlikely (fwd->bk != bck))
@@ -5170,6 +5187,8 @@ static void malloc_consolidate(mstate av)
   mchunkptr       bck;
   mchunkptr       fwd;
 
+  __MTB_TRACE_PATH(malloc_consolidate);
+
   /*
     If max_fast is 0, we know that av hasn't
     yet been initialized, in which case do so below
@@ -5197,6 +5216,7 @@ static void malloc_consolidate(mstate av)
          check_inuse_chunk(av, p);
          nextp = p->fd;
 
+          __MTB_TRACE_PATH(fastbin_remove);
          /* Slightly streamlined version of consolidation code in free() */
          size = p->size & ~(PREV_INUSE|NON_MAIN_ARENA);
          nextchunk = chunk_at_offset(p, size);
@@ -5218,6 +5238,7 @@ static void malloc_consolidate(mstate av)
            } else
              clear_inuse_bit_at_offset(nextchunk, 0);
 
+           __MTB_TRACE_PATH(unsorted_add);
            first_unsorted = unsorted_bin->fd;
            unsorted_bin->fd = p;
            first_unsorted->bk = p;
index 6ce663deb00073bbb0f58a648add0d752e6e4bbb..b151f479f813473d1ff17505840c4622eeac52e5 100644 (file)
@@ -34,7 +34,13 @@ struct __malloc_trace_buffer_s {
   uint32_t path_munmap:1; /* munmap was called */
   uint32_t path_m_f_realloc:1; /* realloc became malloc/free (i.e. next few records) */
   uint32_t path_hook:1; /* A hook was used to complete the request */
-  uint32_t path:16; /* remaining bits */
+  uint32_t path_unsorted_add:1; /* something was added to the unsorted bin */
+  uint32_t path_unsorted_remove:1; /* something was removed from the unsorted bin */
+  uint32_t path_unsorted_empty:1; /* the unsorted bin was emptied */
+  uint32_t path_fastbin_add:1; /* something was added to a fastbin */
+  uint32_t path_fastbin_remove:1; /* something was removed from a fastbin */
+  uint32_t path_malloc_consolidate:1; /* something was removed from a fastbin */
+  uint32_t path:10; /* remaining bits */
 
   /* FREE - pointer to allocation to free.
      REALLOC - pointer to original allocation.
index 7b691d9ed0e5c713040416a5a7524c8804761876..95535cd59c2a49ac0a40a2f23b31163b9914d434 100644 (file)
@@ -77,7 +77,7 @@ dump_raw_trace (unsigned char *data, long n_data)
        default:
          /* Consider 'memalign' to be the largest API word we want to align
             on so make the name 8 chars wide at a minimum.  */
-         printf ("%08x %8s %c%c%c%c%c%c%c%c %016llx %016llx %016llx %016llx %016llx\n",
+         printf ("%08x %8s %c%c%c%c%c%c%c%c%c%c%c%c%c%c %016llx %016llx %016llx %016llx %016llx\n",
                  t->thread,
                  t->type == __MTB_TYPE_MAGIC ? "magic" : typenames[t->type],
                  t->path_thread_cache ? 'T' : '-',
@@ -88,6 +88,12 @@ dump_raw_trace (unsigned char *data, long n_data)
                  t->path_munmap ? 'U' : '-',
                  t->path_m_f_realloc ? 'R' : '-',
                  t->path_hook ? 'H' : '-',
+                 t->path_unsorted_add ? 'U' : '-',
+                 t->path_unsorted_remove ? 'u' : '-',
+                 t->path_unsorted_empty ? 'E' : '-',
+                 t->path_fastbin_add ? 'F' : '-',
+                 t->path_fastbin_remove ? 'f' : '-',
+                 t->path_malloc_consolidate ? 'C' : '-',
                  (long long unsigned int) (size_t) t->ptr1,
                  (long long unsigned int) t->size,
                  (long long unsigned int) (size_t) t->ptr2,