[slf4j-dev] svn commit: r1072 - in slf4j/trunk/slf4j-ext/src: main/java/org/slf4j/profiler main/java/resources main/java/resources/META-INF test/java/org/slf4j/profiler

ceki at slf4j.org ceki at slf4j.org
Mon Jul 21 17:05:10 CEST 2008


Author: ceki
Date: Mon Jul 21 17:05:10 2008
New Revision: 1072

Added:
   slf4j/trunk/slf4j-ext/src/main/java/resources/
   slf4j/trunk/slf4j-ext/src/main/java/resources/META-INF/
   slf4j/trunk/slf4j-ext/src/main/java/resources/META-INF/MANIFEST.MF
   slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/profiler/UtilTest.java
      - copied, changed from r1069, /slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/profiler/StopWatchTest.java
Removed:
   slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/profiler/StopWatchTest.java
Modified:
   slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/profiler/Profiler.java
   slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/profiler/PackageTest.java

Log:
- profilers now know about loggers
- added MANIFEST.MF file

Modified: slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/profiler/Profiler.java
==============================================================================
--- slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/profiler/Profiler.java	(original)
+++ slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/profiler/Profiler.java	Mon Jul 21 17:05:10 2008
@@ -26,42 +26,47 @@
 import java.util.ArrayList;
 import java.util.List;
 
-
-// +  Profiler [BAS]
-// |-- elapsed time            [doX]     0 milliseconds.
-// |-- elapsed time        [doYYYYY]    56 milliseconds.
+import org.slf4j.Logger;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+
+// + Profiler [BAS]
+// |-- elapsed time [doX] 0 milliseconds.
+// |-- elapsed time [doYYYYY] 56 milliseconds.
 // |--+ Profiler Y
-//    |-- elapsed time            [doZ]    21 milliseconds.
-//    |-- elapsed time            [doZ]    21 milliseconds.
-//    |-- Total elapsed time        [Y]    78 milliseconds.
-// |-- elapsed time            [doZ]    21 milliseconds.
-// |-- Total elapsed time      [BAS]    78 milliseconds.
+// |-- elapsed time [doZ] 21 milliseconds.
+// |-- elapsed time [doZ] 21 milliseconds.
+// |-- Total elapsed time [Y] 78 milliseconds.
+// |-- elapsed time [doZ] 21 milliseconds.
+// |-- Total elapsed time [BAS] 78 milliseconds.
 
 // + Profiler [TOP]
 // |--+ Profiler [IIII]
-//    |-- elapsed time                            [A]   0.006 milliseconds.
-//    |-- elapsed time                            [B]  75.777 milliseconds.
-//    |-- elapsed time                       [VVVVVV] 161.589 milliseconds.
-//    |-- Total elapsed time                   [IIII] 240.580 milliseconds.
+// |-- elapsed time [A] 0.006 milliseconds.
+// |-- elapsed time [B] 75.777 milliseconds.
+// |-- elapsed time [VVVVVV] 161.589 milliseconds.
+// |-- Total elapsed time [IIII] 240.580 milliseconds.
 // |--+ Profiler [RRRRRRRRR]
-//    |-- elapsed time                           [R0]   9.390 milliseconds.
-//    |-- elapsed time                           [R1]   6.555 milliseconds.
-//    |-- elapsed time                           [R2]   5.995 milliseconds.
-//    |-- elapsed time                           [R3] 115.502 milliseconds.
-//    |-- elapsed time                           [R4]   0.064 milliseconds.
-//    |-- Total elapsed time                      [R] 138.340 milliseconds.
+// |-- elapsed time [R0] 9.390 milliseconds.
+// |-- elapsed time [R1] 6.555 milliseconds.
+// |-- elapsed time [R2] 5.995 milliseconds.
+// |-- elapsed time [R3] 115.502 milliseconds.
+// |-- elapsed time [R4] 0.064 milliseconds.
+// |-- Total elapsed time [R] 138.340 milliseconds.
 // |--+ Profiler [S]
-//    |-- Total elapsed time                     [S0]  3.091 milliseconds.
+// |-- Total elapsed time [S0] 3.091 milliseconds.
 // |--+ Profiler [P]
-//    |-- elapsed time                           [P0] 87.550 milliseconds.
-//    |-- Total elapsed time                      [P] 87.559 milliseconds.
-// |-- Total elapsed time                  [TOP] 467.548 milliseconds.
-            
+// |-- elapsed time [P0] 87.550 milliseconds.
+// |-- Total elapsed time [P] 87.559 milliseconds.
+// |-- Total elapsed time [TOP] 467.548 milliseconds.
+
 public class Profiler {
 
+  final static String PROFILER_MARKER_NAME = "PROFILER";
+
   final static int MIN_SW_NAME_LENGTH = 24;
   final static int MIN_SW_ELAPSED_TIME_NUMBER_LENGTH = 9;
-
+  
   final String name;
   final StopWatch globalStopWatch;
 
@@ -69,12 +74,13 @@
   List<Object> childList = new ArrayList<Object>();
 
   ProfilerRegistry profilerRegistry;
-  
+  Logger logger;
+
   public Profiler(String name) {
     this.name = name;
     this.globalStopWatch = new StopWatch(name);
   }
-  
+
   public String getName() {
     return name;
   }
@@ -84,13 +90,21 @@
   }
 
   public void setProfilerRegistry(ProfilerRegistry profilerRegistry) {
-    if(profilerRegistry == null) {
+    if (profilerRegistry == null) {
       return;
     }
     this.profilerRegistry = profilerRegistry;
     profilerRegistry.put(this);
   }
 
+  public Logger getLogger() {
+    return logger;
+  }
+
+  public void setLogger(Logger logger) {
+    this.logger = logger;
+  }
+
   public void start(String name) {
     stopLastStopWatch();
     StopWatch childSW = new StopWatch(name);
@@ -101,6 +115,7 @@
   public Profiler startNested(String name) {
     Profiler nestedProfiler = new Profiler(name);
     nestedProfiler.setProfilerRegistry(profilerRegistry);
+    nestedProfiler.setLogger(logger);
     childList.add(nestedProfiler);
     return nestedProfiler;
   }
@@ -140,22 +155,31 @@
     System.out.println(r);
   }
 
+  public void log() {
+    Marker profilerMarker = MarkerFactory.getMarker(PROFILER_MARKER_NAME);
+    if (logger.isDebugEnabled(profilerMarker)) {
+      DurationUnit du = Util.selectDurationUnitForDisplay(globalStopWatch);
+      String r = buildString(du, "+", "");
+      logger.debug(profilerMarker, r);
+    }
+  }
+
   private String buildString(DurationUnit du, String prefix, String indentation) {
     StringBuffer buf = new StringBuffer();
 
-    
     buf.append(prefix);
     buf.append(" Profiler [");
     buf.append(name);
     buf.append("]");
     buf.append(SpacePadder.LINE_SEP);
     for (Object child : childList) {
-      if(child instanceof StopWatch) {
-       buildStringForChildStopWatch(buf, indentation, (StopWatch) child, du);
-      } else if(child instanceof Profiler) {
+      if (child instanceof StopWatch) {
+        buildStringForChildStopWatch(buf, indentation, (StopWatch) child, du);
+      } else if (child instanceof Profiler) {
         Profiler profiler = (Profiler) child;
         profiler.stop();
-        String subString = profiler.buildString(du, "|--+", indentation + "   ");
+        String subString = profiler
+            .buildString(du, "|--+", indentation + "   ");
         buf.append(subString);
       }
     }

Added: slf4j/trunk/slf4j-ext/src/main/java/resources/META-INF/MANIFEST.MF
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-ext/src/main/java/resources/META-INF/MANIFEST.MF	Mon Jul 21 17:05:10 2008
@@ -0,0 +1,8 @@
+Implementation-Title: slf4j-ext
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: slf4j.ext
+Bundle-Name: slf4j-log4j12
+Bundle-Vendor: SLF4J.ORG
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Export-Package: org.slf4j.profiler;version=${project.version}
+Import-Package: org.slf4j;version=${project.version}, org.slf4j.spi;version=${project.version}, org.slf4j.helpers;version=${project.version}

Modified: slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/profiler/PackageTest.java
==============================================================================
--- slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/profiler/PackageTest.java	(original)
+++ slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/profiler/PackageTest.java	Mon Jul 21 17:05:10 2008
@@ -31,7 +31,7 @@
 
   public static Test suite() {
     TestSuite suite = new TestSuite();
-    suite.addTestSuite(StopWatchTest.class);
+    suite.addTestSuite(UtilTest.class);
     suite.addTestSuite(ProfilerTest.class);
     return suite;
   }

Copied: slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/profiler/UtilTest.java (from r1069, /slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/profiler/StopWatchTest.java)
==============================================================================
--- /slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/profiler/StopWatchTest.java	(original)
+++ slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/profiler/UtilTest.java	Mon Jul 21 17:05:10 2008
@@ -26,9 +26,9 @@
 
 import junit.framework.TestCase;
 
-public class StopWatchTest extends TestCase {
+public class UtilTest extends TestCase {
 
-  public StopWatchTest(String name) {
+  public UtilTest(String name) {
     super(name);
   }
 



More information about the slf4j-dev mailing list