From: Pierre-Marc Fournier Date: Wed, 18 Feb 2009 17:30:39 +0000 (-0500) Subject: ust: continue work X-Git-Tag: v1.9.1~1060 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=aafb1650caa90246ada3cc2c4ca7fc9493673617;p=lttng-ust.git ust: continue work - improve support for sending commands through ust - now reserve buffers in SYSV IPC shmem segments --- diff --git a/hello/hello.c b/hello/hello.c index d271a453..3c4843ab 100644 --- a/hello/hello.c +++ b/hello/hello.c @@ -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; diff --git a/libtracectl/tracectl.c b/libtracectl/tracectl.c index 874f4149..2c64c10e 100644 --- a/libtracectl/tracectl.c +++ b/libtracectl/tracectl.c @@ -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"); diff --git a/libtracing/relay.c b/libtracing/relay.c index c063d1fa..4dc5afce 100644 --- a/libtracing/relay.c +++ b/libtracing/relay.c @@ -23,6 +23,8 @@ //ust// #include //ust// #include #include +#include +#include #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; } /** diff --git a/ust/ust.c b/ust/ust.c index 1fb7d098..01562948 100644 --- 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");