From: Pierre-Marc Fournier Date: Wed, 7 Apr 2010 18:36:42 +0000 (-0400) Subject: add support for channel overwrite and non-collection X-Git-Tag: v0.5~37 X-Git-Url: https://git.lttng.org/?p=ust.git;a=commitdiff_plain;h=8649cd59b1c15b8d4097cf63f733e8007d76ad13 add support for channel overwrite and non-collection --- diff --git a/libust/channels.c b/libust/channels.c index abb2986..32942cf 100644 --- a/libust/channels.c +++ b/libust/channels.c @@ -45,6 +45,9 @@ static LIST_HEAD(ltt_channels); static unsigned int free_index; static struct kref index_kref; /* Keeps track of allocated trace channels */ +int ust_channels_overwrite_by_default = 0; +int ust_channels_request_collection_by_default = 1; + static struct ltt_channel_setting *lookup_channel(const char *name) { struct ltt_channel_setting *iter; @@ -246,6 +249,7 @@ int ltt_channels_get_index_from_name(const char *name) */ struct ust_channel *ltt_channels_trace_alloc(unsigned int *nr_channels, int overwrite, + int request_collection, int active) { struct ust_channel *channel = NULL; @@ -272,6 +276,7 @@ struct ust_channel *ltt_channels_trace_alloc(unsigned int *nr_channels, channel[iter->index].subbuf_size = iter->subbuf_size; channel[iter->index].subbuf_cnt = iter->subbuf_cnt; channel[iter->index].overwrite = overwrite; + channel[iter->index].request_collection = request_collection; channel[iter->index].active = active; channel[iter->index].channel_name = iter->name; } diff --git a/libust/channels.h b/libust/channels.h index e92e6cc..693bf82 100644 --- a/libust/channels.h +++ b/libust/channels.h @@ -39,6 +39,8 @@ struct ust_channel { int *buf_struct_shmids; struct ust_buffer **buf; int overwrite:1; + /* whether collection is requested upon trace start */ + int request_collection:1; int active:1; unsigned int n_subbufs_order; unsigned long commit_count_mask; /* @@ -80,9 +82,13 @@ extern const char *ltt_channels_get_name_from_index(unsigned int index); extern int ltt_channels_get_index_from_name(const char *name); extern struct ust_channel *ltt_channels_trace_alloc(unsigned int *nr_channels, int overwrite, + int request_collection, int active); extern void ltt_channels_trace_free(struct ust_channel *channels); extern int _ltt_channels_get_event_id(const char *channel, const char *name); extern int ltt_channels_get_event_id(const char *channel, const char *name); +extern int ust_channels_overwrite_by_default; +extern int ust_channels_request_collection_by_default; + #endif /* UST_CHANNELS_H */ diff --git a/libust/tracectl.c b/libust/tracectl.c index bb03447..74ad4ea 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -58,7 +58,7 @@ struct tracecmd { /* no padding */ }; /* volatile because shared between the listener and the main thread */ -volatile sig_atomic_t buffers_to_export = 0; +int buffers_to_export = 0; struct trctl_msg { /* size: the size of all the fields except size itself */ @@ -144,17 +144,19 @@ static void inform_consumer_daemon(const char *trace_name) } for(i=0; i < trace->nr_channels; i++) { - /* iterate on all cpus */ - for(j=0; jchannels[i].n_cpus; j++) { - char *buf; - asprintf(&buf, "%s_%d", trace->channels[i].channel_name, j); - result = ustcomm_request_consumer(pid, buf); - if(result == -1) { - WARN("Failed to request collection for channel %s. Is the daemon available?", trace->channels[i].channel_name); - /* continue even if fail */ + if(trace->channels[i].request_collection) { + /* iterate on all cpus */ + for(j=0; jchannels[i].n_cpus; j++) { + char *buf; + asprintf(&buf, "%s_%d", trace->channels[i].channel_name, j); + result = ustcomm_request_consumer(pid, buf); + if(result == -1) { + WARN("Failed to request collection for channel %s. Is the daemon available?", trace->channels[i].channel_name); + /* continue even if fail */ + } + free(buf); + STORE_SHARED(buffers_to_export, LOAD_SHARED(buffers_to_export)+1); } - free(buf); - buffers_to_export++; } } @@ -645,7 +647,7 @@ static int do_cmd_get_subbuffer(const char *recvbuf, struct ustcomm_source *src) */ if(uatomic_read(&buf->consumed) == 0) { DBG("decrementing buffers_to_export"); - buffers_to_export--; + STORE_SHARED(buffers_to_export, LOAD_SHARED(buffers_to_export)-1); } break; @@ -1152,6 +1154,26 @@ static void __attribute__((constructor)) init() } } + if(getenv("UST_OVERWRITE")) { + int val = atoi(getenv("UST_OVERWRITE")); + if(val == 0 || val == 1) { + STORE_SHARED(ust_channels_overwrite_by_default, val); + } + else { + WARN("invalid value for UST_OVERWRITE"); + } + } + + if(getenv("UST_AUTOCOLLECT")) { + int val = atoi(getenv("UST_AUTOCOLLECT")); + if(val == 0 || val == 1) { + STORE_SHARED(ust_channels_request_collection_by_default, val); + } + else { + WARN("invalid value for UST_AUTOCOLLECT"); + } + } + if(getenv("UST_TRACE")) { char trace_name[] = "auto"; char trace_type[] = "ustrelay"; @@ -1322,10 +1344,10 @@ static void stop_listener() static void __attribute__((destructor)) keepalive() { - if(trace_recording() && buffers_to_export) { + if(trace_recording() && LOAD_SHARED(buffers_to_export)) { int total = 0; DBG("Keeping process alive for consumer daemon..."); - while(buffers_to_export) { + while(LOAD_SHARED(buffers_to_export)) { const int interv = 200000; restarting_usleep(interv); total += interv; @@ -1394,7 +1416,7 @@ static void ust_fork(void) /* free app, keeping socket file */ ustcomm_fini_app(&ustcomm_app, 1); - buffers_to_export = 0; + STORE_SHARED(buffers_to_export, 0); have_listener = 0; init_socket(); create_listener(); diff --git a/libust/tracer.c b/libust/tracer.c index 6f3c1ae..60fc8b7 100644 --- a/libust/tracer.c +++ b/libust/tracer.c @@ -389,7 +389,8 @@ int _ltt_trace_setup(const char *trace_name) } strncpy(new_trace->trace_name, trace_name, NAME_MAX); new_trace->channels = ltt_channels_trace_alloc(&new_trace->nr_channels, - 0, 1); + ust_channels_overwrite_by_default, + ust_channels_request_collection_by_default, 1); if (!new_trace->channels) { ERR("Unable to allocate memory for chaninfo %s\n", trace_name); err = -ENOMEM;