From mboxrd@z Thu Jan 1 00:00:00 1970 From: david.goulet@polymtl.ca (David Goulet) Date: Tue, 02 Nov 2010 12:43:31 -0400 Subject: [ltt-dev] [UST PATCH] Add trace name to ustcomm structs and push trace name to ustctl In-Reply-To: <1288601857-26835-1-git-send-email-nils.carlson@ericsson.com> References: <1288601857-26835-1-git-send-email-nils.carlson@ericsson.com> Message-ID: <4CD03FB3.1080603@polymtl.ca> Hmmm, for what I can see, this patch add something else. I wonder if we should maybe separate this patch into two? I'm talking about the do_trace_cmd function and ustcomm_pack_trace_info that are yes related to the addition of trace name but maybe a first patch adding these two functions and then the trace name ? I don't want to make your life harder :P but I've been told too many times that ;) (thanks Mathieu :D). What do you think? David On 10-11-01 04:57 AM, Nils Carlson wrote: > This patch adds the trace name to all ustcomm structs and > corresponding functions. In the long-term this should allow us > to have multiple trace sessions. > > Signed-off-by: Nils Carlson > --- > include/ust/ustcmd.h | 26 ++-- > include/ust/ustd.h | 1 + > libust/tracectl.c | 84 +++++++++---- > libustcmd/ustcmd.c | 102 +++++++-------- > libustcomm/ustcomm.c | 133 ++++++++++++------- > libustcomm/ustcomm.h | 17 +++ > libustd/libustd.c | 44 +++++--- > .../ustcmd_function_tests/ustcmd_function_tests.c | 41 +++--- > ustctl/ustctl.c | 24 ++-- > 9 files changed, 287 insertions(+), 185 deletions(-) > > diff --git a/include/ust/ustcmd.h b/include/ust/ustcmd.h > index b32fe36..6273575 100644 > --- a/include/ust/ustcmd.h > +++ b/include/ust/ustcmd.h > @@ -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); > diff --git a/include/ust/ustd.h b/include/ust/ustd.h > index 01b88d7..0757acb 100644 > --- a/include/ust/ustd.h > +++ b/include/ust/ustd.h > @@ -37,6 +37,7 @@ struct ustcomm_sock; > > struct buffer_info { > char *name; > + char *trace; > char *channel; > int channel_cpu; > > diff --git a/libust/tracectl.c b/libust/tracectl.c > index 5f942cd..d5ca7d2 100644 > --- a/libust/tracectl.c > +++ b/libust/tracectl.c > @@ -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; jchannels[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, > diff --git a/libustcmd/ustcmd.c b/libustcmd/ustcmd.c > index a53455a..bffd3c2 100644 > --- a/libustcmd/ustcmd.c > +++ b/libustcmd/ustcmd.c > @@ -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); > } > > /** > diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c > index 2c547ab..bbdbd7e 100644 > --- a/libustcomm/ustcomm.c > +++ b/libustcomm/ustcomm.c > @@ -621,13 +621,55 @@ char * ustcomm_restore_ptr(char *ptr, char *data_field, int data_field_size) > return data_field + (long)ptr; > } > > +int ustcomm_pack_trace_info(struct ustcomm_header *header, > + struct ustcomm_trace_info *trace_inf, > + const char *trace) > +{ > + int offset = 0; > + > + trace_inf->trace = ustcomm_print_data(trace_inf->data, > + sizeof(trace_inf->data), > + &offset, > + trace); > + > + if (trace_inf->trace == USTCOMM_POISON_PTR) { > + return -ENOMEM; > + } > + > + header->size = COMPUTE_MSG_SIZE(trace_inf, offset); > + > + return 0; > +} > + > + > +int ustcomm_unpack_trace_info(struct ustcomm_trace_info *trace_inf) > +{ > + trace_inf->trace = ustcomm_restore_ptr(trace_inf->trace, > + trace_inf->data, > + sizeof(trace_inf->data)); > + if (!trace_inf->trace) { > + return -EINVAL; > + } > + > + return 0; > +} > > 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, > @@ -645,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)); > @@ -657,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, > @@ -681,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)); > @@ -693,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, > @@ -724,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)); > @@ -775,52 +859,3 @@ int ustcomm_unpack_sock_path(struct ustcomm_sock_path *sock_path_inf) > return 0; > } > > -int ustcomm_send_ch_req(int sock, char *channel, int command, > - struct ustcomm_header *recv_header, > - char *recv_data) > -{ > - struct ustcomm_header send_header; > - struct ustcomm_channel_info ch_info; > - int result; > - > - result = ustcomm_pack_channel_info(&send_header, > - &ch_info, > - channel); > - if (result< 0) { > - return result; > - } > - > - send_header.command = command; > - > - return ustcomm_req(sock, > - &send_header, > - (char *)&ch_info, > - recv_header, > - recv_data); > -} > - > -int ustcomm_send_buf_req(int sock, char *channel, int ch_cpu, > - int command, > - struct ustcomm_header *recv_header, > - char *recv_data) > -{ > - struct ustcomm_header send_header; > - struct ustcomm_buffer_info buf_info; > - int result; > - > - result = ustcomm_pack_buffer_info(&send_header, > - &buf_info, > - channel, > - ch_cpu); > - if (result< 0) { > - return result; > - } > - > - send_header.command = command; > - > - return ustcomm_req(sock, > - &send_header, > - (char *)&buf_info, > - recv_header, > - recv_data); > -} > diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h > index f62250c..2d5ac5c 100644 > --- a/libustcomm/ustcomm.h > +++ b/libustcomm/ustcomm.h > @@ -78,7 +78,13 @@ enum tracectl_commands { > STOP_TRACE, > }; > > +struct ustcomm_trace_info { > + char *trace; > + char data[USTCOMM_DATA_SIZE]; > +}; > + > struct ustcomm_channel_info { > + char *trace; > char *channel; > unsigned int subbuf_size; > unsigned int subbuf_num; > @@ -86,6 +92,7 @@ struct ustcomm_channel_info { > }; > > struct ustcomm_buffer_info { > + char *trace; > char *channel; > int ch_cpu; > pid_t pid; > @@ -96,6 +103,7 @@ struct ustcomm_buffer_info { > }; > > struct ustcomm_marker_info { > + char *trace; > char *channel; > char *marker; > char data[USTCOMM_DATA_SIZE]; > @@ -172,14 +180,22 @@ extern char * ustcomm_restore_ptr(char *ptr, char *data_field, > (size_t) (long)(struct_ptr)->data - (long)(struct_ptr) + (offset) > > /* Packing and unpacking functions, making life easier */ > +extern int ustcomm_pack_trace_info(struct ustcomm_header *header, > + struct ustcomm_trace_info *trace_inf, > + const char *trace); > + > +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); > > @@ -187,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); > > diff --git a/libustd/libustd.c b/libustd/libustd.c > index 6e7b0cd..1581f83 100644 > --- a/libustd/libustd.c > +++ b/libustd/libustd.c > @@ -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) { > diff --git a/tests/ustcmd_function_tests/ustcmd_function_tests.c b/tests/ustcmd_function_tests/ustcmd_function_tests.c > index 8a3376e..d44dafc 100644 > --- a/tests/ustcmd_function_tests/ustcmd_function_tests.c > +++ b/tests/ustcmd_function_tests/ustcmd_function_tests.c > @@ -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); > diff --git a/ustctl/ustctl.c b/ustctl/ustctl.c > index 48aa758..aad3834 100644 > --- a/ustctl/ustctl.c > +++ b/ustctl/ustctl.c > @@ -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; -- David Goulet LTTng project, DORSAL Lab. PGP/GPG : 1024D/16BD8563 BE3C 672B 9331 9796 291A 14C6 4AF7 C14B 16BD 8563