From: Pierre-Marc Fournier Date: Mon, 23 Feb 2009 19:03:08 +0000 (-0500) Subject: ust: additional work on libmallocwrap and cleanups X-Git-Tag: v1.9.1~1053 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=1c184644865c13e167b174cd593e80a2c62b2482;p=lttng-ust.git ust: additional work on libmallocwrap and cleanups --- diff --git a/libmallocwrap/Makefile b/libmallocwrap/Makefile index d5890a71..834d3241 100644 --- a/libmallocwrap/Makefile +++ b/libmallocwrap/Makefile @@ -1,6 +1,6 @@ all: libmallocwrap.so libmallocwrap.so: mallocwrap.c - gcc -shared -fPIC -g -I../share -I../libmarkers -I../libtracing -I../libtracectl -L../libmarkers -L../libtracing -L../libtracectl $(CFLAGS) -ldl -lmarkers -o libmallocwrap.so mallocwrap.c + gcc -shared -fPIC -g -I../share -I../libmarkers -I../libtracing -I../libtracectl -L../libmarkers -L../libtracing -L../libtracectl $(CFLAGS) -ldl -lmarkers -ltracectl -ltracing -o libmallocwrap.so mallocwrap.c .PHONY: libmallocwrap.so diff --git a/libmallocwrap/mallocwrap.c b/libmallocwrap/mallocwrap.c index de1d0f13..77945276 100644 --- a/libmallocwrap/mallocwrap.c +++ b/libmallocwrap/mallocwrap.c @@ -5,10 +5,47 @@ #include "marker.h" -void *(*plibc_malloc)(size_t size) = NULL; +//INTERCEPT_PROTOTYPE(void, malloc, size_t size) +//INTERCEPT_TRACE("size %d", size) +//INTERCEPT_CALL_ARGS(size) +//INTERCEPT() +// +//#define INTERCEPT_FUNC(type, name, args...) \ +//__I_FUNC_TYPE(type) \ +//__I_FUNC_NAME(name) \ +//__I_FUNC_ARGS(args) +// +//#define INTERCEPT_TRACE(fmt, args...) \ +//#define __I_TRACE_FMT fmt \ +//#define __I_TRACE_ARGS args +// +//#define INTERCEPT_CALL_ARGS(args...) \ +//#define __I_CALL_ARGS args +// +//#define INTERCEPT() \ +//__I_FUNC_TYPE __I_FUNC_NAME(__I_FUNC_ARGS) \ +//{ \ +// static __I_FUNC_TYPE (*plibc_ ## __I_FUNC_NAME)(args) = NULL; \ +// \ +// if(plibc_ ## __I_FUNC_NAME == NULL) { \ +// plibc_ ## __I_FUNC_NAME = dlsym(RTLD_NEXT, "malloc"); \ +// if(plibc_ ## __I_FUNC_NAME == NULL) { \ +// fprintf(stderr, "mallocwrap: unable to find malloc\n"); \ +// return NULL; \ +// } \ +// } \ +// \ +// trace_mark(ust, __I_FUNC_NAME, __I_TRACE_FMT, __I_TRACE_ARGS); \ +// \ +// return plibc_ ## __I_FUNC_NAME (__I_CALL_ARGS); \ +//} void *malloc(size_t size) { + static void *(*plibc_malloc)(size_t size) = NULL; + + void *retval; + if(plibc_malloc == NULL) { plibc_malloc = dlsym(RTLD_NEXT, "malloc"); if(plibc_malloc == NULL) { @@ -17,10 +54,28 @@ void *malloc(size_t size) } } - trace_mark(ust, malloc, "%d", (int)size); + retval = plibc_malloc(size); + + trace_mark(ust, malloc, "size %d ptr %p", (int)size, retval); + + return retval; +} + +void free(void *ptr) +{ + static void *(*plibc_free)(void *ptr) = NULL; + + if(plibc_free == NULL) { + plibc_free = dlsym(RTLD_NEXT, "free"); + if(plibc_free == NULL) { + fprintf(stderr, "mallocwrap: unable to find free\n"); + return NULL; + } + } + + trace_mark(ust, free, "%p", ptr); - fprintf(stderr, "mallocating size %d\n", size); - return plibc_malloc(size); + return plibc_free(ptr); } MARKER_LIB diff --git a/libmarkers/marker.c b/libmarkers/marker.c index 43dfff7f..33d63c0b 100644 --- a/libmarkers/marker.c +++ b/libmarkers/marker.c @@ -1504,7 +1504,7 @@ int marker_register_lib(struct marker *markers_start, int markers_count) /* FIXME: update just the loaded lib */ lib_update_markers(); - printf("just registered a markers section from %p and having %d markers\n", markers_start, markers_count); + DBG("just registered a markers section from %p and having %d markers", markers_start, markers_count); return 0; } diff --git a/libtracectl/tracectl.c b/libtracectl/tracectl.c index 1725bcab..a2521585 100644 --- a/libtracectl/tracectl.c +++ b/libtracectl/tracectl.c @@ -18,11 +18,6 @@ #define SOCKETDIRLEN sizeof(SOCKETDIR) #define USTSIGNAL SIGIO -#define DBG(fmt, args...) fprintf(stderr, fmt "\n", ## args) -#define WARN(fmt, args...) fprintf(stderr, "usertrace: WARNING: " fmt "\n", ## args) -#define ERR(fmt, args...) fprintf(stderr, "usertrace: ERROR: " fmt "\n", ## args); fflush(stderr) -#define PERROR(call) perror("usertrace: ERROR: " call) - #define MAX_MSG_SIZE (100) #define MSG_NOTIF 1 #define MSG_REGISTER_NOTIF 2 @@ -89,7 +84,7 @@ int consumer(void *arg) consumer_channels[i].chan = chan; - snprintf(tmp, sizeof(tmp), "trace/%s", chan->channel_name); + snprintf(tmp, sizeof(tmp), "trace/%s_0", chan->channel_name); result = consumer_channels[i].fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 00644); if(result == -1) { perror("open"); @@ -111,10 +106,10 @@ int consumer(void *arg) result = ltt_do_get_subbuf(rbuf, lttbuf, &consumed_old); if(result < 0) { - CPRINTF("ltt_do_get_subbuf: error: %s", strerror(-result)); + DBG("ltt_do_get_subbuf: error: %s", strerror(-result)); } else { - CPRINTF("success!"); + DBG("success!"); result = write(consumer_channels[i].fd, rbuf->buf_data + (consumed_old & (2 * 4096-1)), 4096); ltt_do_put_subbuf(rbuf, lttbuf, consumed_old); @@ -531,7 +526,7 @@ static void __attribute__((destructor)) fini() } /* FIXME: wait for the consumer to be done */ - sleep(10); + sleep(3); destroy_socket(); } diff --git a/share/usterr.h b/share/usterr.h index 83b3222c..f1eef743 100644 --- a/share/usterr.h +++ b/share/usterr.h @@ -1,10 +1,10 @@ #ifndef USTERR_H #define USTERR_H -#define DBG(fmt, args...) fprintf(stderr, fmt "\n", ## args) -#define WARN(fmt, args...) fprintf(stderr, "usertrace: WARNING: " fmt "\n", ## args) -#define ERR(fmt, args...) fprintf(stderr, "usertrace: ERROR: " fmt "\n", ## args) -#define BUG(fmt, args...) fprintf(stderr, "usertrace: BUG: " fmt "\n", ## args) +#define DBG(fmt, args...) fprintf(stderr, fmt "\n", ## args); fflush(stderr) +#define WARN(fmt, args...) fprintf(stderr, "usertrace: WARNING: " fmt "\n", ## args); fflush(stderr) +#define ERR(fmt, args...) fprintf(stderr, "usertrace: ERROR: " fmt "\n", ## args); fflush(stderr) +#define BUG(fmt, args...) fprintf(stderr, "usertrace: BUG: " fmt "\n", ## args); fflush(stderr) #define PERROR(call) perror("usertrace: ERROR: " call) #define BUG_ON(condition) do { if (unlikely(condition)) ERR("condition not respected (BUG)"); } while(0)