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
$(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
-LTTng usertrace generic package
+LTTng usertrace package
Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
March 2006
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_!
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.
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;
#include <stdlib.h>
#define LTT_TRACE
-//this one is a non blocking sample (not #define LTT_BLOCKING 1)
+#define LTT_TRACE_FAST
#include <ltt/ltt-facility-user_generic.h>
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);
}
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;
}
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);
}
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;
}
{
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.");