X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=ltt-usertrace%2Fsample-thread-fast.c;h=46ffbd12ff3f5b27df1e307763204cf6e37fd1c0;hb=70185ef663a3cd2de43af410d9578dbac997ff04;hp=d98c86f5487fdc91c55b5a87ca5f923de2955ac7;hpb=7d33c02d3f64dcfe7e3c8d5bdd66bfb375ba85c8;p=lttv.git diff --git a/ltt-usertrace/sample-thread-fast.c b/ltt-usertrace/sample-thread-fast.c index d98c86f5..46ffbd12 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()); + int i; + 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) { + for(i=0; i<100000; i++) { 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()); - sleep(1); - while(1) { + int i; + /* See ? no init */ + printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid()); + + for(i=0; i<100000; i++) { trace_user_generic_string("Hello world! Have a nice day."); - sleep(2); - } - return ((void*)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); } @@ -41,22 +48,21 @@ int main() void *tret; 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("It will stop automatically.\n"); + printf("See the result file in /tmp/ltt-usertrace.\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; }