Add functions and command line for listing trace_events v3
[ust.git] / libust / tracectl.c
index e339218ebd216108fb1f4c7bf6b9cc2e690ec442..f1b644cc45b29aa741deae84b9307f2f4bcef705 100644 (file)
@@ -35,6 +35,7 @@
 #include <urcu/uatomic_arch.h>
 
 #include <ust/marker.h>
+#include <ust/tracepoint.h>
 #include <ust/tracectl.h>
 #include "tracer.h"
 #include "usterr.h"
@@ -127,6 +128,21 @@ static void print_markers(FILE *fp)
        unlock_markers();
 }
 
+static void print_trace_events(FILE *fp)
+{
+       struct trace_event_iter iter;
+
+       lock_trace_events();
+       trace_event_iter_reset(&iter);
+       trace_event_iter_start(&iter);
+
+       while(iter.trace_event) {
+               fprintf(fp, "trace_event: %s\n", iter.trace_event->name);
+               trace_event_iter_next(&iter);
+       }
+       unlock_trace_events();
+}
+
 static int init_socket(void);
 
 /* Ask the daemon to collect a trace called trace_name and being
@@ -282,12 +298,14 @@ static int do_cmd_get_shmid(const char *recvbuf, struct ustcomm_source *src)
        channel_and_cpu = nth_token(recvbuf, 1);
        if(channel_and_cpu == NULL) {
                ERR("cannot parse channel");
+               retval = -1;
                goto end;
        }
 
        seperate_channel_cpu(channel_and_cpu, &ch_name, &ch_cpu);
        if(ch_cpu == -1) {
                ERR("problem parsing channel name");
+               retval = -1;
                goto free_short_chan_name;
        }
 
@@ -360,12 +378,14 @@ static int do_cmd_get_n_subbufs(const char *recvbuf, struct ustcomm_source *src)
        channel_and_cpu = nth_token(recvbuf, 1);
        if(channel_and_cpu == NULL) {
                ERR("cannot parse channel");
+               retval = -1;
                goto end;
        }
 
        seperate_channel_cpu(channel_and_cpu, &ch_name, &ch_cpu);
        if(ch_cpu == -1) {
                ERR("problem parsing channel name");
+               retval = -1;
                goto free_short_chan_name;
        }
 
@@ -434,12 +454,14 @@ static int do_cmd_get_subbuf_size(const char *recvbuf, struct ustcomm_source *sr
        channel_and_cpu = nth_token(recvbuf, 1);
        if(channel_and_cpu == NULL) {
                ERR("cannot parse channel");
+               retval = -1;
                goto end;
        }
 
        seperate_channel_cpu(channel_and_cpu, &ch_name, &ch_cpu);
        if(ch_cpu == -1) {
                ERR("problem parsing channel name");
+               retval = -1;
                goto free_short_chan_name;
        }
 
@@ -522,6 +544,7 @@ static int do_cmd_set_subbuf_size(const char *recvbuf, struct ustcomm_source *sr
 
        if(ch_name == NULL) {
                ERR("cannot parse channel");
+               retval = -1;
                goto end;
        }
 
@@ -577,10 +600,12 @@ static int do_cmd_set_subbuf_num(const char *recvbuf, struct ustcomm_source *src
 
        if(ch_name == NULL) {
                ERR("cannot parse channel");
+               retval = -1;
                goto end;
        }
        if (num < 2) {
                ERR("subbuffer count should be greater than 2");
+               retval = -1;
                goto end;
        }
 
@@ -629,12 +654,14 @@ static int do_cmd_get_subbuffer(const char *recvbuf, struct ustcomm_source *src)
        channel_and_cpu = nth_token(recvbuf, 1);
        if(channel_and_cpu == NULL) {
                ERR("cannot parse channel");
+               retval = -1;
                goto end;
        }
 
        seperate_channel_cpu(channel_and_cpu, &ch_name, &ch_cpu);
        if(ch_cpu == -1) {
                ERR("problem parsing channel name");
+               retval = -1;
                goto free_short_chan_name;
        }
 
@@ -664,9 +691,9 @@ static int do_cmd_get_subbuffer(const char *recvbuf, struct ustcomm_source *src)
 
                        found = 1;
 
-                       bc = (struct blocked_consumer *) malloc(sizeof(struct blocked_consumer));
+                       bc = (struct blocked_consumer *) zmalloc(sizeof(struct blocked_consumer));
                        if(bc == NULL) {
-                               ERR("malloc returned NULL");
+                               ERR("zmalloc returned NULL");
                                goto unlock_traces;
                        }
                        bc->fd_consumer = src->fd;
@@ -856,8 +883,29 @@ int process_client_cmd(char *recvbuf, struct ustcomm_source *src)
                result = ustcomm_send_reply(&ustcomm_app.server, ptr, src);
 
                free(ptr);
-       }
-       else if(!strcmp(recvbuf, "start")) {
+       } else if (!strcmp(recvbuf, "print_trace_events")) {
+               print_trace_events(stderr);
+
+       } else if(!strcmp(recvbuf, "list_trace_events")) {
+               char *ptr;
+               size_t size;
+               FILE *fp;
+
+               fp = open_memstream(&ptr, &size);
+               if (fp == NULL) {
+                       ERR("opening memstream failed");
+                       return -1;
+               }
+               print_trace_events(fp);
+               fclose(fp);
+
+               result = ustcomm_send_reply(&ustcomm_app.server, ptr, src);
+               if (result < 0) {
+                       ERR("list_trace_events failed");
+                       return -1;
+               }
+               free(ptr);
+       } else if(!strcmp(recvbuf, "start")) {
                /* start is an operation that setups the trace, allocates it and starts it */
                result = ltt_trace_setup(trace_name);
                if(result < 0) {
This page took 0.029891 seconds and 4 git commands to generate.