aboutsummaryrefslogtreecommitdiff
path: root/malloc/malloc.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@delorie.com>2016-02-11 01:49:48 -0500
committerDJ Delorie <dj@delorie.com>2016-02-11 01:49:48 -0500
commit1322011d96a58f2d7cf9658eaa91f6645ff31b1a (patch)
treeabe8a109898a46103ecccd2b9e27d517e36de06c /malloc/malloc.c
parent649255b5d3d24089ecc0024972a875ee83a2be0a (diff)
downloadglibc-1322011d96a58f2d7cf9658eaa91f6645ff31b1a.tar.xz
glibc-1322011d96a58f2d7cf9658eaa91f6645ff31b1a.zip
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.
Diffstat (limited to 'malloc/malloc.c')
-rw-r--r--malloc/malloc.c17
1 files changed, 9 insertions, 8 deletions
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;
}