add support for channel overwrite and non-collection
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Wed, 7 Apr 2010 18:36:42 +0000 (14:36 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Wed, 7 Apr 2010 18:36:42 +0000 (14:36 -0400)
libust/channels.c
libust/channels.h
libust/tracectl.c
libust/tracer.c

index abb2986c4689a4354d7e49648ea9ce7ca2f0e91a..32942cf795f79a4d7c1f7b63755eef68a9c4fdf8 100644 (file)
@@ -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;
        }
index e92e6cced4b31c119927757c317899d2f860487d..693bf82bedc9bac9208abd66d491fd878ed9efb4 100644 (file)
@@ -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 */
index bb03447d6fabdad5cea31cde8ec5e3bc888a35ac..74ad4ea6be59a309ab8a4634ae7af15d48725d2b 100644 (file)
@@ -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; j<trace->channels[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; j<trace->channels[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();
index 6f3c1aeaaf58b37cfc52fd310b49f655a40d7921..60fc8b7a182270110e9408ec7d96fd72e655d8e0 100644 (file)
@@ -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;
This page took 0.026976 seconds and 4 git commands to generate.