ust: additional work on libmallocwrap and cleanups
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Mon, 23 Feb 2009 19:03:08 +0000 (14:03 -0500)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Mon, 23 Feb 2009 19:03:08 +0000 (14:03 -0500)
libmallocwrap/Makefile
libmallocwrap/mallocwrap.c
libmarkers/marker.c
libtracectl/tracectl.c
share/usterr.h

index d5890a71b022bb207d82e81e6d646b1630a5c8ec..834d324122655bfad6cd43bfaa137cc9845388a9 100644 (file)
@@ -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
index de1d0f139c11601b9b3e580723440c5f55379d13..7794527652dd9f4fb20c5449ba842b90126e3ba0 100644 (file)
@@ -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
index 43dfff7f58d38a5e06506d5a9c73d6b130e6229f..33d63c0b0028fc599f8eee244f39e9d7e0b40348 100644 (file)
@@ -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;
 }
index 1725bcab727361f330d0e6127fa260d1f37b9037..a2521585b336f204d56cf1ef7b8489d18d242578 100644 (file)
 #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();
 }
index 83b3222c72ce4a9031d525389f94670c5375f697..f1eef743ebd7de5381a4ecbf77ff231c0011ccb0 100644 (file)
@@ -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)
This page took 0.030176 seconds and 4 git commands to generate.