From 9e04e2365a7210f7e671137d8f70e475688b0885 Mon Sep 17 00:00:00 2001 From: Grzegorz Kossakowski Date: Thu, 26 Jul 2012 11:40:13 +0200 Subject: Instrument all classes in `instrumented` package. Extend instrumenting infrastructure to instrument classes in `instrumented` package. This is useful because very often you need to put your classes into non-empty package. E.g. inliner doesn't work properly with empty package at the moment so in order to test any behaviour we need to put classes in some other package that is instrumented. Added testing code for that to instrumentation test-case. Review by @phaller. --- src/partest/scala/tools/partest/javaagent/ASMTransformer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/partest/scala/tools/partest/javaagent/ASMTransformer.java b/src/partest/scala/tools/partest/javaagent/ASMTransformer.java index 643c683002..09cd485d6b 100644 --- a/src/partest/scala/tools/partest/javaagent/ASMTransformer.java +++ b/src/partest/scala/tools/partest/javaagent/ASMTransformer.java @@ -21,7 +21,9 @@ public class ASMTransformer implements ClassFileTransformer { // we instrument all classes from empty package (!className.contains("/") || // we instrument all classes from scala package - className.startsWith("scala/")); + className.startsWith("scala/") || + // we instrument all classes from `instrumented` package + className.startsWith("instrumented/")); } public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) { -- cgit v1.2.3 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(-) (limited to 'src') 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