X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=ltt-usertrace%2Fltt-usertrace-fast.c;h=f97e941e5e12b2d97e80c9abb52602ee393a656e;hb=f3db587c08181fce7dd92af34f2bdd73fb430703;hp=1a57db154686f910b1eff7b7b553bf3c825df985;hpb=0701d15032099822d418c7879427c0bdf21703be;p=lttv.git diff --git a/ltt-usertrace/ltt-usertrace-fast.c b/ltt-usertrace/ltt-usertrace-fast.c index 1a57db15..f97e941e 100644 --- a/ltt-usertrace/ltt-usertrace-fast.c +++ b/ltt-usertrace/ltt-usertrace-fast.c @@ -45,8 +45,7 @@ #define _GNU_SOURCE #define LTT_TRACE -#include -#include +#define LTT_TRACE_FAST #include #include #include @@ -56,24 +55,25 @@ #include #include #include -#include #include -#include #include #include +#include #include #include -#include - -#include -#include //for get_cycles() +#include +#include +#include +#include +#include +#include -_syscall0(pid_t,gettid) +#include -#include +#define gettid() syscall(__NR_gettid) #ifdef LTT_SHOW_DEBUG -#define dbg_printf(...) dbg_printf(__VA_ARGS__) +#define dbg_printf(...) printf(__VA_ARGS__) #else #define dbg_printf(...) #endif //LTT_SHOW_DEBUG @@ -108,6 +108,9 @@ static void ltt_usertrace_fast_cleanup(void *arg) static pid_t traced_pid = 0; static pid_t traced_tid = 0; static int parent_exited = 0; +static int fd_process = -1; +static char outfile_name[PATH_MAX]; +static char identifier_name[PATH_MAX]; /* signal handling */ static void handler_sigusr1(int signo) @@ -201,7 +204,7 @@ static void flush_buffer(struct ltt_buf *ltt_buf, enum force_switch_mode mode) index in the buffer being the one which will win this loop. */ /* If the buffer is not in overwrite mode, pushing the reader only happen if a sub-buffer is corrupted */ - if((SUBBUF_TRUNC(offset_end, ltt_buf) + if((SUBBUF_TRUNC(offset_end-1, ltt_buf) - SUBBUF_TRUNC(consumed_old, ltt_buf)) >= ltt_buf->alloc_size) consumed_new = SUBBUF_ALIGN(consumed_old, ltt_buf); @@ -283,6 +286,45 @@ static void flush_buffer(struct ltt_buf *ltt_buf, enum force_switch_mode mode) } + +static int open_output_files(void) +{ + int ret; + int fd; + /* Open output files */ + umask(00000); + ret = mkdir(LTT_USERTRACE_ROOT, 0777); + if(ret < 0 && errno != EEXIST) { + perror("LTT Error in creating output (mkdir)"); + exit(-1); + } + ret = chdir(LTT_USERTRACE_ROOT); + if(ret < 0) { + perror("LTT Error in creating output (chdir)"); + exit(-1); + } + 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); + +#ifndef LTT_NULL_OUTPUT_TEST + fd = creat(outfile_name, 0644); +#else + /* NULL test */ + ret = symlink("/dev/null", outfile_name); + if(ret < 0) { + perror("error in symlink"); + exit(-1); + } + fd = open(outfile_name, O_WRONLY); + if(fd_process < 0) { + perror("Error in open"); + exit(-1); + } +#endif //LTT_NULL_OUTPUT_TEST + return fd; +} + static inline int ltt_buffer_get(struct ltt_buf *ltt_buf, unsigned int *offset) { @@ -319,11 +361,14 @@ static inline int ltt_buffer_put(struct ltt_buf *ltt_buf, * It can also happen if this is a buffer we never got. */ return -EIO; } else { + if(traced_pid == 0 || parent_exited) return 0; + ret = sem_post(<t_buf->writer_sem); if(ret < 0) { printf("error in sem_post"); } } + return ret; } static int read_subbuffer(struct ltt_buf *ltt_buf, int fd) @@ -338,6 +383,9 @@ static int read_subbuffer(struct ltt_buf *ltt_buf, int fd) if(err != -EAGAIN) dbg_printf("LTT Reserving sub buffer failed\n"); goto get_error; } + if(fd_process == -1) { + fd_process = fd = open_output_files(); + } err = TEMP_FAILURE_RETRY(write(fd, ltt_buf->start @@ -375,13 +423,8 @@ get_error: static void ltt_usertrace_fast_daemon(struct ltt_trace_info *shared_trace_info, sigset_t oldset, pid_t l_traced_pid, pthread_t l_traced_tid) { - sigset_t set; struct sigaction act; int ret; - int fd_process; - char outfile_name[PATH_MAX]; - char identifier_name[PATH_MAX]; - traced_pid = l_traced_pid; traced_tid = l_traced_tid; @@ -409,41 +452,11 @@ static void ltt_usertrace_fast_daemon(struct ltt_trace_info *shared_trace_info, alarm(3); - /* Open output files */ - umask(00000); - ret = mkdir(LTT_USERTRACE_ROOT, 0777); - if(ret < 0 && errno != EEXIST) { - perror("LTT Error in creating output (mkdir)"); - exit(-1); - } - ret = chdir(LTT_USERTRACE_ROOT); - if(ret < 0) { - perror("LTT Error in creating output (chdir)"); - exit(-1); - } - 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); -#ifndef LTT_NULL_OUTPUT_TEST - fd_process = creat(outfile_name, 0644); -#else - /* NULL test */ - ret = symlink("/dev/null", outfile_name); - if(ret < 0) { - perror("error in symlink"); - } - fd_process = open(outfile_name, O_WRONLY); - if(fd_process < 0) { - perror("Error in open"); - } -#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,7 +465,6 @@ static void ltt_usertrace_fast_daemon(struct ltt_trace_info *shared_trace_info, ret = read_subbuffer(&shared_trace_info->channel.process, fd_process); } while(ret == 0); } - /* The parent thread is dead and we have finished with the buffer */ /* Buffer force switch (flush). Using FLUSH instead of ACTIVE because we know @@ -462,8 +474,8 @@ static void ltt_usertrace_fast_daemon(struct ltt_trace_info *shared_trace_info, ret = read_subbuffer(&shared_trace_info->channel.process, fd_process); } while(ret == 0); - - close(fd_process); + if(fd_process != -1) + close(fd_process); ret = sem_destroy(&shared_trace_info->channel.process.writer_sem); if(ret < 0) { @@ -520,7 +532,6 @@ void ltt_rw_init(void) dbg_printf("LTT Error in sigfillset\n"); } - ret = pthread_sigmask(SIG_BLOCK, &set, &oldset); if(ret) { dbg_printf("LTT Error in pthread_sigmask\n");