From 20b37a3100b0d8722b361f62fd592520264fb9fa Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Thu, 19 Feb 2009 00:08:48 -0500 Subject: [PATCH] ust: add markers autoconnect --- hello/hello.c | 4 ++-- libmallocwrap/Makefile | 2 +- libmarkers/marker.c | 19 +++++++++++++++++++ libmarkers/marker.h | 2 ++ libtracectl/tracectl.c | 32 ++++++++++++++++++++++++-------- 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/hello/hello.c b/hello/hello.c index 3c4843a..67b9ef3 100644 --- a/hello/hello.c +++ b/hello/hello.c @@ -204,8 +204,8 @@ int main() sleep(1); for(i=0; i<50; i++) { - trace_mark(foo, bar, "str %s", "FOOBAZ"); - trace_mark(foo, bar2, "number1 %d number2 %d", 53, 9800); + trace_mark(ust, bar, "str %s", "FOOBAZ"); + trace_mark(ust, bar2, "number1 %d number2 %d", 53, 9800); usleep(100000); } diff --git a/libmallocwrap/Makefile b/libmallocwrap/Makefile index 6f12740..d5890a7 100644 --- a/libmallocwrap/Makefile +++ b/libmallocwrap/Makefile @@ -1,6 +1,6 @@ all: libmallocwrap.so libmallocwrap.so: mallocwrap.c - gcc -shared -fPIC -g -I../share -I../libmarkers -I../libtracing -I../libtracectl -L../libmarkers -L../libtracing -L../libtracectl -ldl -lmarkers -o libmallocwrap.so mallocwrap.c + gcc -shared -fPIC -g -I../share -I../libmarkers -I../libtracing -I../libtracectl -L../libmarkers -L../libtracing -L../libtracectl $(CFLAGS) -ldl -lmarkers -o libmallocwrap.so mallocwrap.c .PHONY: libmallocwrap.so diff --git a/libmarkers/marker.c b/libmarkers/marker.c index e1b62c7..43dfff7 100644 --- a/libmarkers/marker.c +++ b/libmarkers/marker.c @@ -1471,6 +1471,23 @@ void lib_update_markers(void) //ust// mutex_unlock(&module_mutex); } +static void (*new_marker_cb)(struct marker *) = NULL; + +void marker_set_new_marker_cb(void (*cb)(struct marker *)) +{ + new_marker_cb = cb; +} + +static void new_markers(struct marker *start, struct marker *end) +{ + if(new_marker_cb) { + struct marker *m; + for(m=start; m < end; m++) { + new_marker_cb(m); + } + } +} + int marker_register_lib(struct marker *markers_start, int markers_count) { struct lib *pl; @@ -1482,6 +1499,8 @@ int marker_register_lib(struct marker *markers_start, int markers_count) list_add(&pl->list, &libs); + new_markers(markers_start, markers_start + markers_count); + /* FIXME: update just the loaded lib */ lib_update_markers(); diff --git a/libmarkers/marker.h b/libmarkers/marker.h index aebe27a..62954e1 100644 --- a/libmarkers/marker.h +++ b/libmarkers/marker.h @@ -294,3 +294,5 @@ static void __attribute__((constructor)) __markers__init(void) \ } #endif + +void marker_set_new_marker_cb(void (*cb)(struct marker *)); diff --git a/libtracectl/tracectl.c b/libtracectl/tracectl.c index 2c64c10..ab62adf 100644 --- a/libtracectl/tracectl.c +++ b/libtracectl/tracectl.c @@ -291,10 +291,31 @@ static int init_signal_handler(void) return 0; } -static void __attribute__((constructor)) init() +static void auto_probe_connect(struct marker *m) { int result; + result = ltt_marker_connect(m->channel, m->name, "default"); + if(result) + ERR("ltt_marker_connect"); + + DBG("just auto connected marker %s %s to probe default", m->channel, m->name); +} + +static void __attribute__((constructor(101))) init0() +{ + DBG("UST_AUTOPROBE constructor"); + if(getenv("UST_AUTOPROBE")) { + marker_set_new_marker_cb(auto_probe_connect); + } +} + +static void __attribute__((constructor(1000))) init() +{ + int result; + + DBG("UST_TRACE constructor"); + mypid = getpid(); if(getenv("UST_TRACE")) { @@ -312,13 +333,8 @@ static void __attribute__((constructor)) init() /* Ensure markers are initialized */ init_markers(); - result = ltt_marker_connect("foo", "bar", "default"); - if(result) - ERR("ltt_marker_connect"); - - result = ltt_marker_connect("foo", "bar2", "default"); - if(result) - ERR("ltt_marker_connect"); + /* In case. */ + ltt_channels_register("ust"); result = ltt_trace_setup(trace_name); if(result < 0) { -- 2.34.1