From 6c734305a9bad126b38c1235c0ef629c3137769b Mon Sep 17 00:00:00 2001 From: Grzegorz Kossakowski Date: Thu, 26 Jul 2012 11:43:04 +0200 Subject: Fix `Instrumentation.getStatistics` method in partest. The previous implementation was wrong because it would always enable profiling after call to `Instrumenation.getStatistics` method. Now we are checking the profiling status and enable it again only when it was enabled before. Review by @phaller. --- .../scala/tools/partest/instrumented/Instrumentation.scala | 10 ++++++++-- src/partest/scala/tools/partest/instrumented/Profiler.java | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/partest/scala/tools/partest/instrumented/Instrumentation.scala b/src/partest/scala/tools/partest/instrumented/Instrumentation.scala index f29a7f90fd..3589df60f6 100644 --- a/src/partest/scala/tools/partest/instrumented/Instrumentation.scala +++ b/src/partest/scala/tools/partest/instrumented/Instrumentation.scala @@ -54,14 +54,20 @@ object Instrumentation { def startProfiling(): Unit = Profiler.startProfiling() def stopProfiling(): Unit = Profiler.stopProfiling() def resetProfiling(): Unit = Profiler.resetProfiling() + def isProfiling(): Boolean = Profiler.isProfiling() def getStatistics: Statistics = { - Profiler.stopProfiling() + val isProfiling = Profiler.isProfiling() + if (isProfiling) { + Profiler.stopProfiling() + } val stats = Profiler.getStatistics().asScala.toSeq.map { case (trace, count) => MethodCallTrace(trace.className, trace.methodName, trace.methodDescriptor) -> count.intValue } val res = Map(stats: _*) - Profiler.startProfiling() + if (isProfiling) { + Profiler.startProfiling() + } res } diff --git a/src/partest/scala/tools/partest/instrumented/Profiler.java b/src/partest/scala/tools/partest/instrumented/Profiler.java index 215bdbba08..0c87060794 100644 --- a/src/partest/scala/tools/partest/instrumented/Profiler.java +++ b/src/partest/scala/tools/partest/instrumented/Profiler.java @@ -55,6 +55,10 @@ public class Profiler { isProfiling = false; } + public static boolean isProfiling() { + return isProfiling; + } + public static void resetProfiling() { counts = new HashMap(); } -- cgit v1.2.3