new ltt-usertrace
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Thu, 9 Mar 2006 21:36:50 +0000 (21:36 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Thu, 9 Mar 2006 21:36:50 +0000 (21:36 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@1650 04897980-b3bd-0310-b5e0-8ef037075253

ltt-usertrace/ltt-usertrace-fast.c
ltt-usertrace/sample-thread-fast.c

index 863d4fa34bf627e31419329e7b4993548fcc1a2f..28a0ed0e404d2a80ab4af7eb499435ad513d73d0 100644 (file)
@@ -425,6 +425,14 @@ static void ltt_usertrace_fast_daemon(struct ltt_trace_info *shared_trace_info,
        snprintf(identifier_name, PATH_MAX-1,   "%lu.%lu.%llu",
                        traced_tid, traced_pid, get_cycles());
        snprintf(outfile_name, PATH_MAX-1,      "process-%s", identifier_name);
+
+       /* Wait for the first signal before creating files */
+       ret = sigsuspend(&oldset);
+       if(ret != -1) {
+               perror("LTT Error in sigsuspend\n");
+       }
+       if(traced_pid == 0 || parent_exited) goto dead_parent;
+
 #ifndef LTT_NULL_OUTPUT_TEST
        fd_process = creat(outfile_name, 0644);
 #else
@@ -440,11 +448,6 @@ static void ltt_usertrace_fast_daemon(struct ltt_trace_info *shared_trace_info,
 #endif //LTT_NULL_OUTPUT_TEST
        
        while(1) {
-               ret = sigsuspend(&oldset);
-               if(ret != -1) {
-                       perror("LTT Error in sigsuspend\n");
-               }
-               
                if(traced_pid == 0) break; /* parent died */
                if(parent_exited) break;
                dbg_printf("LTT Doing a buffer switch read. pid is : %lu\n", getpid());
@@ -452,8 +455,12 @@ static void ltt_usertrace_fast_daemon(struct ltt_trace_info *shared_trace_info,
                do {
                        ret = read_subbuffer(&shared_trace_info->channel.process, fd_process);
                } while(ret == 0);
+               ret = sigsuspend(&oldset);
+               if(ret != -1) {
+                       perror("LTT Error in sigsuspend\n");
+               }
        }
-
+dead_parent:
        /* The parent thread is dead and we have finished with the buffer */
 
        /* Buffer force switch (flush). Using FLUSH instead of ACTIVE because we know
index 69f1cf890c4770bb88e2297ede7bcf30fa1ec2b5..46ffbd12ff3f5b27df1e307763204cf6e37fd1c0 100644 (file)
 
 void *thr1(void *arg)
 {
+       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);
        }
        pthread_exit((void*)1);
 }
@@ -26,12 +26,12 @@ void *thr1(void *arg)
 /* Example of a _bad_ thread, which still works with the tracing */
 void *thr2(void *arg)
 {
+       int i;
        /* See ? no init */
        printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid());
-       sleep(1);
-       while(1) {
+
+       for(i=0; i<100000; i++) {
                trace_user_generic_string("Hello world! Have a nice day.");
-               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
@@ -48,9 +48,8 @@ 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);
This page took 0.025468 seconds and 4 git commands to generate.