ust: continue work
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Wed, 18 Feb 2009 17:30:39 +0000 (12:30 -0500)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Wed, 18 Feb 2009 17:30:39 +0000 (12:30 -0500)
- improve support for sending commands through ust
- now reserve buffers in SYSV IPC shmem segments

hello/hello.c
libtracectl/tracectl.c
libtracing/relay.c
ust/ust.c

index d271a453149b4e74b05ee7242f185b408b645d18..3c4843abfa0c3bb5955be89a0ddff6d577a5dad3 100644 (file)
@@ -204,13 +204,11 @@ int main()
 
        sleep(1);
        for(i=0; i<50; i++) {
-               trace_mark(foo, bar, "%s", "FOOBAZ");
+               trace_mark(foo, bar, "str %s", "FOOBAZ");
+               trace_mark(foo, bar2, "number1 %d number2 %d", 53, 9800);
                usleep(100000);
        }
 
-       ltt_trace_stop("auto");
-       ltt_trace_destroy("auto");
-
        scanf("%*s");
 
        return 0;
index 874f4149e4419dcbad50cf4272ab7961cabe8bd0..2c64c10e420366879d74cdf2330620cc39b1d285 100644 (file)
@@ -101,6 +101,8 @@ int listener_main(void *p)
                uint32_t size;
                struct sockaddr_un addr;
                socklen_t addrlen = sizeof(addr);
+               char trace_name[] = "auto";
+               char trace_type[] = "ustrelay";
 
                for(;;) {
                        struct trctl_msg msg;
@@ -112,8 +114,8 @@ int listener_main(void *p)
                                continue;
                        }
 
-                       if(recvbuf[len-2] == '\n')
-                               recvbuf[len-2] = '\0';
+                       if(recvbuf[len-1] == '\n')
+                               recvbuf[len-1] = '\0';
 
                        fprintf(stderr, "received a message! it's: %s\n", recvbuf);
 
@@ -123,15 +125,55 @@ int listener_main(void *p)
                        }
                        else if(!strcmp(recvbuf, "trace_setup")) {
                                DBG("trace setup");
+
+                               result = ltt_trace_setup(trace_name);
+                               if(result < 0) {
+                                       ERR("ltt_trace_setup failed");
+                                       return;
+                               }
+
+                               result = ltt_trace_set_type(trace_name, trace_type);
+                               if(result < 0) {
+                                       ERR("ltt_trace_set_type failed");
+                                       return;
+                               }
                        }
                        else if(!strcmp(recvbuf, "trace_alloc")) {
                                DBG("trace alloc");
+
+                               result = ltt_trace_alloc(trace_name);
+                               if(result < 0) {
+                                       ERR("ltt_trace_alloc failed");
+                                       return;
+                               }
                        }
                        else if(!strcmp(recvbuf, "trace_start")) {
                                DBG("trace start");
+
+                               result = ltt_trace_start(trace_name);
+                               if(result < 0) {
+                                       ERR("ltt_trace_start failed");
+                                       return;
+                               }
                        }
                        else if(!strcmp(recvbuf, "trace_stop")) {
                                DBG("trace stop");
+
+                               result = ltt_trace_stop(trace_name);
+                               if(result < 0) {
+                                       ERR("ltt_trace_stop failed");
+                                       return;
+                               }
+                       }
+                       else if(!strcmp(recvbuf, "trace_destroy")) {
+
+                               DBG("trace destroy");
+
+                               result = ltt_trace_destroy(trace_name);
+                               if(result < 0) {
+                                       ERR("ltt_trace_destroy failed");
+                                       return;
+                               }
                        }
                }
                next_conn:;
@@ -274,6 +316,10 @@ static void __attribute__((constructor)) init()
                if(result)
                        ERR("ltt_marker_connect");
 
+               result = ltt_marker_connect("foo", "bar2", "default");
+               if(result)
+                       ERR("ltt_marker_connect");
+
                result = ltt_trace_setup(trace_name);
                if(result < 0) {
                        ERR("ltt_trace_setup failed");
index c063d1faddcda841987b9c4b4950408956199438..4dc5afce23816134cf23e9186a0b7ddae70221be 100644 (file)
@@ -23,6 +23,8 @@
 //ust// #include <linux/splice.h>
 //ust// #include <linux/bitops.h>
 #include <sys/mman.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
 #include "kernelcompat.h"
 #include "list.h"
 #include "relay.h"
@@ -93,21 +95,45 @@ static int relay_alloc_buf(struct rchan_buf *buf, size_t *size)
        unsigned int n_pages;
        struct buf_page *buf_page, *n;
 
-       void *result;
+       void *ptr;
+       int result;
+       int shmid;
 
        *size = PAGE_ALIGN(*size);
 
-       /* Maybe do read-ahead */
-       result = mmap(NULL, *size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
-       if(result == MAP_FAILED) {
-               PERROR("mmap");
+       result = shmid = shmget(getpid(), *size, IPC_CREAT | IPC_EXCL | 0700);
+       if(shmid == -1) {
+               PERROR("shmget");
+               return -1;
+       }
+
+       ptr = shmat(shmid, NULL, 0);
+       if(ptr == (void *) -1) {
+               perror("shmat");
+               goto destroy_shmem;
+       }
+
+       /* Already mark the shared memory for destruction. This will occur only
+         * when all users have detached.
+        */
+       result = shmctl(shmid, IPC_RMID, NULL);
+       if(result == -1) {
+               perror("shmctl");
                return -1;
        }
 
-       buf->buf_data = result;
+       buf->buf_data = ptr;
        buf->buf_size = *size;
 
        return 0;
+
+       destroy_shmem:
+       result = shmctl(shmid, IPC_RMID, NULL);
+       if(result == -1) {
+               perror("shmctl");
+       }
+
+       return -1;
 }
 
 /**
index 1fb7d098c521da7d085d857e598deefeccacd802..015629481b8bbe5aadef0d35b02479b3cd310164 100644 (file)
--- a/ust/ust.c
+++ b/ust/ust.c
@@ -89,16 +89,20 @@ int send_message(pid_t pid, const char *msg)
                return 1;
        }
 
-       char buf[] = "print_markers\n";
+       char *buf;
+
+       asprintf(&buf, "%s\n", msg);
 
        signal_process(pid);
 
-       result = sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *)&addr, sizeof(addr));
+       result = sendto(fd, buf, strlen(buf), 0, (struct sockaddr *)&addr, sizeof(addr));
        if(result == -1) {
                perror("sendto");
                return 1;
        }
 
+       free(buf);
+
 //     result = fd = open(sockfile, O_RDWR);
 //     if(result == -1 && errno == ENXIO) {
 //             fprintf(stderr, "signalling process\n");
This page took 0.032922 seconds and 4 git commands to generate.