ust: be able to list markers using ust
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 17 Feb 2009 23:35:04 +0000 (18:35 -0500)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 17 Feb 2009 23:35:04 +0000 (18:35 -0500)
hello/Makefile
hello/hello.c
libmallocwrap/Makefile
libmallocwrap/mallocwrap.c
libmallocwrap/run [new file with mode: 0644]
libmarkers/marker.h
libtracectl/Makefile
libtracectl/tracectl.c
ust/ust.c [new file with mode: 0644]

index 57cc8f2be33567a34a4f3534d73da0000527a0ef..4168e6e60561dfeec8a8031ec826afe99b52d46d 100644 (file)
@@ -2,7 +2,8 @@ all: hello
 
 hello: hello.c
 #dynamic version
-       gcc -g -Wl,--print-map -I../libmarkers -I../share -I../libtracing -L../libmarkers -lmarkers -L../libtracectl -ltracectl -L../libtracing -ltracing -o hello hello.c marker-control.c serialize.c
+       gcc -g -I../libmarkers -I../share -I../libtracing -L../libmarkers -lmarkers -L../libtracectl -ltracectl -L../libtracing -ltracing -o hello hello.c marker-control.c serialize.c
+       # -Wl,--print-map
 #static version
 #      gcc -g -I../libmarkers -I../share -I../libtracing -L../libmarkers -o hello hello.c marker-control.c serialize.c ../libtracing/*.c ../libmarkers/*.c ../libtracectl/*.c ../share/*.c
 
index ee7992b00d006aa9d264a634b268b30680a55d52..b4f5216ed9bc8712ca8ff66abf774fd3063fc794 100644 (file)
@@ -58,7 +58,7 @@ int consumer(void *arg)
        }
 
        consumer_channels = (struct consumer_channel *) malloc(trace->nr_channels * sizeof(struct consumer_channel));
-       if(consumer_channels == NULL) {
+if(consumer_channels == NULL) {
                ERR("malloc returned NULL");
                return 1;
        }
@@ -148,7 +148,7 @@ void start_consumer(void)
 {
        int result;
 
-       result = clone(consumer, consumer_stack+sizeof(consumer_stack)-1, CLONE_FS | CLONE_FILES | CLONE_VM, NULL);
+       result = clone(consumer, consumer_stack+sizeof(consumer_stack)-1, CLONE_FS | CLONE_FILES | CLONE_VM | CLONE_SIGHAND | CLONE_THREAD, NULL);
        if(result == -1) {
                perror("clone");
        }
index ac7ff69726c56b50a142f4914648f478a759dabf..6f12740db6028cb3a9918a7548bcda3fbbadeeed 100644 (file)
@@ -1,4 +1,6 @@
 all: libmallocwrap.so
 
 libmallocwrap.so: mallocwrap.c
-       gcc -shared -fPIC -g -ldl -o libmallocwrap.so mallocwrap.c
+       gcc -shared -fPIC -g -I../share -I../libmarkers -I../libtracing -I../libtracectl -L../libmarkers -L../libtracing -L../libtracectl -ldl -lmarkers -o libmallocwrap.so mallocwrap.c
+
+.PHONY: libmallocwrap.so
index 48dab0aef7dc23127fc748345ab754635bf92324..de1d0f139c11601b9b3e580723440c5f55379d13 100644 (file)
@@ -3,6 +3,8 @@
 #include <sys/types.h>
 #include <stdio.h>
 
+#include "marker.h"
+
 void *(*plibc_malloc)(size_t size) = NULL;
 
 void *malloc(size_t size)
@@ -14,6 +16,11 @@ void *malloc(size_t size)
                        return NULL;
                }
        }
+
+       trace_mark(ust, malloc, "%d", (int)size);
+
        fprintf(stderr, "mallocating size %d\n", size);
        return plibc_malloc(size);
 }
+
+MARKER_LIB
diff --git a/libmallocwrap/run b/libmallocwrap/run
new file mode 100644 (file)
index 0000000..da398d3
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+LD_VERBOSE=1 LD_LIBRARY_PATH=.:../libtracing:../libmarkers:../libtracectl LD_PRELOAD=libmallocwrap.so $1
index b83ff65e654328fef1c8ca28d0eee6c01a7e055a..aebe27a975c9bfa7eb171c93c6c8d1144267c120 100644 (file)
@@ -284,12 +284,12 @@ struct lib {
 
 int marker_register_lib(struct marker *markers_start, int markers_count);
 
-#define MARKER_LIB                                             \
-extern struct marker __start___markers[] __attribute__((visibility("hidden")));                        \
-extern struct marker __stop___markers[] __attribute__((visibility("hidden")));                         \
-                                                               \
-static void __attribute__((constructor)) __markers__init(void)         \
-{                                                              \
+#define MARKER_LIB                                                                     \
+extern struct marker __start___markers[] __attribute__((visibility("hidden")));                \
+extern struct marker __stop___markers[] __attribute__((visibility("hidden")));         \
+                                                                                       \
+static void __attribute__((constructor)) __markers__init(void)                                 \
+{                                                                                      \
        marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));\
 }
 
index 754e8ffc9ab807da06bbbc50994b8262255b53c9..6aa41e46c6d9f1768ad8af039811f7fe31c67cbc 100644 (file)
@@ -1,7 +1,7 @@
 all: libtracectl.so
 
 libtracectl.so: tracectl.c
-       gcc -g -shared -fPIC -o libtracectl.so tracectl.c
+       gcc -g -shared -fPIC -I../libmarkers -I../share -o libtracectl.so tracectl.c
 
 clean:
        rm -rf *.so *.o
index 46874d4ad4d56d15c2e6217906ebac8d898f719e..04de9f39be695194187f7c7b816091990aed67c1 100644 (file)
@@ -5,6 +5,9 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sched.h>
+
+#include "marker.h"
+
 #define UNIX_PATH_MAX 108
 
 //#define SOCKETDIR "/var/run/ust/socks"
@@ -44,6 +47,20 @@ pid_t mypid;
 char mysocketfile[UNIX_PATH_MAX] = "";
 int pfd = -1;
 
+
+static void print_markers(void)
+{
+       struct marker_iter iter;
+
+       marker_iter_reset(&iter);
+       marker_iter_start(&iter);
+
+       while(iter.marker) {
+               fprintf(stderr, "marker: %s_%s \"%s\"\n", iter.marker->channel, iter.marker->name, iter.marker->format);
+               marker_iter_next(&iter);
+       }
+}
+
 void do_command(struct tracecmd *cmd)
 {
 }
@@ -74,56 +91,48 @@ void notif_cb(void)
        }
 }
 
+char recvbuf[10000];
+
 int listener_main(void *p)
 {
        int result;
 
-       /* Allowing only 1 connection for now. */
-       result = listen(pfd, 1);
-       if(result == -1) {
-               PERROR("listen");
-               return 1;
-       }
-
        for(;;) {
-
                uint32_t size;
-               int fd;
                struct sockaddr_un addr;
                socklen_t addrlen = sizeof(addr);
 
-               result = fd = accept(pfd, (struct sockaddr *)&addr, &addrlen);
-               if(result == -1) {
-                       PERROR("accept");
-                       continue;
-               }
-
                for(;;) {
                        struct trctl_msg msg;
-                       unsigned char dontclose=0;
+                       int len;
 
-                       result = read(fd, &msg.size, sizeof(msg.size));
+                       result = len = recvfrom(pfd, recvbuf, sizeof(recvbuf), 0, &addr, &addrlen);
                        if(result == -1) {
-                               PERROR("read");
+                               PERROR("recvfrom");
                                continue;
                        }
 
-                       if(size > MAX_MSG_SIZE) {
-                               ERR("trctl message too big");
-                               break;
-                       }
+                       if(recvbuf[len-2] == '\n')
+                               recvbuf[len-2] = '\0';
 
-                       result = read(fd, &msg.type, sizeof(msg.type));
-                       if(result == -1) {
-                               PERROR("read");
-                               continue;
-                       }
+                       fprintf(stderr, "received a message! it's: %s\n", recvbuf);
 
-                       switch(msg.type) {
-                               case MSG_REGISTER_NOTIF:
-                                       /* TODO: put it in notif mode */
-                                       goto next_conn;
-                       };
+
+                       if(!strcmp(recvbuf, "print_markers")) {
+                               print_markers();
+                       }
+                       else if(!strcmp(recvbuf, "trace_setup")) {
+                               DBG("trace setup");
+                       }
+                       else if(!strcmp(recvbuf, "trace_alloc")) {
+                               DBG("trace alloc");
+                       }
+                       else if(!strcmp(recvbuf, "trace_start")) {
+                               DBG("trace start");
+                       }
+                       else if(!strcmp(recvbuf, "trace_stop")) {
+                               DBG("trace stop");
+                       }
                }
                next_conn:;
        }
@@ -134,7 +143,7 @@ void create_listener(void)
        int result;
        static char listener_stack[16384];
 
-       result = clone(listener_main, listener_stack+sizeof(listener_stack)-1, CLONE_FS | CLONE_FILES | CLONE_VM, NULL);
+       result = clone(listener_main, listener_stack+sizeof(listener_stack)-1, CLONE_FS | CLONE_FILES | CLONE_VM | CLONE_SIGHAND | CLONE_THREAD, NULL);
        if(result == -1) {
                perror("clone");
        }
@@ -145,7 +154,7 @@ void create_listener(void)
 void sighandler(int sig)
 {
        DBG("sighandler");
-       receive_commands();
+       create_listener();
 }
 
 /* Called by the app signal handler to chain it to us. */
@@ -164,7 +173,7 @@ static int init_socket(void)
 
        struct sockaddr_un addr;
        
-       result = fd = socket(PF_UNIX, SOCK_SEQPACKET, 0);
+       result = fd = socket(PF_UNIX, SOCK_DGRAM, 0);
        if(result == -1) {
                PERROR("socket");
                return -1;
diff --git a/ust/ust.c b/ust/ust.c
new file mode 100644 (file)
index 0000000..1fb7d09
--- /dev/null
+++ b/ust/ust.c
@@ -0,0 +1,128 @@
+#include <unistd.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#define UNIX_PATH_MAX 108
+#define SOCK_DIR "/tmp/socks"
+#define UST_SIGNAL SIGIO
+
+struct ust_msg {
+       char *raw;
+};
+
+void parse_opts(int argc, char **argv)
+{
+       int flags, opt;
+       int nsecs, tfnd;
+
+       nsecs = 0;
+       tfnd = 0;
+       flags = 0;
+       while ((opt = getopt(argc, argv, "nt:")) != -1) {
+               switch (opt) {
+               case 'n':
+                       flags = 1;
+                       break;
+               case 't':
+                       nsecs = atoi(optarg);
+                       tfnd = 1;
+                       break;
+               default:        /* '?' */
+                       fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\n",
+                               argv[0]);
+                       exit(EXIT_FAILURE);
+               }
+       }
+
+       printf("flags=%d; tfnd=%d; optind=%d\n", flags, tfnd, optind);
+
+       if (optind >= argc) {
+               fprintf(stderr, "Expected argument after options\n");
+               exit(EXIT_FAILURE);
+       }
+
+       printf("name argument = %s\n", argv[optind]);
+
+       /* Other code omitted */
+
+       exit(EXIT_SUCCESS);
+
+}
+
+void signal_process(pid_t pid)
+{
+       int result;
+
+       result = kill(pid, UST_SIGNAL);
+       if(result == -1) {
+               perror("kill");
+               return;
+       }
+
+       sleep(1);
+}
+
+int send_message(pid_t pid, const char *msg)
+{
+       int fd;
+       int result;
+       struct sockaddr_un addr;
+
+       result = fd = socket(PF_UNIX, SOCK_DGRAM, 0);
+       if(result == -1) {
+               perror("socket");
+               return 1;
+       }
+
+       addr.sun_family = AF_UNIX;
+
+       result = snprintf(addr.sun_path, UNIX_PATH_MAX, "%s/%d", SOCK_DIR, pid);
+       if(result >= UNIX_PATH_MAX) {
+               fprintf(stderr, "string overflow allocating socket name");
+               return 1;
+       }
+
+       char buf[] = "print_markers\n";
+
+       signal_process(pid);
+
+       result = sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *)&addr, sizeof(addr));
+       if(result == -1) {
+               perror("sendto");
+               return 1;
+       }
+
+//     result = fd = open(sockfile, O_RDWR);
+//     if(result == -1 && errno == ENXIO) {
+//             fprintf(stderr, "signalling process\n");
+//
+//             result = fd = open(sockfile, O_RDWR);
+//             if(result == -1) {
+//                     perror("open");
+//                     return 1;
+//             }
+//     }
+//     else if(result == -1) {
+//             perror("open");
+//             return 1;
+//     }
+
+}
+
+int main(int argc, char *argv[])
+{
+       pid_t pid = atoi(argv[1]);
+
+       char *msg = argv[2];
+
+       send_message(pid, msg);
+
+       return 0;
+}
This page took 0.030008 seconds and 4 git commands to generate.