Add trace name handling throughout tracectl, ustcomm and ustcmd
authorNils Carlson <nils.carlson@ericsson.com>
Thu, 4 Nov 2010 16:45:06 +0000 (17:45 +0100)
committerNils Carlson <nils.carlson@ericsson.com>
Wed, 10 Nov 2010 08:05:12 +0000 (09:05 +0100)
This patch is the first real step in allowing multi-session
tracing. It pushes trace name all the way out to libustcmd
(though not yet to ustctl) and trace session support all
the way into tracectl in libust (though not yet down to markers).

Signed-off-by: Nils Carlson <nils.carlson@ericsson.com>
Acked-by: David Goulet <david.goulet@polymtl.ca>
include/ust/ustcmd.h
include/ust/ustd.h
libust/tracectl.c
libustcmd/ustcmd.c
libustcomm/ustcomm.c
libustcomm/ustcomm.h
libustd/libustd.c
tests/ustcmd_function_tests/ustcmd_function_tests.c
ustctl/ustctl.c

index b32fe36bcf96fd674a45301e1de22549c6db8a5b..6273575b1d26dc92e7590ae182e5e991ad6f0e6b 100644 (file)
@@ -48,20 +48,22 @@ struct trace_event_status {
 };
 
 extern pid_t *ustcmd_get_online_pids(void);
-extern int ustcmd_set_marker_state(const char *channel, const char *marker,
-int state, pid_t pid);
-extern int ustcmd_set_subbuf_size(const char *channel, unsigned int subbuf_size,
+extern int ustcmd_set_marker_state(const char *trace, const char *channel,
+                                  const char *marker, int state, pid_t pid);
+extern int ustcmd_set_subbuf_size(const char *trace, const char *channel,
+                                 unsigned int subbuf_size, pid_t pid);
+extern int ustcmd_set_subbuf_num(const char *trace, const char *channel,
+                                unsigned int num, pid_t pid);
+extern int ustcmd_get_subbuf_size(const char *trace, const char *channel,
                                  pid_t pid);
-extern int ustcmd_set_subbuf_num(const char *channel, unsigned int num,
+extern int ustcmd_get_subbuf_num(const char *trace, const char *channel,
                                 pid_t pid);
-extern int ustcmd_get_subbuf_size(const char *channel, pid_t pid);
-extern int ustcmd_get_subbuf_num(const char *channel, pid_t pid);
-extern int ustcmd_destroy_trace(pid_t pid);
-extern int ustcmd_setup_and_start(pid_t pid);
-extern int ustcmd_stop_trace(pid_t pid);
-extern int ustcmd_create_trace(pid_t pid);
-extern int ustcmd_start_trace(pid_t pid);
-extern int ustcmd_alloc_trace(pid_t pid);
+extern int ustcmd_destroy_trace(const char *trace, pid_t pid);
+extern int ustcmd_setup_and_start(const char *trace, pid_t pid);
+extern int ustcmd_stop_trace(const char *trace, pid_t pid);
+extern int ustcmd_create_trace(const char *trace, pid_t pid);
+extern int ustcmd_start_trace(const char *trace, pid_t pid);
+extern int ustcmd_alloc_trace(const char *trace, pid_t pid);
 extern int ustcmd_free_cmsf(struct marker_status *);
 extern unsigned int ustcmd_count_nl(const char *);
 extern int ustcmd_get_cmsf(struct marker_status **, pid_t);
index 01b88d755f2f7d20fa1860b54913e715d8407dc7..0757acb9b035f77472c797dd25dc35d88914d190 100644 (file)
@@ -37,6 +37,7 @@ struct ustcomm_sock;
 
 struct buffer_info {
        char *name;
+       char *trace;
        char *channel;
        int channel_cpu;
 
index 5f942cd8306a3cdb661c73bb45484782bb6a245d..d5ca7d2b9655aa230b4b7d1fd029e2a4a7f05a1b 100644 (file)
@@ -149,8 +149,9 @@ static int connect_ustd(void)
 
 
 static void request_buffer_consumer(int sock,
-                                  const char *channel,
-                                  int cpu)
+                                   const char *trace,
+                                   const char *channel,
+                                   int cpu)
 {
        struct ustcomm_header send_header, recv_header;
        struct ustcomm_buffer_info buf_inf;
@@ -158,6 +159,7 @@ static void request_buffer_consumer(int sock,
 
        result = ustcomm_pack_buffer_info(&send_header,
                                          &buf_inf,
+                                         trace,
                                          channel,
                                          cpu);
 
@@ -212,7 +214,8 @@ static void inform_consumer_daemon(const char *trace_name)
                        /* iterate on all cpus */
                        for (j=0; j<trace->channels[i].n_cpus; j++) {
                                ch_name = trace->channels[i].channel_name;
-                               request_buffer_consumer(sock, ch_name, j);
+                               request_buffer_consumer(sock, trace_name,
+                                                       ch_name, j);
                                STORE_SHARED(buffers_to_export,
                                             LOAD_SHARED(buffers_to_export)+1);
                        }
@@ -545,10 +548,6 @@ static void force_subbuf_switch()
 /* Simple commands are those which need only respond with a return value. */
 static int process_simple_client_cmd(int command, char *recv_buf)
 {
-       int result;
-       char trace_type[] = "ustrelay";
-       char trace_name[] = "auto";
-
        switch(command) {
        case SET_SOCK_PATH:
        {
@@ -564,6 +563,27 @@ static int process_simple_client_cmd(int command, char *recv_buf)
                }
                return setenv("UST_DAEMON_SOCKET", sock_msg->sock_path, 1);
        }
+
+       case FORCE_SUBBUF_SWITCH:
+               /* FIXME: return codes? */
+               force_subbuf_switch();
+
+               break;
+
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+
+static int process_trace_cmd(int command, char *trace_name)
+{
+       int result;
+       char trace_type[] = "ustrelay";
+
+       switch(command) {
        case START:
                /* start is an operation that setups the trace, allocates it and starts it */
                result = ltt_trace_setup(trace_name);
@@ -675,19 +695,12 @@ static int process_simple_client_cmd(int command, char *recv_buf)
                        return result;
                }
                return 0;
-       case FORCE_SUBBUF_SWITCH:
-               /* FIXME: return codes? */
-               force_subbuf_switch();
-
-               break;
-
-       default:
-               return -EINVAL;
        }
 
        return 0;
 }
 
+
 static void process_channel_cmd(int sock, int command,
                                struct ustcomm_channel_info *ch_inf)
 {
@@ -695,14 +708,13 @@ static void process_channel_cmd(int sock, int command,
        struct ustcomm_header *reply_header = &_reply_header;
        struct ustcomm_channel_info *reply_msg =
                (struct ustcomm_channel_info *)send_buffer;
-       char trace_name[] = "auto";
        int result, offset = 0, num, size;
 
        memset(reply_header, 0, sizeof(*reply_header));
 
        switch (command) {
        case GET_SUBBUF_NUM_SIZE:
-               result = get_subbuf_num_size(trace_name,
+               result = get_subbuf_num_size(ch_inf->trace,
                                             ch_inf->channel,
                                             &num, &size);
                if (result < 0) {
@@ -719,13 +731,13 @@ static void process_channel_cmd(int sock, int command,
 
                break;
        case SET_SUBBUF_NUM:
-               reply_header->result = set_subbuf_num(trace_name,
+               reply_header->result = set_subbuf_num(ch_inf->trace,
                                                      ch_inf->channel,
                                                      ch_inf->subbuf_num);
 
                break;
        case SET_SUBBUF_SIZE:
-               reply_header->result = set_subbuf_size(trace_name,
+               reply_header->result = set_subbuf_size(ch_inf->trace,
                                                       ch_inf->channel,
                                                       ch_inf->subbuf_size);
 
@@ -744,7 +756,6 @@ static void process_buffer_cmd(int sock, int command,
        struct ustcomm_header *reply_header = &_reply_header;
        struct ustcomm_buffer_info *reply_msg =
                (struct ustcomm_buffer_info *)send_buffer;
-       char trace_name[] = "auto";
        int result, offset = 0, buf_shmid, buf_struct_shmid, buf_pipe_fd;
        long consumed_old;
 
@@ -752,7 +763,8 @@ static void process_buffer_cmd(int sock, int command,
 
        switch (command) {
        case GET_BUF_SHMID_PIPE_FD:
-               result = get_buffer_shmid_pipe_fd(trace_name, buf_inf->channel,
+               result = get_buffer_shmid_pipe_fd(buf_inf->trace,
+                                                 buf_inf->channel,
                                                  buf_inf->ch_cpu,
                                                  &buf_shmid,
                                                  &buf_struct_shmid,
@@ -777,12 +789,12 @@ static void process_buffer_cmd(int sock, int command,
 
        case NOTIFY_BUF_MAPPED:
                reply_header->result =
-                       notify_buffer_mapped(trace_name,
+                       notify_buffer_mapped(buf_inf->trace,
                                             buf_inf->channel,
                                             buf_inf->ch_cpu);
                break;
        case GET_SUBBUFFER:
-               result = get_subbuffer(trace_name, buf_inf->channel,
+               result = get_subbuffer(buf_inf->trace, buf_inf->channel,
                                       buf_inf->ch_cpu, &consumed_old);
                if (result < 0) {
                        reply_header->result = result;
@@ -796,7 +808,7 @@ static void process_buffer_cmd(int sock, int command,
 
                break;
        case PUT_SUBBUFFER:
-               result = put_subbuffer(trace_name, buf_inf->channel,
+               result = put_subbuffer(buf_inf->trace, buf_inf->channel,
                                       buf_inf->ch_cpu,
                                       buf_inf->consumed_old);
                reply_header->result = result;
@@ -1008,6 +1020,30 @@ static void process_client_cmd(struct ustcomm_header *recv_header,
 
                goto send_response;
        }
+       case START:
+       case SETUP_TRACE:
+       case ALLOC_TRACE:
+       case CREATE_TRACE:
+       case START_TRACE:
+       case STOP_TRACE:
+       case DESTROY_TRACE:
+       {
+               struct ustcomm_trace_info *trace_inf =
+                       (struct ustcomm_trace_info *)recv_buf;
+
+               result = ustcomm_unpack_trace_info(trace_inf);
+               if (result < 0) {
+                       ERR("couldn't unpack trace info");
+                       reply_header->result = -EINVAL;
+                       goto send_response;
+               }
+
+               reply_header->result =
+                       process_trace_cmd(recv_header->command,
+                                         trace_inf->trace);
+               goto send_response;
+
+       }
        default:
                reply_header->result =
                        process_simple_client_cmd(recv_header->command,
index a53455aae6d1f07f3184e796dd8cfbf86ac0aaba..bffd3c237235144c12211e26b93246d15337811b 100644 (file)
@@ -140,8 +140,8 @@ pid_t *ustcmd_get_online_pids(void)
  * @param pid  Traced process ID
  * @return     0 if successful, or errors {USTCMD_ERR_GEN, USTCMD_ERR_ARG}
  */
-int ustcmd_set_marker_state(const char *channel, const char *marker,
-                           int state, pid_t pid)
+int ustcmd_set_marker_state(const char *trace, const char *channel,
+                           const char *marker, int state, pid_t pid)
 {
        struct ustcomm_header req_header, res_header;
        struct ustcomm_marker_info marker_inf;
@@ -149,6 +149,7 @@ int ustcmd_set_marker_state(const char *channel, const char *marker,
 
        result = ustcomm_pack_marker_info(&req_header,
                                          &marker_inf,
+                                         trace,
                                          channel,
                                          marker);
        if (result < 0) {
@@ -169,8 +170,8 @@ int ustcmd_set_marker_state(const char *channel, const char *marker,
  * @param pid          Traced process ID
  * @return             0 if successful, or error
  */
-int ustcmd_set_subbuf_size(const char *channel, unsigned int subbuf_size,
-                          pid_t pid)
+int ustcmd_set_subbuf_size(const char *trace, const char *channel,
+                          unsigned int subbuf_size, pid_t pid)
 {
        struct ustcomm_header req_header, res_header;
        struct ustcomm_channel_info ch_inf;
@@ -178,6 +179,7 @@ int ustcmd_set_subbuf_size(const char *channel, unsigned int subbuf_size,
 
        result = ustcomm_pack_channel_info(&req_header,
                                           &ch_inf,
+                                          trace,
                                           channel);
        if (result < 0) {
                errno = -result;
@@ -198,8 +200,8 @@ int ustcmd_set_subbuf_size(const char *channel, unsigned int subbuf_size,
  * @param pid          Traced process ID
  * @return             0 if successful, or error
  */
-int ustcmd_set_subbuf_num(const char *channel, unsigned int num,
-                         pid_t pid)
+int ustcmd_set_subbuf_num(const char *trace, const char *channel,
+                         unsigned int num, pid_t pid)
 {
        struct ustcomm_header req_header, res_header;
        struct ustcomm_channel_info ch_inf;
@@ -207,6 +209,7 @@ int ustcmd_set_subbuf_num(const char *channel, unsigned int num,
 
        result = ustcomm_pack_channel_info(&req_header,
                                           &ch_inf,
+                                          trace,
                                           channel);
        if (result < 0) {
                errno = -result;
@@ -221,8 +224,8 @@ int ustcmd_set_subbuf_num(const char *channel, unsigned int num,
 
 }
 
-static int ustcmd_get_subbuf_num_size(const char *channel, pid_t pid,
-                              int *num, int *size)
+static int ustcmd_get_subbuf_num_size(const char *trace, const char *channel,
+                                     pid_t pid, int *num, int *size)
 {
        struct ustcomm_header req_header, res_header;
        struct ustcomm_channel_info ch_inf, *ch_inf_res;
@@ -231,6 +234,7 @@ static int ustcmd_get_subbuf_num_size(const char *channel, pid_t pid,
 
        result = ustcomm_pack_channel_info(&req_header,
                                           &ch_inf,
+                                          trace,
                                           channel);
        if (result < 0) {
                errno = -result;
@@ -260,11 +264,11 @@ static int ustcmd_get_subbuf_num_size(const char *channel, pid_t pid,
  * @param pid          Traced process ID
  * @return             subbuf cnf if successful, or error
  */
-int ustcmd_get_subbuf_num(const char *channel, pid_t pid)
+int ustcmd_get_subbuf_num(const char *trace, const char *channel, pid_t pid)
 {
        int num, size, result;
 
-       result = ustcmd_get_subbuf_num_size(channel, pid,
+       result = ustcmd_get_subbuf_num_size(trace, channel, pid,
                                            &num, &size);
        if (result < 0) {
                errno = -result;
@@ -281,11 +285,11 @@ int ustcmd_get_subbuf_num(const char *channel, pid_t pid)
  * @param pid          Traced process ID
  * @return             subbuf size if successful, or error
  */
-int ustcmd_get_subbuf_size(const char *channel, pid_t pid)
+int ustcmd_get_subbuf_size(const char *trace, const char *channel, pid_t pid)
 {
        int num, size, result;
 
-       result = ustcmd_get_subbuf_num_size(channel, pid,
+       result = ustcmd_get_subbuf_num_size(trace, channel, pid,
                                            &num, &size);
        if (result < 0) {
                errno = -result;
@@ -295,20 +299,35 @@ int ustcmd_get_subbuf_size(const char *channel, pid_t pid)
        return size;
 }
 
+
+static int do_trace_cmd(const char *trace, pid_t pid, int command)
+{
+       struct ustcomm_header req_header, res_header;
+       struct ustcomm_trace_info trace_inf;
+       int result;
+
+       result = ustcomm_pack_trace_info(&req_header,
+                                        &trace_inf,
+                                        trace);
+       if (result < 0) {
+               errno = -result;
+               return -1;
+       }
+
+       req_header.command = command;
+
+       return do_cmd(pid, &req_header, (char *)&trace_inf, &res_header, NULL);
+}
+
 /**
  * Destroys an UST trace according to a PID.
  *
  * @param pid  Traced process ID
  * @return     0 if successful, or error USTCMD_ERR_GEN
  */
-int ustcmd_destroy_trace(pid_t pid)
+int ustcmd_destroy_trace(const char *trace, pid_t pid)
 {
-       struct ustcomm_header req_header, res_header;
-
-       req_header.command = DESTROY_TRACE;
-       req_header.size = 0;
-
-       return do_cmd(pid, &req_header, NULL, &res_header, NULL);
+       return do_trace_cmd(trace, pid, DESTROY_TRACE);
 }
 
 /**
@@ -317,14 +336,9 @@ int ustcmd_destroy_trace(pid_t pid)
  * @param pid  Traced process ID
  * @return     0 if successful, or error USTCMD_ERR_GEN
  */
-int ustcmd_setup_and_start(pid_t pid)
+int ustcmd_setup_and_start(const char *trace, pid_t pid)
 {
-       struct ustcomm_header req_header, res_header;
-
-       req_header.command = START;
-       req_header.size = 0;
-
-       return do_cmd(pid, &req_header, NULL, &res_header, NULL);
+       return do_trace_cmd(trace, pid, START);
 }
 
 /**
@@ -333,14 +347,9 @@ int ustcmd_setup_and_start(pid_t pid)
  * @param pid  Traced process ID
  * @return     0 if successful, or error USTCMD_ERR_GEN
  */
-int ustcmd_create_trace(pid_t pid)
+int ustcmd_create_trace(const char *trace, pid_t pid)
 {
-       struct ustcomm_header req_header, res_header;
-
-       req_header.command = CREATE_TRACE;
-       req_header.size = 0;
-
-       return do_cmd(pid, &req_header, NULL, &res_header, NULL);
+       return do_trace_cmd(trace, pid, CREATE_TRACE);
 }
 
 /**
@@ -349,14 +358,9 @@ int ustcmd_create_trace(pid_t pid)
  * @param pid  Traced process ID
  * @return     0 if successful, or error USTCMD_ERR_GEN
  */
-int ustcmd_start_trace(pid_t pid)
+int ustcmd_start_trace(const char *trace, pid_t pid)
 {
-       struct ustcomm_header req_header, res_header;
-
-       req_header.command = START_TRACE;
-       req_header.size = 0;
-
-       return do_cmd(pid, &req_header, NULL, &res_header, NULL);
+       return do_trace_cmd(trace, pid, START_TRACE);
 }
 
 /**
@@ -365,14 +369,9 @@ int ustcmd_start_trace(pid_t pid)
  * @param pid  Traced process ID
  * @return     0 if successful, or error USTCMD_ERR_GEN
  */
-int ustcmd_alloc_trace(pid_t pid)
+int ustcmd_alloc_trace(const char *trace, pid_t pid)
 {
-       struct ustcomm_header req_header, res_header;
-
-       req_header.command = ALLOC_TRACE;
-       req_header.size = 0;
-
-       return do_cmd(pid, &req_header, NULL, &res_header, NULL);
+       return do_trace_cmd(trace, pid, ALLOC_TRACE);
 }
 
 /**
@@ -381,14 +380,9 @@ int ustcmd_alloc_trace(pid_t pid)
  * @param pid  Traced process ID
  * @return     0 if successful, or error USTCMD_ERR_GEN
  */
-int ustcmd_stop_trace(pid_t pid)
+int ustcmd_stop_trace(const char *trace, pid_t pid)
 {
-       struct ustcomm_header req_header, res_header;
-
-       req_header.command = STOP_TRACE;
-       req_header.size = 0;
-
-       return do_cmd(pid, &req_header, NULL, &res_header, NULL);
+       return do_trace_cmd(trace, pid, STOP_TRACE);
 }
 
 /**
index 7d0fe000155525669e28afaff4931d2597c2ecc8..bbdbd7ee643a7b4c887aced587f9e001a34ac8b5 100644 (file)
@@ -656,10 +656,20 @@ int ustcomm_unpack_trace_info(struct ustcomm_trace_info *trace_inf)
 
 int ustcomm_pack_channel_info(struct ustcomm_header *header,
                              struct ustcomm_channel_info *ch_inf,
+                             const char *trace,
                              const char *channel)
 {
        int offset = 0;
 
+       ch_inf->trace = ustcomm_print_data(ch_inf->data,
+                                          sizeof(ch_inf->data),
+                                          &offset,
+                                          trace);
+
+       if (ch_inf->trace == USTCOMM_POISON_PTR) {
+               return -ENOMEM;
+       }
+
        ch_inf->channel = ustcomm_print_data(ch_inf->data,
                                             sizeof(ch_inf->data),
                                             &offset,
@@ -677,6 +687,13 @@ int ustcomm_pack_channel_info(struct ustcomm_header *header,
 
 int ustcomm_unpack_channel_info(struct ustcomm_channel_info *ch_inf)
 {
+       ch_inf->trace = ustcomm_restore_ptr(ch_inf->trace,
+                                           ch_inf->data,
+                                           sizeof(ch_inf->data));
+       if (!ch_inf->trace) {
+               return -EINVAL;
+       }
+
        ch_inf->channel = ustcomm_restore_ptr(ch_inf->channel,
                                              ch_inf->data,
                                              sizeof(ch_inf->data));
@@ -689,11 +706,21 @@ int ustcomm_unpack_channel_info(struct ustcomm_channel_info *ch_inf)
 
 int ustcomm_pack_buffer_info(struct ustcomm_header *header,
                             struct ustcomm_buffer_info *buf_inf,
+                            const char *trace,
                             const char *channel,
                             int channel_cpu)
 {
        int offset = 0;
 
+       buf_inf->trace = ustcomm_print_data(buf_inf->data,
+                                           sizeof(buf_inf->data),
+                                           &offset,
+                                           trace);
+
+       if (buf_inf->trace == USTCOMM_POISON_PTR) {
+               return -ENOMEM;
+       }
+
        buf_inf->channel = ustcomm_print_data(buf_inf->data,
                                              sizeof(buf_inf->data),
                                              &offset,
@@ -713,6 +740,13 @@ int ustcomm_pack_buffer_info(struct ustcomm_header *header,
 
 int ustcomm_unpack_buffer_info(struct ustcomm_buffer_info *buf_inf)
 {
+       buf_inf->trace = ustcomm_restore_ptr(buf_inf->trace,
+                                            buf_inf->data,
+                                            sizeof(buf_inf->data));
+       if (!buf_inf->trace) {
+               return -EINVAL;
+       }
+
        buf_inf->channel = ustcomm_restore_ptr(buf_inf->channel,
                                               buf_inf->data,
                                               sizeof(buf_inf->data));
@@ -725,11 +759,22 @@ int ustcomm_unpack_buffer_info(struct ustcomm_buffer_info *buf_inf)
 
 int ustcomm_pack_marker_info(struct ustcomm_header *header,
                             struct ustcomm_marker_info *marker_inf,
+                            const char *trace,
                             const char *channel,
                             const char *marker)
 {
        int offset = 0;
 
+       marker_inf->trace = ustcomm_print_data(marker_inf->data,
+                                              sizeof(marker_inf->data),
+                                              &offset,
+                                              trace);
+
+       if (marker_inf->trace == USTCOMM_POISON_PTR) {
+               return -ENOMEM;
+       }
+
+
        marker_inf->channel = ustcomm_print_data(marker_inf->data,
                                                 sizeof(marker_inf->data),
                                                 &offset,
@@ -756,6 +801,13 @@ int ustcomm_pack_marker_info(struct ustcomm_header *header,
 
 int ustcomm_unpack_marker_info(struct ustcomm_marker_info *marker_inf)
 {
+       marker_inf->trace = ustcomm_restore_ptr(marker_inf->trace,
+                                               marker_inf->data,
+                                               sizeof(marker_inf->data));
+       if (!marker_inf->trace) {
+               return -EINVAL;
+       }
+
        marker_inf->channel = ustcomm_restore_ptr(marker_inf->channel,
                                                  marker_inf->data,
                                                  sizeof(marker_inf->data));
index ed8470f773e92cb93b2018166ce4b0392b360b49..ad4848a653c9656f1650aeddd6aea82ce79f5d32 100644 (file)
@@ -84,6 +84,7 @@ struct ustcomm_trace_info {
 };
 
 struct ustcomm_channel_info {
+       char *trace;
        char *channel;
        unsigned int subbuf_size;
        unsigned int subbuf_num;
@@ -91,6 +92,7 @@ struct ustcomm_channel_info {
 };
 
 struct ustcomm_buffer_info {
+       char *trace;
        char *channel;
        int ch_cpu;
        pid_t pid;
@@ -101,6 +103,7 @@ struct ustcomm_buffer_info {
 };
 
 struct ustcomm_marker_info {
+       char *trace;
        char *channel;
        char *marker;
        char data[USTCOMM_DATA_SIZE];
@@ -185,12 +188,14 @@ extern int ustcomm_unpack_trace_info(struct ustcomm_trace_info *trace_inf);
 
 extern int ustcomm_pack_channel_info(struct ustcomm_header *header,
                                     struct ustcomm_channel_info *ch_inf,
+                                    const char *trace,
                                     const char *channel);
 
 extern int ustcomm_unpack_channel_info(struct ustcomm_channel_info *ch_inf);
 
 extern int ustcomm_pack_buffer_info(struct ustcomm_header *header,
                                    struct ustcomm_buffer_info *buf_inf,
+                                   const char *trace,
                                    const char *channel,
                                    int channel_cpu);
 
@@ -198,6 +203,7 @@ extern int ustcomm_unpack_buffer_info(struct ustcomm_buffer_info *buf_inf);
 
 extern int ustcomm_pack_marker_info(struct ustcomm_header *header,
                                    struct ustcomm_marker_info *marker_inf,
+                                   const char *trace,
                                    const char *channel,
                                    const char *marker);
 
index 6e7b0cd5c145024e8a73a210508bdf5e9c63a0e8..1581f830cd4a83484c687a079cc2b293690352b4 100644 (file)
@@ -61,7 +61,7 @@ static int get_subbuffer(struct buffer_info *buf)
        send_msg = &_send_msg;
        recv_msg = &_recv_msg;
 
-       result = ustcomm_pack_buffer_info(send_hdr, send_msg,
+       result = ustcomm_pack_buffer_info(send_hdr, send_msg, buf->trace,
                                          buf->channel, buf->channel_cpu);
        if (result < 0) {
                return result;
@@ -105,7 +105,7 @@ static int put_subbuffer(struct buffer_info *buf)
        recv_hdr = &_recv_hdr;
        send_msg = &_send_msg;
 
-       result = ustcomm_pack_buffer_info(send_hdr, send_msg,
+       result = ustcomm_pack_buffer_info(send_hdr, send_msg, buf->trace,
                                          buf->channel, buf->channel_cpu);
        if (result < 0) {
                return result;
@@ -189,7 +189,7 @@ static int get_buf_shmid_pipe_fd(int sock, struct buffer_info *buf,
        send_msg = &_send_msg;
        recv_msg = &_recv_msg;
 
-       result = ustcomm_pack_buffer_info(send_hdr, send_msg,
+       result = ustcomm_pack_buffer_info(send_hdr, send_msg, buf->trace,
                                          buf->channel, buf->channel_cpu);
        if (result < 0) {
                ERR("Failed to pack buffer info");
@@ -234,7 +234,7 @@ static int get_subbuf_num_size(int sock, struct buffer_info *buf,
        send_msg = &_send_msg;
        recv_msg = &_recv_msg;
 
-       result = ustcomm_pack_channel_info(send_hdr, send_msg,
+       result = ustcomm_pack_channel_info(send_hdr, send_msg, buf->trace,
                                           buf->channel);
        if (result < 0) {
                return result;
@@ -266,7 +266,7 @@ static int notify_buffer_mapped(int sock, struct buffer_info *buf)
        recv_hdr = &_recv_hdr;
        send_msg = &_send_msg;
 
-       result = ustcomm_pack_buffer_info(send_hdr, send_msg,
+       result = ustcomm_pack_buffer_info(send_hdr, send_msg, buf->trace,
                                          buf->channel, buf->channel_cpu);
        if (result < 0) {
                return result;
@@ -285,7 +285,8 @@ static int notify_buffer_mapped(int sock, struct buffer_info *buf)
 
 
 struct buffer_info *connect_buffer(struct libustd_instance *instance, pid_t pid,
-                                  const char *channel, int channel_cpu)
+                                  const char *trace, const char *channel,
+                                  int channel_cpu)
 {
        struct buffer_info *buf;
        int result;
@@ -297,9 +298,14 @@ struct buffer_info *connect_buffer(struct libustd_instance *instance, pid_t pid,
                return NULL;
        }
 
+       buf->trace = strdup(trace);
+       if (!buf->trace) {
+               goto free_buf;
+       }
+
        buf->channel = strdup(channel);
        if (!buf->channel) {
-               goto free_buf;
+               goto free_buf_trace;
        }
 
        result = asprintf(&buf->name, "%s_%d", channel, channel_cpu);
@@ -403,6 +409,9 @@ free_buf_name:
 free_buf_channel:
        free(buf->channel);
 
+free_buf_trace:
+       free(buf->trace);
+
 free_buf:
        free(buf);
        return NULL;
@@ -508,6 +517,7 @@ int consumer_loop(struct libustd_instance *instance, struct buffer_info *buf)
 
 struct consumer_thread_args {
        pid_t pid;
+       const char *trace;
        const char *channel;
        int channel_cpu;
        struct libustd_instance *instance;
@@ -545,7 +555,7 @@ void *consumer_thread(void *arg)
                goto end;
        }
 
-       buf = connect_buffer(args->instance, args->pid,
+       buf = connect_buffer(args->instance, args->pid, args->trace,
                             args->channel, args->channel_cpu);
        if(buf == NULL) {
                ERR("failed to connect to buffer");
@@ -567,7 +577,8 @@ void *consumer_thread(void *arg)
 }
 
 int start_consuming_buffer(struct libustd_instance *instance, pid_t pid,
-                          const char *channel, int channel_cpu)
+                          const char *trace, const char *channel,
+                          int channel_cpu)
 {
        pthread_t thr;
        struct consumer_thread_args *args;
@@ -582,11 +593,12 @@ int start_consuming_buffer(struct libustd_instance *instance, pid_t pid,
        }
 
        args->pid = pid;
+       args->trace = strdup(trace);
        args->channel = strdup(channel);
        args->channel_cpu = channel_cpu;
        args->instance = instance;
-       DBG("beginning2 of start_consuming_buffer: args: pid %d bufname %s_%d",
-           args->pid, args->channel, args->channel_cpu);
+       DBG("beginning2 of start_consuming_buffer: args: pid %d trace %s"
+           " bufname %s_%d", args->pid, args->channel, args->channel_cpu);
 
        result = pthread_create(&thr, NULL, consumer_thread, args);
        if(result == -1) {
@@ -598,8 +610,8 @@ int start_consuming_buffer(struct libustd_instance *instance, pid_t pid,
                ERR("pthread_detach failed");
                return -1;
        }
-       DBG("end of start_consuming_buffer: args: pid %d bufname %s_%d",
-           args->pid, args->channel, args->channel_cpu);
+       DBG("end of start_consuming_buffer: args: pid %d trace %s "
+           "bufname %s_%d", args->pid, args->channel, args->channel_cpu);
 
        return 0;
 }
@@ -623,9 +635,11 @@ static void process_client_cmd(int sock, struct ustcomm_header *req_header,
                        return;
                }
 
-               DBG("Going to consume buffer %s_%d in process %d",
-                   buf_inf->channel, buf_inf->ch_cpu, buf_inf->pid);
+               DBG("Going to consume trace %s buffer %s_%d in process %d",
+                   buf_inf->trace, buf_inf->channel, buf_inf->ch_cpu,
+                   buf_inf->pid);
                result = start_consuming_buffer(instance, buf_inf->pid,
+                                               buf_inf->trace,
                                                buf_inf->channel,
                                                buf_inf->ch_cpu);
                if (result < 0) {
index 8a3376e6b61a857f114327a67d6aac431507aa8b..d44dafcca304b40e686aa28cdf1afec640308cdd 100644 (file)
@@ -34,6 +34,7 @@ static void ustcmd_function_tests(pid_t pid)
        struct marker_status *marker_status, *ms_ptr;
        char *old_socket_path, *new_socket_path;
        char *tmp_ustd_socket = "/tmp/tmp_ustd_socket";
+       char *trace = "auto";
 
        printf("Connecting to pid %d\n", pid);
 
@@ -75,79 +76,79 @@ static void ustcmd_function_tests(pid_t pid)
        free(old_socket_path);
 
        /* Enable, disable markers */
-       tap_ok(!ustcmd_set_marker_state("ust", "bar", 1, pid),
+       tap_ok(!ustcmd_set_marker_state(trace, "ust", "bar", 1, pid),
               "ustcmd_set_marker_state - existing marker ust bar");
 
        /* Create and allocate a trace */
-       tap_ok(!ustcmd_create_trace(pid), "ustcmd_create_trace");
+       tap_ok(!ustcmd_create_trace(trace, pid), "ustcmd_create_trace");
 
-       tap_ok(!ustcmd_alloc_trace(pid), "ustcmd_alloc_trace");
+       tap_ok(!ustcmd_alloc_trace(trace, pid), "ustcmd_alloc_trace");
 
        /* Get subbuf size and number */
-       subbuf_num = ustcmd_get_subbuf_num("ust", pid);
+       subbuf_num = ustcmd_get_subbuf_num(trace, "ust", pid);
        tap_ok(subbuf_num > 0, "ustcmd_get_subbuf_num - %d sub-buffers",
               subbuf_num);
 
-       subbuf_size = ustcmd_get_subbuf_size("ust", pid);
+       subbuf_size = ustcmd_get_subbuf_size(trace, "ust", pid);
        tap_ok(subbuf_size, "ustcmd_get_subbuf_size - sub-buffer size is %d",
               subbuf_size);
 
        /* Start the trace */
-       tap_ok(!ustcmd_start_trace(pid), "ustcmd_start_trace");
+       tap_ok(!ustcmd_start_trace(trace, pid), "ustcmd_start_trace");
 
 
        /* Stop the trace and destroy it*/
-       tap_ok(!ustcmd_stop_trace(pid), "ustcmd_stop_trace");
+       tap_ok(!ustcmd_stop_trace(trace, pid), "ustcmd_stop_trace");
 
-       tap_ok(!ustcmd_destroy_trace(pid), "ustcmd_destroy_trace");
+       tap_ok(!ustcmd_destroy_trace(trace, pid), "ustcmd_destroy_trace");
 
        /* Create a new trace */
-       tap_ok(!ustcmd_create_trace(pid), "ustcmd_create_trace - create a new trace");
+       tap_ok(!ustcmd_create_trace(trace, pid), "ustcmd_create_trace - create a new trace");
 
        printf("Setting new subbufer number and sizes (doubling)\n");
        new_subbuf_num = 2 * subbuf_num;
        new_subbuf_size = 2 * subbuf_size;
 
-       tap_ok(!ustcmd_set_subbuf_num("ust", new_subbuf_num, pid),
+       tap_ok(!ustcmd_set_subbuf_num(trace, "ust", new_subbuf_num, pid),
               "ustcmd_set_subbuf_num");
 
-       tap_ok(!ustcmd_set_subbuf_size("ust", new_subbuf_size, pid),
+       tap_ok(!ustcmd_set_subbuf_size(trace, "ust", new_subbuf_size, pid),
               "ustcmd_set_subbuf_size");
 
 
        /* Allocate the new trace */
-       tap_ok(!ustcmd_alloc_trace(pid), "ustcmd_alloc_trace - allocate the new trace");
+       tap_ok(!ustcmd_alloc_trace(trace, pid), "ustcmd_alloc_trace - allocate the new trace");
 
 
         /* Get subbuf size and number and compare with what was set */
-       subbuf_num = ustcmd_get_subbuf_num("ust", pid);
+       subbuf_num = ustcmd_get_subbuf_num(trace, "ust", pid);
 
-       subbuf_size = ustcmd_get_subbuf_size("ust", pid);
+       subbuf_size = ustcmd_get_subbuf_size(trace, "ust", pid);
 
        tap_ok(subbuf_num == new_subbuf_num, "Set a new subbuf number, %d == %d",
               subbuf_num, new_subbuf_num);
 
 
-       result = ustcmd_get_subbuf_size("ust", pid);
+       result = ustcmd_get_subbuf_size(trace, "ust", pid);
        tap_ok(subbuf_size == new_subbuf_size, "Set a new subbuf size, %d == %d",
               subbuf_size, new_subbuf_size);
 
-       tap_ok(!ustcmd_destroy_trace(pid), "ustcmd_destroy_trace - without ever starting");
+       tap_ok(!ustcmd_destroy_trace(trace, pid), "ustcmd_destroy_trace - without ever starting");
 
 
        printf("##### Tests that definetly should work are completed #####\n");
        printf("############## Start expected failure cases ##############\n");
 
-       tap_ok(ustcmd_set_marker_state("ust","bar", 1, pid),
+       tap_ok(ustcmd_set_marker_state(trace, "ust","bar", 1, pid),
               "Enable already enabled marker ust/bar");
 
-       tap_ok(ustcmd_set_marker_state("ustl", "blar", 1, pid),
+       tap_ok(ustcmd_set_marker_state(trace, "ustl", "blar", 1, pid),
               "Enable non-existent marker ustl blar");
 
-       tap_ok(ustcmd_start_trace(pid),
+       tap_ok(ustcmd_start_trace(trace, pid),
               "Start a non-existent trace");
 
-       tap_ok(ustcmd_destroy_trace(pid),
+       tap_ok(ustcmd_destroy_trace(trace, pid),
               "Destroy non-existent trace");
 
        exit(tap_status() ? EXIT_FAILURE : EXIT_SUCCESS);
index 48aa758d076519d09103639b3355da602e332e95..aad3834a4ccfeb597bc21f22bd95b09de80262ee 100644 (file)
@@ -216,6 +216,8 @@ static int scan_ch_and_num(const char *ch_num, char **channel, unsigned int *num
        }
 }
 
+char *trace = "auto";
+
 int main(int argc, char *argv[])
 {
        pid_t *pidit;
@@ -272,7 +274,7 @@ int main(int argc, char *argv[])
        while(*pidit != -1) {
                switch (opts.cmd) {
                        case CREATE_TRACE:
-                               result = ustcmd_create_trace(*pidit);
+                               result = ustcmd_create_trace(trace, *pidit);
                                if (result) {
                                        ERR("error while trying to create trace with PID %u\n", (unsigned int) *pidit);
                                        retval = EXIT_FAILURE;
@@ -281,7 +283,7 @@ int main(int argc, char *argv[])
                                break;
 
                        case START_TRACE:
-                               result = ustcmd_start_trace(*pidit);
+                               result = ustcmd_start_trace(trace, *pidit);
                                if (result) {
                                        ERR("error while trying to for trace with PID %u\n", (unsigned int) *pidit);
                                        retval = EXIT_FAILURE;
@@ -290,7 +292,7 @@ int main(int argc, char *argv[])
                                break;
 
                        case STOP_TRACE:
-                               result = ustcmd_stop_trace(*pidit);
+                               result = ustcmd_stop_trace(trace, *pidit);
                                if (result) {
                                        ERR("error while trying to stop trace for PID %u\n", (unsigned int) *pidit);
                                        retval = EXIT_FAILURE;
@@ -299,7 +301,7 @@ int main(int argc, char *argv[])
                                break;
 
                        case DESTROY_TRACE:
-                               result = ustcmd_destroy_trace(*pidit);
+                               result = ustcmd_destroy_trace(trace, *pidit);
                                if (result) {
                                        ERR("error while trying to destroy trace with PID %u\n", (unsigned int) *pidit);
                                        retval = EXIT_FAILURE;
@@ -355,7 +357,7 @@ int main(int argc, char *argv[])
                                                retval = EXIT_FAILURE;
                                                break;
                                        }
-                                       if (ustcmd_set_marker_state(channel, marker, 1, *pidit)) {
+                                       if (ustcmd_set_marker_state(trace, channel, marker, 1, *pidit)) {
                                                PERROR("error while trying to enable marker %s with PID %u",
                                                       opts.regex, (unsigned int) *pidit);
                                                retval = EXIT_FAILURE;
@@ -372,7 +374,7 @@ int main(int argc, char *argv[])
                                                retval = EXIT_FAILURE;
                                                break;
                                        }
-                                       if (ustcmd_set_marker_state(channel, marker, 0, *pidit)) {
+                                       if (ustcmd_set_marker_state(trace, channel, marker, 0, *pidit)) {
                                                ERR("error while trying to disable marker %s with PID %u\n",
                                                                opts.regex, (unsigned int) *pidit);
                                                retval = EXIT_FAILURE;
@@ -389,7 +391,7 @@ int main(int argc, char *argv[])
                                                break;
                                        }
 
-                                       if (ustcmd_set_subbuf_size(channel, size, *pidit)) {
+                                       if (ustcmd_set_subbuf_size(trace, channel, size, *pidit)) {
                                                ERR("error while trying to set the size of subbuffers with PID %u\n",
                                                                (unsigned int) *pidit);
                                                retval = EXIT_FAILURE;
@@ -411,7 +413,7 @@ int main(int argc, char *argv[])
                                                retval = EXIT_FAILURE;
                                                break;
                                        }
-                                       if (ustcmd_set_subbuf_num(channel, num, *pidit)) {
+                                       if (ustcmd_set_subbuf_num(trace, channel, num, *pidit)) {
                                                ERR("error while trying to set the number of subbuffers with PID %u\n",
                                                                (unsigned int) *pidit);
                                                retval = EXIT_FAILURE;
@@ -420,7 +422,7 @@ int main(int argc, char *argv[])
                                break;
 
                        case GET_SUBBUF_SIZE:
-                               result = ustcmd_get_subbuf_size(opts.regex, *pidit);
+                               result = ustcmd_get_subbuf_size(trace, opts.regex, *pidit);
                                if (result == -1) {
                                        ERR("error while trying to get_subuf_size with PID %u\n", (unsigned int) *pidit);
                                        retval = EXIT_FAILURE;
@@ -431,7 +433,7 @@ int main(int argc, char *argv[])
                                break;
 
                        case GET_SUBBUF_NUM:
-                               result = ustcmd_get_subbuf_num(opts.regex, *pidit);
+                               result = ustcmd_get_subbuf_num(trace, opts.regex, *pidit);
                                if (result == -1) {
                                        ERR("error while trying to get_subuf_num with PID %u\n", (unsigned int) *pidit);
                                        retval = EXIT_FAILURE;
@@ -442,7 +444,7 @@ int main(int argc, char *argv[])
                                break;
 
                        case ALLOC_TRACE:
-                               result = ustcmd_alloc_trace(*pidit);
+                               result = ustcmd_alloc_trace(trace, *pidit);
                                if (result) {
                                        ERR("error while trying to alloc trace with PID %u\n", (unsigned int) *pidit);
                                        retval = EXIT_FAILURE;
This page took 0.044818 seconds and 4 git commands to generate.