ust: cleanups and functionality
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Wed, 18 Feb 2009 01:19:51 +0000 (20:19 -0500)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Wed, 18 Feb 2009 01:19:51 +0000 (20:19 -0500)
- move trace starting from hello.c to libtracectl
- support early tracing
- initialize libs in the right places

hello/hello.c
hello/marker-control.c
libmarkers/marker.c
libtracectl/tracectl.c
libtracing/relay.c

index d6429f133ba339e411fb01250f96de5d0bcb3756..d271a453149b4e74b05ee7242f185b408b645d18 100644 (file)
@@ -14,8 +14,6 @@
 
 
 char consumer_stack[10000];
-char trace_name[] = "theusttrace";
-char trace_type[] = "ustrelay";
 
 #define CPRINTF(fmt, args...) safe_printf(fmt "\n", ## args)
 
@@ -47,6 +45,7 @@ int consumer(void *arg)
        struct ltt_trace_struct *trace;
        struct consumer_channel *consumer_channels;
        int i;
+       char trace_name[] = "auto";
 
        ltt_lock_traces();
        trace = _ltt_trace_find(trace_name);
@@ -200,34 +199,6 @@ int main()
 
        init_int_handler();
 
-       result = ltt_marker_connect("foo", "bar", "default");
-       if(result)
-               ERR("ltt_marker_connect");
-
-       result = ltt_trace_setup(trace_name);
-       if(result < 0) {
-               ERR("ltt_trace_setup failed");
-               return 1;
-       }
-
-       result = ltt_trace_set_type(trace_name, trace_type);
-       if(result < 0) {
-               ERR("ltt_trace_set_type failed");
-               return 1;
-       }
-
-       result = ltt_trace_alloc(trace_name);
-       if(result < 0) {
-               ERR("ltt_trace_alloc failed");
-               return 1;
-       }
-
-       result = ltt_trace_start(trace_name);
-       if(result < 0) {
-               ERR("ltt_trace_start failed");
-               return 1;
-       }
-
        start_consumer();
        printf("Hello, World!\n");
 
@@ -237,8 +208,8 @@ int main()
                usleep(100000);
        }
 
-       ltt_trace_stop(trace_name);
-       ltt_trace_destroy(trace_name);
+       ltt_trace_stop("auto");
+       ltt_trace_destroy("auto");
 
        scanf("%*s");
 
index 9d231d1143438b83358fdd2d5ea86f6c104c4fb3..ab5413dcbc4c2c757f8aa01d1a56dc4b1c00d42c 100644 (file)
@@ -409,24 +409,30 @@ static void disconnect_all_markers(void)
        }
 }
 
-int __attribute__((constructor)) marker_control_init(void)
+static char initialized = 0;
+
+void __attribute__((constructor)) init_marker_control(void)
 {
-       int ret;
+       if(!initialized) {
+               int ret;
 
 //ust//        pentry = create_proc_entry("ltt", S_IRUSR|S_IWUSR, NULL);
 //ust//        if (!pentry)
 //ust//                return -EBUSY;
 //ust//        markers_loaded_cachep = KMEM_CACHE(ltt_active_marker, 0);
 
-       ret = ltt_probe_register(&default_probe);
-       BUG_ON(ret);
-       ret = ltt_marker_connect("metadata", "core_marker_format",
-                                DEFAULT_PROBE);
-       BUG_ON(ret);
-       ret = ltt_marker_connect("metadata", "core_marker_id", DEFAULT_PROBE);
-       BUG_ON(ret);
+               ret = ltt_probe_register(&default_probe);
+               BUG_ON(ret);
+               ret = ltt_marker_connect("metadata", "core_marker_format",
+                                        DEFAULT_PROBE);
+               BUG_ON(ret);
+               ret = ltt_marker_connect("metadata", "core_marker_id", DEFAULT_PROBE);
+               BUG_ON(ret);
 //ust//        pentry->proc_fops = &ltt_fops;
 
+               initialized = 1;
+       }
+
        return 0;
 }
 //ust// module_init(marker_control_init);
index 139b4327084528e2eb8e99f81eecfe30d1e43cf3..198650b32d41846e0b8180c865ab5177e54119d7 100644 (file)
@@ -678,6 +678,20 @@ void marker_update_probe_range(struct marker *begin,
                        /*
                         * ignore error, continue
                         */
+
+                       /* This is added for UST. We emit a core_marker_id event
+                        * for markers that are already registered to a probe
+                        * upon library load. Otherwise, no core_marker_id will
+                        * be generated for these markers. Is this the right thing
+                        * to do?
+                        */
+                       trace_mark(metadata, core_marker_id,
+                                  "channel %s name %s event_id %hu "
+                                  "int #1u%zu long #1u%zu pointer #1u%zu "
+                                  "size_t #1u%zu alignment #1u%u",
+                                  iter->channel, iter->name, mark_entry->event_id,
+                                  sizeof(int), sizeof(long), sizeof(void *),
+                                  sizeof(size_t), ltt_get_alignment());
                } else {
                        disable_marker(iter);
                }
@@ -1467,13 +1481,21 @@ int marker_register_lib(struct marker *markers_start, int markers_count)
 
        list_add(&pl->list, &libs);
 
+       /* FIXME: update just the loaded lib */
+       lib_update_markers();
+
        printf("just registered a markers section from %p and having %d markers\n", markers_start, markers_count);
        
        return 0;
 }
 
-static void __attribute__((constructor)) __markers__init(void)
+static int initialized = 0;
+
+void __attribute__((constructor)) init_markers(void)
 {
-       marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));
-       printf("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers);
+       if(!initialized) {
+               marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));
+               printf("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers);
+               initialized = 1;
+       }
 }
index 04de9f39be695194187f7c7b816091990aed67c1..874f4149e4419dcbad50cf4272ab7961cabe8bd0 100644 (file)
@@ -255,6 +255,50 @@ static void __attribute__((constructor)) init()
 
        mypid = getpid();
 
+       if(getenv("UST_TRACE")) {
+               char trace_name[] = "auto";
+               char trace_type[] = "ustrelay";
+
+               DBG("starting early tracing");
+
+               /* Ensure marker control is initialized */
+               init_marker_control();
+
+               /* Ensure relay is initialized */
+               init_ustrelay_transport();
+
+               /* Ensure markers are initialized */
+               init_markers();
+
+               result = ltt_marker_connect("foo", "bar", "default");
+               if(result)
+                       ERR("ltt_marker_connect");
+
+               result = ltt_trace_setup(trace_name);
+               if(result < 0) {
+                       ERR("ltt_trace_setup failed");
+                       return;
+               }
+
+               result = ltt_trace_set_type(trace_name, trace_type);
+               if(result < 0) {
+                       ERR("ltt_trace_set_type failed");
+                       return;
+               }
+
+               result = ltt_trace_alloc(trace_name);
+               if(result < 0) {
+                       ERR("ltt_trace_alloc failed");
+                       return;
+               }
+
+               result = ltt_trace_start(trace_name);
+               if(result < 0) {
+                       ERR("ltt_trace_start failed");
+                       return;
+               }
+       }
+
        /* Must create socket before signal handler to prevent races
          * on pfd variable.
          */
index 4c8dd2a5aaa63bedf91ceba7b9b38b0113513678..c063d1faddcda841987b9c4b4950408956199438 100644 (file)
@@ -2344,9 +2344,14 @@ static struct ltt_transport ust_relay_transport = {
 //ust//        return 0;
 //ust// }
 
+static char initialized = 0;
+
 void __attribute__((constructor)) init_ustrelay_transport(void)
 {
-       ltt_transport_register(&ust_relay_transport);
+       if(!initialized) {
+               ltt_transport_register(&ust_relay_transport);
+               initialized = 1;
+       }
 }
 
 static void __exit ltt_relay_exit(void)
This page took 0.027952 seconds and 4 git commands to generate.