From: Liu Yuan <[email protected]> In some unusual corner cases, pop_return_trace() will be called first, to avoid negative index, we start at the middle of array. On the buffer reader side, we can minus TRACE_RET_STACK_LEN / 2 to identify those negative index which are actually uselss because we don't store their entry time.
Signed-off-by: Liu Yuan <[email protected]> --- collie/debug.c | 8 +++++++- include/sheep.h | 2 ++ sheep/trace/graph.c | 11 +++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/collie/debug.c b/collie/debug.c index 250a131..c40d164 100644 --- a/collie/debug.c +++ b/collie/debug.c @@ -53,6 +53,11 @@ static inline void print_finale(struct trace_graph_item *item) static void print_trace_item(struct trace_graph_item *item) { + item->depth -= TRACE_RET_STACK_LEN / 2; + /* Ignore the item that doesn't have entry time stored */ + if (item->depth < 0) + return; + print_thread_name(item); print_time(item); print_finale(item); @@ -180,7 +185,8 @@ static int trace_cat(int argc, char **argv) return EXIT_SYSFAIL; } - map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + map = mmap(NULL, st.st_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE, fd, 0); close(fd); if (map == MAP_FAILED) { fprintf(stderr, "%m\n"); diff --git a/include/sheep.h b/include/sheep.h index a2d0cd9..36de58b 100644 --- a/include/sheep.h +++ b/include/sheep.h @@ -47,6 +47,8 @@ struct vdi_copy { #define TRACE_FNAME_LEN 36 #define TRACE_THREAD_LEN 20 +#define TRACE_RET_STACK_LEN 100 + struct trace_graph_item { char tname[TRACE_THREAD_LEN]; int type; diff --git a/sheep/trace/graph.c b/sheep/trace/graph.c index ab3a6c3..e39b801 100644 --- a/sheep/trace/graph.c +++ b/sheep/trace/graph.c @@ -19,12 +19,19 @@ #include "logger.h" #include "util.h" -static __thread int ret_stack_index; +/* + * In some unusual corner cases, pop_return_trace() will be called first, to + * avoid negative index, we start at the middle of array. On the buffer reader + * side, we can minus TRACE_RET_STACK_LEN / 2 to identify those negative index + * which are actually uselss because we don't store their entry time. + */ +static __thread int ret_stack_index = TRACE_RET_STACK_LEN / 2; + static __thread struct trace_ret_stack { unsigned long ret; unsigned long func; unsigned long long entry_time; -} trace_ret_stack[100]; /* FIXME: consider stack overrun */ +} trace_ret_stack[TRACE_RET_STACK_LEN]; /* FIXME: consider stack overrun */ static void push_return_trace(unsigned long ret, unsigned long long etime, unsigned long func, int *depth) -- 1.7.12.84.gefa6462 -- sheepdog mailing list [email protected] http://lists.wpkg.org/mailman/listinfo/sheepdog
