Author: bpoussin Date: 2011-08-26 18:01:12 +0200 (Fri, 26 Aug 2011) New Revision: 2195 Url: http://nuiton.org/repositories/revision/nuiton-utils/2195 Log: Evolution #1712: Add information of caller of method with number of call - call stack must be per thread to prevent mix Modified: trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java Modified: trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java =================================================================== --- trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java 2011-08-26 15:28:26 UTC (rev 2194) +++ trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java 2011-08-26 16:01:12 UTC (rev 2195) @@ -123,9 +123,22 @@ protected Map<Method, Caller<Method>> callers = new HashMap<Method, Caller<Method>>(); - /** array : [nest method call, start time, start time with child] */ - protected Stack<Call> callStack = new Stack<Call>(); + /** + * array : [nest method call, start time, start time with child] + * + * On ne melange pas les stack entre les threads, sinon les resultats + * ne veulent plus rien dire car toutes les methodes des threads sont + * melangees + */ + protected static final ThreadLocal<Stack<Call>> callStack = new ThreadLocal<Stack<Call>> () { + @Override + protected Stack<Call> initialValue() { + Stack<Call> result = new Stack<Call>(); + return result; + } + }; + public NuitonTrace() { instances.add(this); } @@ -171,9 +184,7 @@ long current = System.nanoTime(); Call stackItem = new Call(method, 0, current, current); - callStack.push(stackItem); - - + callStack.get().push(stackItem); } @AfterThrowing("executeMethod() && !within(org.nuiton.profiling.NuitonTrace.*)") @@ -188,6 +199,8 @@ long current = System.nanoTime(); + Stack<Call> callStack = this.callStack.get(); + if (callStack.isEmpty()) { // log.warn("Empty stack in afterExecute for method " + method.getName()); } else { @@ -252,6 +265,7 @@ for (NuitonTrace trace : instances) { for (Method method : trace.statistics.keySet()) { Statistic stat = trace.getStatistics(method); + Caller<Method> caller = trace.getCallers(method); long meanTime = stat.timeTotal / stat.call; result.append(method) .append(";").append(stat.call) @@ -262,11 +276,14 @@ .append(";").append(DurationFormatUtils.formatDuration(stat.timeTotal / 1000000, "s'.'S")) .append(";").append(stat.callNestMethod) .append(";").append(DurationFormatUtils.formatDuration(stat.timeTotalNestMethod / 1000000, "s'.'S")) - .append(";").append(trace.getCallers(method)) + .append(";").append(caller) .append("\n"); } + trace.statistics.clear(); + trace.callers.clear(); } - instances.clear(); + // Poussin 20110826 on ne vide pas les instances mais les stats +// instances.clear(); return result.toString(); } @@ -291,8 +308,11 @@ .append("\n"); } result.append("--------------------\n"); + trace.statistics.clear(); + trace.callers.clear(); } - instances.clear(); + // Poussin 20110826 on ne vide pas les instances mais les stats +// instances.clear(); return result.toString(); }
participants (1)
-
bpoussin@users.nuiton.org