From 1322011d96a58f2d7cf9658eaa91f6645ff31b1a Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Thu, 11 Feb 2016 01:49:48 -0500 Subject: Update malloc tracing utility. Change head pointer to be total calls; adjust users to modulo after incrementing. Use mmap() instead of sbrk(). Split environment variables so count and file can be specified. Export trace hooks so mtrace-ctl can be built against libc.so. Allow NULL to be passed to __mtrace_get_trace_buffer. Add some error handling to mtrace-ctl. --- malloc/malloc.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'malloc/malloc.c') diff --git a/malloc/malloc.c b/malloc/malloc.c index 6765aba6eb..2fe4adaaf0 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -1093,12 +1093,11 @@ static __thread __malloc_trace_buffer_ptr trace_ptr; static inline void __attribute__((always_inline)) __mtb_trace_entry (uint32_t type, int64_t size, void *ptr1) { - int head1, head2; - do { - head1 = head2 = __malloc_trace_buffer_head; - head2 = (head2 + 1) % __malloc_trace_buffer_size; - } while (catomic_compare_and_exchange_bool_acq (&__malloc_trace_buffer_head, head2, head1)); - trace_ptr = __malloc_trace_buffer + head1; + int head1; + + head1 = catomic_exchange_and_add (&__malloc_trace_buffer_head, 1); + + trace_ptr = __malloc_trace_buffer + (head1 % __malloc_trace_buffer_size); trace_ptr->thread = syscall(__NR_gettid); trace_ptr->type = type; @@ -1128,8 +1127,10 @@ __malloc_set_trace_buffer (void *bufptr, int bufsize) void * __malloc_get_trace_buffer (int *bufcount, int *bufhead) { - *bufcount = __malloc_trace_buffer_size; - *bufhead = __malloc_trace_buffer_head; + if (bufcount) + *bufcount = __malloc_trace_buffer_size; + if (bufhead) + *bufhead = __malloc_trace_buffer_head; return __malloc_trace_buffer; } -- cgit v1.2.3