[sheepdog] [PATCH] trace: call tracer->exit only when the paird trace->enter was called

MORITA Kazutaka morita.kazutaka at gmail.com
Fri Aug 30 16:06:05 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

This fixes the result of graph tracer when we use other tracers
(thread_checker and/or loop_checker) at the same time.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/trace/trace.c |   14 ++++++++++++--
 sheep/trace/trace.h |    1 +
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/sheep/trace/trace.c b/sheep/trace/trace.c
index 9e2e94c..84b1849 100644
--- a/sheep/trace/trace.c
+++ b/sheep/trace/trace.c
@@ -115,8 +115,10 @@ void trace_function_enter(unsigned long ip, unsigned long *ret_addr)
 	caller = trace_lookup_ip(ip);
 
 	list_for_each_entry(tracer, &tracers, list) {
-		if (tracer->enter != NULL && uatomic_is_true(&tracer->enabled))
+		if (tracer->enter && uatomic_is_true(&tracer->enabled)) {
+			tracer->stack_depth++;
 			tracer->enter(caller, ret_stack_index);
+		}
 	}
 
 	trace_ret_stack[ret_stack_index].caller = caller;
@@ -139,9 +141,17 @@ unsigned long trace_function_exit(void)
 	ret_stack_index--;
 
 	list_for_each_entry(tracer, &tracers, list) {
-		if (tracer->exit != NULL && uatomic_is_true(&tracer->enabled))
+		if (tracer->exit && uatomic_is_true(&tracer->enabled)) {
+			if (tracer->stack_depth == 0)
+				/*
+				 * The paird trace_function_enter() was not
+				 * called with this tracer.
+				 */
+				continue;
+			tracer->stack_depth--;
 			tracer->exit(trace_ret_stack[ret_stack_index].caller,
 				     ret_stack_index);
+		}
 	}
 
 	in_trace = false;
diff --git a/sheep/trace/trace.h b/sheep/trace/trace.h
index a50fa33..ea72733 100644
--- a/sheep/trace/trace.h
+++ b/sheep/trace/trace.h
@@ -22,6 +22,7 @@ struct tracer {
 
 	/* internal use only */
 	uatomic_bool enabled;
+	int stack_depth;
 	struct list_node list;
 };
 
-- 
1.7.9.5




More information about the sheepdog mailing list