[jboss-cvs] JBoss Profiler SVN: r491 - in branches/JBossProfiler2/src: main/org/jboss/profiler/client and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 29 07:36:23 EDT 2008


Author: jesper.pedersen
Date: 2008-10-29 07:36:23 -0400 (Wed, 29 Oct 2008)
New Revision: 491

Modified:
   branches/JBossProfiler2/src/main/org/jboss/profiler/agent/JavassistTransformer.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/agent/NopProfilerThreadImpl.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ProfilerThread.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ProfilerThreadImpl.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java
   branches/JBossProfiler2/src/test/java/org/jboss/profiler/test/Test.java
Log:
Add support for wait time (Javassist)

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/agent/JavassistTransformer.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/agent/JavassistTransformer.java	2008-10-24 13:19:58 UTC (rev 490)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/agent/JavassistTransformer.java	2008-10-29 11:36:23 UTC (rev 491)
@@ -28,10 +28,13 @@
 
 import javassist.CannotCompileException;
 import javassist.ClassPool;
+import javassist.CtBehavior;
 import javassist.CtClass;
 import javassist.CtConstructor;
 import javassist.CtMethod;
 import javassist.Modifier;
+import javassist.expr.ExprEditor;
+import javassist.expr.MethodCall;
 
 /**
  * Implements the Javssist based transformer
@@ -47,6 +50,8 @@
    */
   public JavassistTransformer() {
     pool = ClassPool.getDefault();
+
+    //setup();
   }
 
   /**
@@ -131,6 +136,8 @@
         constructor.insertAfter("{ " +
                                 "org.jboss.profiler.agent.Profiler.getProfilerThread(Thread.currentThread()).end(\"" + className + "\", \"" + constructor.getLongName() + "\");" +
                                 " }", true);
+
+        setup(constructor);
       }
     }
   }
@@ -171,17 +178,39 @@
       method.insertAfter("{ " +
                          "org.jboss.profiler.agent.Profiler.getProfilerThread(Thread.currentThread()).end(\"" + className + "\", \"" + method.getLongName() + "\");" +
                          " }", true);
+
+      setup(method);
     }
+  }
 
-    /*
-      TODO
+  /**
+   * Setup the beginWait/endWait methods
+   * @param ctb The behavior
+   */
+  private void setup(CtBehavior ctb) {
+    try {
+      final String code = "{org.jboss.profiler.agent.Profiler.getProfilerThread(Thread.currentThread()).beginWait(); " +
+        "$_ = $proceed($$); " +
+        "org.jboss.profiler.agent.Profiler.getProfilerThread(Thread.currentThread()).endWait();}";
 
-      Implement support for beginWait/endWait for the following methods:
+      ctb.instrument(new ExprEditor() {
+          public void edit(MethodCall m) throws CannotCompileException {
+            if ("java.lang.Object".equals(m.getClassName())) {
+              if ("wait".equals(m.getMethodName())) {
+                m.replace(code);
+              }
+            } else if ("java.lang.Thread".equals(m.getClassName())) {
+              if ("join".equals(m.getMethodName()) ||
+                  "sleep".equals(m.getMethodName()) ||
+                  "yield".equals(m.getMethodName())) {
+                m.replace(code);
+              }
+            }
+          }
+        });
 
-      java.lang.Object#wait()
-      java.lang.Thread#join()
-      java.lang.Thread#sleep()
-      java.lang.Thread#yield()
-    */
+    } catch(Exception e) {
+      e.printStackTrace(System.err);
+    }
   }
 }

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/agent/NopProfilerThreadImpl.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/agent/NopProfilerThreadImpl.java	2008-10-24 13:19:58 UTC (rev 490)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/agent/NopProfilerThreadImpl.java	2008-10-29 11:36:23 UTC (rev 491)
@@ -52,18 +52,14 @@
   
   /**
    * Register start wait time for a method
-   * @param className The class name
-   * @param methodName The method name
    */
-  public void beginWait(String className, String methodName) {
+  public void beginWait() {
   }
   
   /**
    * Register end wait time for a method
-   * @param className The class name
-   * @param methodName The method name
    */
-  public void endWait(String className, String methodName) {
+  public void endWait() {
   }
   
   /**

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ProfilerThread.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ProfilerThread.java	2008-10-24 13:19:58 UTC (rev 490)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ProfilerThread.java	2008-10-29 11:36:23 UTC (rev 491)
@@ -43,17 +43,13 @@
   
   /**
    * Register start wait time for a method
-   * @param className The class name
-   * @param methodName The method name
    */
-  public void beginWait(String className, String methodName);
+  public void beginWait();
   
   /**
    * Register end wait time for a method
-   * @param className The class name
-   * @param methodName The method name
    */
-  public void endWait(String className, String methodName);
+  public void endWait();
   
   /**
    * Class allocation

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ProfilerThreadImpl.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ProfilerThreadImpl.java	2008-10-24 13:19:58 UTC (rev 490)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ProfilerThreadImpl.java	2008-10-29 11:36:23 UTC (rev 491)
@@ -175,15 +175,13 @@
   
   /**
    * Register start wait time for a method
-   * @param className The class name
-   * @param methodName The method name
    */
-  public void beginWait(String className, String methodName) {
+  public void beginWait() {
     if (!Agent.isEnabled() || !Agent.isCPU() || !Profiler.isRunning()) {
       return;
     }
 
-    FrameInfo fi = findFrame(className, methodName);
+    FrameInfo fi = activeFrame;
       
     if (fi == null) {
       return;
@@ -194,17 +192,15 @@
   
   /**
    * Register end wait time for a method
-   * @param className The class name
-   * @param methodName The method name
    */
-  public void endWait(String className, String methodName) {
+  public void endWait() {
     long start = System.nanoTime();
     
     if (!Agent.isEnabled() || !Agent.isCPU() || !Profiler.isRunning()) {
       return;
     }
 
-    FrameInfo fi = findFrame(className, methodName);
+    FrameInfo fi = activeFrame;
       
     if (fi == null) {
       return;

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java	2008-10-24 13:19:58 UTC (rev 490)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java	2008-10-29 11:36:23 UTC (rev 491)
@@ -636,7 +636,7 @@
     DecimalFormat df = new DecimalFormat("#0.00");
     
     bw.write("Total time: " + df.format(tci.getTotalTime()) + " ms" + NEW_LINE);
-    //bw.write(" Wait time: " + df.format(tci.getWaitTime()) + " ms" + NEW_LINE);
+    bw.write(" Wait time: " + df.format(tci.getWaitTime()) + " ms" + NEW_LINE);
 
     if (allocs != null && allocs.size() > 0) {
       long alloc = 0;

Modified: branches/JBossProfiler2/src/test/java/org/jboss/profiler/test/Test.java
===================================================================
--- branches/JBossProfiler2/src/test/java/org/jboss/profiler/test/Test.java	2008-10-24 13:19:58 UTC (rev 490)
+++ branches/JBossProfiler2/src/test/java/org/jboss/profiler/test/Test.java	2008-10-29 11:36:23 UTC (rev 491)
@@ -104,6 +104,11 @@
    * Method: F
    */
   void f() {
+    try {
+      Thread.sleep(2000);
+    } catch (InterruptedException ie) {
+      // Ignore
+    }
   }
  
   /**




More information about the jboss-cvs-commits mailing list