Commits

Jonathan Gilbert committed 2b27960

modified profiling

Comments (0)

Files changed (6)

mangler/src/main/scala/org/trillica/mangley/adapter/ContextCallSwitcher.scala

 
     override def visitMethod(access: Int, name: String, desc: String, signature: String, exceptions: Array[String]) = {
         new MethodAdapter(super.visitMethod(access, name, desc, signature, exceptions)) {
-            var stored: () => Unit = null
 
-            def maybePop() = {
-                if (stored != null)
-                    {
-                        stored()
-                        stored = null;
-                    }
-            }
-
-            override def visitMaxs(maxStack: Int, maxLocals: Int) = {
-                maybePop()
-                super.visitMaxs(maxStack: Int, maxLocals: Int)
-            }
-
-            override def visitLineNumber(line: Int, start: Label) = {
-                maybePop()
-                super.visitLineNumber(line: Int, start: Label)
-            }
-
-            override def visitLocalVariable(name: String, desc: String, signature: String, start: Label, end: Label, index: Int) = {
-                maybePop()
-                super.visitLocalVariable(name: String, desc: String, signature: String, start: Label, end: Label, index: Int)
-            }
-
-            override def visitTryCatchBlock(start: Label, end: Label, handler: Label, `type` : String) = {
-                maybePop()
-                super.visitTryCatchBlock(start: Label, end: Label, handler: Label, `type` : String)
-            }
-
-            override def visitMultiANewArrayInsn(desc: String, dims: Int) = {
-                maybePop()
-                super.visitMultiANewArrayInsn(desc: String, dims: Int)
-            }
-
-            override def visitLookupSwitchInsn(dflt: Label, keys: Array[Int], labels: Array[Label]) = {
-                maybePop()
-                super.visitLookupSwitchInsn(dflt: Label, keys: Array[Int], labels: Array[Label])
-            }
-
-            override def visitTableSwitchInsn(min: Int, max: Int, dflt: Label, labels: Array[Label]) = {
-                maybePop()
-                super.visitTableSwitchInsn(min: Int, max: Int, dflt: Label, labels: Array[Label])
-            }
-
-            override def visitIincInsn(`var` : Int, increment: Int) = {
-                maybePop()
-                super.visitIincInsn(`var` : Int, increment: Int)
-            }
-
-            override def visitLdcInsn(cst: AnyRef) = {
-                maybePop()
-                super.visitLdcInsn(cst: AnyRef)
-            }
-
-            override def visitLabel(label: Label) = {
-                maybePop()
-                super.visitLabel(label: Label)
-            }
-
-            override def visitJumpInsn(opcode: Int, label: Label) = {
-                maybePop()
-                super.visitJumpInsn(opcode: Int, label: Label)
-            }
-
-            override def visitFieldInsn(opcode: Int, owner: String, name: String, desc: String) = {
-                maybePop()
-                super.visitFieldInsn(opcode: Int, owner: String, name: String, desc: String)
-            }
-
-            override def visitTypeInsn(opcode: Int, `type` : String) = {
-                maybePop()
-                super.visitTypeInsn(opcode: Int, `type` : String)
-            }
-
-            override def visitVarInsn(opcode: Int, `var` : Int) = {
-                maybePop()
-                super.visitVarInsn(opcode: Int, `var` : Int)
-            }
-
-            override def visitIntInsn(opcode: Int, operand: Int) = {
-                maybePop()
-                super.visitIntInsn(opcode: Int, operand: Int)
-            }
-
-            override def visitInsn(opcode: Int) = {
-                maybePop()
-                super.visitInsn(opcode: Int)
-            }
 
             override def visitMethodInsn(opcode: Int, owner: String, name: String, desc: String) = {
 
                 if (!owner.equals(contextType.getInternalName()) && !owner.equals(contextType.getInternalName() + "$"))
                     {
-                        maybePop()
-
-                        stored = () => {
-                            super.visitMethodInsn(opcode: Int, owner: String, name: String, desc: String)
-                        }
+                        super.visitMethodInsn(opcode: Int, owner: String, name: String, desc: String)
                     }
                 else
                     {
-                        stored == null;
-                        super.visitLdcInsn(ManglingContext.current().methodId)
+                      super.visitIntInsn(Opcodes.BIPUSH, ManglingContext.current().methodId)
+                      //super.visitLdcInsn(ManglingContext.current().methodId)
                     }
 
             }
-
-
-            override def visitEnd = {
-                maybePop()
-            }
         }
     }
 }
             <plugin>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <configuration>
-                    <argLine>-javaagent:${basedir}/../agent/target/agent-${project.version}-all.jar</argLine>
+                    <argLine>-javaagent:${basedir}/../agent/target/agent-${project.version}-all.jar  -verbose:class -Dmangley.dump.classfile=true</argLine>
                     <useSystemClassLoader>true</useSystemClassLoader>
                 </configuration>
             </plugin>

profiler/src/main/java/org/trillica/mangley/profiler/ProfileCall.java

+package org.trillica.mangley.profiler;
+
+import org.trillica.mangley.MangleContext;
+import org.trillica.mangley.builder.StaticCall;
+
+public class ProfileCall implements StaticCall
+{
+    public void call()
+    {
+        Profiler.recordInvocation(MangleContext.methodLocation());
+    }
+}

profiler/src/main/scala/org/trillica/mangley/profiler/Profiler.scala

         val profilePackage = System.getProperty("mangley.profile.package")
         Mangler.applyConfig(ClassFilterConfig.byPackage(profilePackage, new JavaWrapper {
             override def wrap(cv: ClassVisitor): ClassVisitor = {
-                return OperationBuilder.create(cv).injectCode(new StaticCall {
-                    override def call: Unit = {
-                        Profiler.recordInvocation(MangleContext.methodLocation)
-                    }
-                }).withLogging.build
+                return OperationBuilder.create(cv).injectCode(new ProfileCall).withLogging.build
             }
         }))
     }

profiler/src/test/java/org/trillica/mangley/profiler/simple/SimpleProfileTest.java

         runner.doStuff();
         Assert.assertEquals(2, Profiler.invocationCount(methodId));
     }
+
+    class Code {
+        public void before(){
+            Profiler.recordInvocation(MangleContext.methodLocation());
+        }
+        
+        public void after(){
+            Profiler.recordInvocation(17);
+        }
+    }
 }
             <plugin>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <configuration>
-                    <argLine>-javaagent:${basedir}/../agent/target/agent-${project.version}-all.jar -verbose:class -Dmangley.dump.classfile=true</argLine>
+                    <argLine>-javaagent:${basedir}/../agent/target/agent-${project.version}-all.jar</argLine>
                     <useSystemClassLoader>true</useSystemClassLoader>
                 </configuration>
             </plugin>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.