Add functions and command line for listing trace_events v3
authorNils Carlson <nils.carlson@ericsson.com>
Fri, 10 Sep 2010 08:49:49 +0000 (10:49 +0200)
committerNils Carlson <nils.carlson@ericsson.com>
Fri, 10 Sep 2010 08:49:49 +0000 (10:49 +0200)
Changes from version 2: Fix a comment.

Changes from version 1: Fix silly things per Davids comments,
realise that we are looping over pids and therefore need to set
all pointers to NULL and all counters to zero each time.

include/ust/ustcmd.h
libust/tracectl.c
libustcmd/ustcmd.c
ustctl/ustctl.c

index 60f5018b1076346856b1d6d2aa8dd2163f34ded4..986ae6182b1951eb882e7241ba8be6778f5150c1 100644 (file)
@@ -43,6 +43,10 @@ struct marker_status {
        char *fs; /* Format string (end of marker_status array if NULL) */
 };
 
+struct trace_event_status {
+       char *name;
+};
+
 extern pid_t *ustcmd_get_online_pids(void);
 extern int ustcmd_set_marker_state(const char *, int, pid_t);
 extern int ustcmd_set_subbuf_size(const char *, pid_t);
@@ -59,6 +63,8 @@ extern int ustcmd_free_cmsf(struct marker_status *);
 extern unsigned int ustcmd_count_nl(const char *);
 extern int ustcmd_send_cmd(const char *, pid_t, char **);
 extern int ustcmd_get_cmsf(struct marker_status **, pid_t);
+extern int ustcmd_free_tes(struct trace_event_status *);
+extern int ustcmd_get_tes(struct trace_event_status **, pid_t);
 extern int ustcmd_set_sock_path(const char *, pid_t);
 extern int ustcmd_get_sock_path(char **, pid_t);
 extern int ustcmd_force_switch(pid_t);
index e64b26f7cf85dc6ad2718d508f0e95d2cd226c8d..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
@@ -867,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) {
index f0a6ae0a25059cfcaead24f313c0b926e5ccb02a..4248072b4705d0ca384982dcbd1acb2a68f4b01e 100644 (file)
@@ -438,6 +438,83 @@ int ustcmd_get_cmsf(struct marker_status **cmsf, const pid_t pid)
        return 0;
 }
 
+
+/**
+ * Frees a TES array.
+ *
+ * @param tes  TES array to free
+ * @return     0 if successful, or error USTCMD_ERR_ARG
+ */
+int ustcmd_free_tes(struct trace_event_status *tes)
+{
+       if (tes == NULL) {
+               return USTCMD_ERR_ARG;
+       }
+
+       unsigned int i = 0;
+       while (tes[i].name != NULL) {
+               free(tes[i].name);
+               ++i;
+       }
+       free(tes);
+
+       return 0;
+}
+
+/**
+ * Gets trace_events string for a given PID.
+ *
+ * @param tes  Pointer to TES array to be filled (callee allocates, caller
+ *             frees with `ustcmd_free_tes')
+ * @param pid  Targeted PID
+ * @return     0 if successful, or -1 on error
+ */
+int ustcmd_get_tes(struct trace_event_status **tes,
+                           const pid_t pid)
+{
+       char *big_str = NULL;
+       int result;
+       struct trace_event_status *tmp_tes = NULL;
+       unsigned int i = 0, tes_ind = 0;
+
+       if (tes == NULL) {
+               return -1;
+       }
+
+       result = ustcmd_send_cmd("list_trace_events", pid, &big_str);
+       if (result != 1) {
+               ERR("error while getting trace_event list");
+               return -1;
+       }
+
+       tmp_tes = (struct trace_event_status *)
+               zmalloc(sizeof(struct trace_event_status) *
+                       (ustcmd_count_nl(big_str) + 1));
+       if (tmp_tes == NULL) {
+               ERR("Failed to allocate TES array");
+               return -1;
+       }
+
+       /* Parse received reply string (format: "[name]"): */
+       while (big_str[i] != '\0') {
+               char state;
+
+               sscanf(big_str + i, "trace_event: %a[^\n]",
+                       &tmp_tes[tes_ind].name);
+               while (big_str[i] != '\n') {
+                       ++i; /* Go to next '\n' */
+               }
+               ++i; /* Skip current pointed '\n' */
+               ++tes_ind;
+       }
+       tmp_tes[tes_ind].name = NULL;
+
+       *tes = tmp_tes;
+
+       free(big_str);
+       return 0;
+}
+
 /**
  * Set socket path
  *
index 35bea7ae6b3d84f17c1493e378593149f4b6e90c..bf149d11f8b6b4c666467f91505d5686783d3076 100644 (file)
@@ -32,6 +32,7 @@ enum command {
        STOP_TRACE,
        DESTROY_TRACE,
        LIST_MARKERS,
+       LIST_TRACE_EVENTS,
        ENABLE_MARKER,
        DISABLE_MARKER,
        GET_ONLINE_PIDS,
@@ -73,6 +74,7 @@ Commands:\n\
     --enable-marker \"CHANNEL/MARKER\"\tEnable a marker\n\
     --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\
     --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t  state and format string\n\
+    --list-trace-events\t\t\tList the trace-events of the process\n\
     --force-switch\t\t\tForce a subbuffer switch\n\
 \
 ");
@@ -94,6 +96,7 @@ int parse_opts_long(int argc, char **argv, struct ust_opts *opts)
                        { "stop-trace", 0, 0, STOP_TRACE },
                        { "destroy-trace", 0, 0, DESTROY_TRACE },
                        { "list-markers", 0, 0, LIST_MARKERS },
+                       { "list-trace-events", 0, 0, LIST_TRACE_EVENTS},
                        { "enable-marker", 1, 0, ENABLE_MARKER },
                        { "disable-marker", 1, 0, DISABLE_MARKER },
                        { "help", 0, 0, 'h' },
@@ -216,6 +219,8 @@ int main(int argc, char *argv[])
 
        pidit = opts.pids;
        struct marker_status *cmsf = NULL;
+       struct trace_event_status *tes = NULL;
+       unsigned int i = 0;
 
        while(*pidit != -1) {
                switch (opts.cmd) {
@@ -262,7 +267,7 @@ int main(int argc, char *argv[])
                                        retval = EXIT_FAILURE;
                                        break;
                                }
-                               unsigned int i = 0;
+                               i = 0;
                                while (cmsf[i].channel != NULL) {
                                        printf("{PID: %u, channel/marker: %s/%s, "
                                                "state: %u, fmt: %s}\n",
@@ -276,6 +281,24 @@ int main(int argc, char *argv[])
                                ustcmd_free_cmsf(cmsf);
                                break;
 
+                       case LIST_TRACE_EVENTS:
+                               tes = NULL;
+                               if (ustcmd_get_tes(&tes, *pidit)) {
+                                       ERR("error while trying to list "
+                                           "trace_events for PID %u\n",
+                                           (unsigned int) *pidit);
+                                       break;
+                               }
+                               i = 0;
+                               while (tes[i].name != NULL) {
+                                       printf("{PID: %u, trace_event: %s}\n",
+                                              (unsigned int) *pidit,
+                                              tes[i].name);
+                                       ++i;
+                               }
+                               ustcmd_free_tes(tes);
+
+                               break;
                        case ENABLE_MARKER:
                                if (opts.regex) {
                                        if (ustcmd_set_marker_state(opts.regex, 1, *pidit)) {
This page took 0.029082 seconds and 4 git commands to generate.