From: Pierre-Marc Fournier Date: Wed, 18 Feb 2009 01:19:51 +0000 (-0500) Subject: ust: cleanups and functionality X-Git-Tag: v1.9.1~1061 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=4db647c5217c9350040c781cdca7ad4a09384337;p=lttng-ust.git ust: cleanups and functionality - move trace starting from hello.c to libtracectl - support early tracing - initialize libs in the right places --- diff --git a/hello/hello.c b/hello/hello.c index d6429f13..d271a453 100644 --- a/hello/hello.c +++ b/hello/hello.c @@ -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"); diff --git a/hello/marker-control.c b/hello/marker-control.c index 9d231d11..ab5413dc 100644 --- a/hello/marker-control.c +++ b/hello/marker-control.c @@ -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 = <t_fops; + initialized = 1; + } + return 0; } //ust// module_init(marker_control_init); diff --git a/libmarkers/marker.c b/libmarkers/marker.c index 139b4327..198650b3 100644 --- a/libmarkers/marker.c +++ b/libmarkers/marker.c @@ -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; + } } diff --git a/libtracectl/tracectl.c b/libtracectl/tracectl.c index 04de9f39..874f4149 100644 --- a/libtracectl/tracectl.c +++ b/libtracectl/tracectl.c @@ -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. */ diff --git a/libtracing/relay.c b/libtracing/relay.c index 4c8dd2a5..c063d1fa 100644 --- a/libtracing/relay.c +++ b/libtracing/relay.c @@ -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)