From 141274aac0c9dd34c0dac660d381a959a2ca5e15 Mon Sep 17 00:00:00 2001 From: compudj Date: Thu, 9 Mar 2006 21:31:33 +0000 Subject: [PATCH] new ltt-usertrace git-svn-id: http://ltt.polymtl.ca/svn@1649 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt-usertrace/Makefile | 9 +++-- ltt-usertrace/README | 20 ++++++----- ltt-usertrace/sample-printf.c | 6 ++-- ltt-usertrace/sample-thread-fast.c | 55 +++++++++++++++++------------- ltt-usertrace/sample-thread-slow.c | 46 ++++++++++++------------- ltt-usertrace/sample.c | 6 ++-- 6 files changed, 76 insertions(+), 66 deletions(-) diff --git a/ltt-usertrace/Makefile b/ltt-usertrace/Makefile index c3daad73..aebde690 100644 --- a/ltt-usertrace/Makefile +++ b/ltt-usertrace/Makefile @@ -4,8 +4,7 @@ INCLUDE_DIR=/usr/include LIB_DIR=/usr/lib RANLIB=ranlib -CFLAGS=-I. -O3 -LDFLAGS=-L. +CFLAGS=-I. -O3 -L. #For testing lib ltt-usertrace-fast #CFLAGS+=-DLTT_SUBBUF_SIZE_CPU=134217728 @@ -22,19 +21,19 @@ sample: sample.c ltt-facility-loader-user_generic.c $(CC) $(CFLAGS) -o $@ $^ sample-highspeed: sample-highspeed.c ltt-facility-loader-user_generic.c - $(CC) $(CFLAGS) -L. -lltt-usertrace-fast -o $@ $^ + $(CC) $(CFLAGS) -lltt-usertrace-fast -o $@ $^ sample-printf: sample-printf.c ltt-facility-loader-user_generic.c $(CC) $(CFLAGS) -o $@ $^ sample-instrument-fct: sample-instrument-fct.c - $(CC) $(CFLAGS) -L. -g -finstrument-functions -lltt-instrument-functions -o $@ $^ + $(CC) $(CFLAGS) -g -finstrument-functions -lltt-instrument-functions -o $@ $^ sample-thread-slow: sample-thread-slow.c ltt-facility-loader-user_generic.c $(CC) $(CFLAGS) -lpthread -o $@ $^ sample-thread-fast: sample-thread-fast.c ltt-facility-loader-user_generic.c - $(CC) $(CFLAGS) -lpthread -o $@ $^ + $(CC) $(CFLAGS) -lpthread -lltt-usertrace-fast -o $@ $^ #LIBRAIRIES diff --git a/ltt-usertrace/README b/ltt-usertrace/README index b9ac1fb4..4bdbf293 100644 --- a/ltt-usertrace/README +++ b/ltt-usertrace/README @@ -1,5 +1,5 @@ -LTTng usertrace generic package +LTTng usertrace package Mathieu Desnoyers March 2006 @@ -10,8 +10,8 @@ short quickstart guide of it. Here are the currently supported architectures : x86 -(please add the ltt_* system calls to other architectures as you need them : it -will work magically) +(please add the ltt_trace_generic and ltt_register_generic system calls to +other architectures as you need them : it will work magically) * Compile your kernel with the latest LTTng patch. Make sure the option "Allow tracing from userspace" is _active_! @@ -19,19 +19,23 @@ will work magically) setup a working tracer and viewer. See the genevent installation step : it is required for method #2 below. -* Extract the latest usertrace-generic archive : +* Extract the latest ltt-usertrace archive : su cd /usr/src -wget http://ltt.polymtl.ca/packages/usertrace-generic-x.x.tar.gz -gzip -cd usertrace-generic-x.x.tar.gz | tar xvof - +wget http://ltt.polymtl.ca/packages/ltt-usertrace-x.x.tar.gz +gzip -cd ltt-usertrace-x.x.tar.gz | tar xvof - -* Build the sample programs and install the headers into your system : +* Build the sample programs and install the headers and librairies into your +system : su cd /usr/src/usertrace-generic make make install -* There are two ways to trace information from your application : +Feel free to look at the sample programs and the Makefile : they demonstrate +very well the features of the usertrace package and how to use them. + +* There are three ways to trace information from your application : 1) Easy way, but slow (printf style) See sample-printf.c for code example. diff --git a/ltt-usertrace/sample-printf.c b/ltt-usertrace/sample-printf.c index 9b2292a7..a513e3b6 100644 --- a/ltt-usertrace/sample-printf.c +++ b/ltt-usertrace/sample-printf.c @@ -13,9 +13,9 @@ int main(int argc, char **argv) { printf("Will trace a printf of an incrementing counter.\n"); - printf("Abort with CTRL-C.\n"); - printf("No file is created with this example : it logs through a kernel\n"); - printf("system call. See the LTTng lttctl command to start tracing.\n"); + printf("Abort with CTRL-C.\n"); + printf("No file is created with this example : it logs through a kernel\n"); + printf("system call. See the LTTng lttctl command to start tracing.\n"); unsigned int count = 0; diff --git a/ltt-usertrace/sample-thread-fast.c b/ltt-usertrace/sample-thread-fast.c index d98c86f5..69f1cf89 100644 --- a/ltt-usertrace/sample-thread-fast.c +++ b/ltt-usertrace/sample-thread-fast.c @@ -5,32 +5,39 @@ #include #define LTT_TRACE -//this one is a non blocking sample (not #define LTT_BLOCKING 1) +#define LTT_TRACE_FAST #include void *thr1(void *arg) { - printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid()); + ltt_thread_init(); /* This init is not required : it will be done + automatically anyways at the first tracing call site */ + printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid()); - while(1) { + while(1) { trace_user_generic_string("Hello world! Have a nice day."); sleep(2); } - - return ((void*)1); - + pthread_exit((void*)1); } + +/* Example of a _bad_ thread, which still works with the tracing */ void *thr2(void *arg) { - printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid()); + /* See ? no init */ + printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid()); sleep(1); - while(1) { + while(1) { trace_user_generic_string("Hello world! Have a nice day."); - sleep(2); - } - return ((void*)2); + sleep(2); + } + /* This thread is a bad citizen : returning like this will cause its cancel + * routines not to be executed. This is still detected by the tracer, but only + * when the complete process dies. This is not recommended if you create a + * huge amount of threads */ + return ((void*)2); } @@ -42,21 +49,21 @@ int main() printf("Will trace the following string : Hello world! Have a nice day.\n"); printf("Press CTRL-C to stop.\n"); - printf("No file is created with this example : it logs through a kernel\n"); - printf("system call. See the LTTng lttctl command to start tracing.\n\n"); + printf("No file is created with this example : it logs through a kernel\n"); + printf("system call. See the LTTng lttctl command to start tracing.\n\n"); - printf("thread main, thread id : %lu, pid %lu\n", pthread_self(), getpid()); - err = pthread_create(&tid1, NULL, thr1, NULL); - if(err!=0) exit(1); + printf("thread main, thread id : %lu, pid %lu\n", pthread_self(), getpid()); + err = pthread_create(&tid1, NULL, thr1, NULL); + if(err!=0) exit(1); - err = pthread_create(&tid2, NULL, thr2, NULL); - if(err!=0) exit(1); + err = pthread_create(&tid2, NULL, thr2, NULL); + if(err!=0) exit(1); - err = pthread_join(tid1, &tret); - if(err!= 0) exit(1); + err = pthread_join(tid1, &tret); + if(err!= 0) exit(1); - err = pthread_join(tid2, &tret); - if(err!= 0) exit(1); - - return 0; + err = pthread_join(tid2, &tret); + if(err!= 0) exit(1); + + return 0; } diff --git a/ltt-usertrace/sample-thread-slow.c b/ltt-usertrace/sample-thread-slow.c index d98c86f5..343332f7 100644 --- a/ltt-usertrace/sample-thread-slow.c +++ b/ltt-usertrace/sample-thread-slow.c @@ -11,26 +11,26 @@ void *thr1(void *arg) { - printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid()); + printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid()); - while(1) { + while(1) { trace_user_generic_string("Hello world! Have a nice day."); sleep(2); } - - return ((void*)1); - + pthread_exit((void*)1); } + +/* Example of a _bad_ thread, which still works with the tracing */ void *thr2(void *arg) { - printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid()); + printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid()); sleep(1); - while(1) { + while(1) { trace_user_generic_string("Hello world! Have a nice day."); - sleep(2); - } - return ((void*)2); + sleep(2); + } + return ((void*)2); } @@ -42,21 +42,21 @@ int main() printf("Will trace the following string : Hello world! Have a nice day.\n"); printf("Press CTRL-C to stop.\n"); - printf("No file is created with this example : it logs through a kernel\n"); - printf("system call. See the LTTng lttctl command to start tracing.\n\n"); + printf("No file is created with this example : it logs through a kernel\n"); + printf("system call. See the LTTng lttctl command to start tracing.\n\n"); - printf("thread main, thread id : %lu, pid %lu\n", pthread_self(), getpid()); - err = pthread_create(&tid1, NULL, thr1, NULL); - if(err!=0) exit(1); + printf("thread main, thread id : %lu, pid %lu\n", pthread_self(), getpid()); + err = pthread_create(&tid1, NULL, thr1, NULL); + if(err!=0) exit(1); - err = pthread_create(&tid2, NULL, thr2, NULL); - if(err!=0) exit(1); + err = pthread_create(&tid2, NULL, thr2, NULL); + if(err!=0) exit(1); - err = pthread_join(tid1, &tret); - if(err!= 0) exit(1); + err = pthread_join(tid1, &tret); + if(err!= 0) exit(1); - err = pthread_join(tid2, &tret); - if(err!= 0) exit(1); - - return 0; + err = pthread_join(tid2, &tret); + if(err!= 0) exit(1); + + return 0; } diff --git a/ltt-usertrace/sample.c b/ltt-usertrace/sample.c index b5ef4492..70bb8a2e 100644 --- a/ltt-usertrace/sample.c +++ b/ltt-usertrace/sample.c @@ -11,9 +11,9 @@ int main(int argc, char **argv) { printf("Will trace the following string : \"Hello world! Have a nice day.\"\n"); printf("every second.\n"); - printf("Abort with CTRL-C.\n"); - printf("No file is created with this example : it logs through a kernel\n"); - printf("system call. See the LTTng lttctl command to start tracing.\n"); + printf("Abort with CTRL-C.\n"); + printf("No file is created with this example : it logs through a kernel\n"); + printf("system call. See the LTTng lttctl command to start tracing.\n"); while(1) { trace_user_generic_string("Hello world! Have a nice day."); -- 2.34.1