Author: ceki
Date: Tue May  6 22:23:31 2008
New Revision: 1690

Added:
   logback/trunk/logback-examples/src/main/java/chapter8/
   
logback/trunk/logback-examples/src/main/java/chapter8/NestedProfilerExample.java
   
logback/trunk/logback-examples/src/main/java/chapter8/ProfilerUsageExample.java

Log:
- adding profiler examples

Added: 
logback/trunk/logback-examples/src/main/java/chapter8/NestedProfilerExample.java
==============================================================================
--- (empty file)
+++ 
logback/trunk/logback-examples/src/main/java/chapter8/NestedProfilerExample.java
    Tue May  6 22:23:31 2008
@@ -0,0 +1,46 @@
+package chapter8;
+
+import ch.qos.logback.classic.stopwatch.Profiler;
+
+public class NestedProfilerExample {
+  
+  public static void main(String[] args) {
+    Profiler profiler = new Profiler("BASIC");
+    profiler.start("A");
+    doA();
+       
+    profiler.start("B");
+    for (int i = 0; i < 5; i++) {
+      doB(i);
+    }
+    profiler.start("Other");
+    doOther();
+    profiler.stop().print();
+  }
+
+  public void subTask() {
+    
+  }
+  
+
+  static void doA() {
+    delay(10);
+  }
+  
+  static void doB(int millis) {
+    delay(millis);
+  }
+
+  static void doOther() {
+    delay(10);
+  }
+
+  
+  static  void delay(int millis) {
+    try {
+      Thread.sleep(millis);
+    } catch (InterruptedException e) {
+    }
+  }
+
+}

Added: 
logback/trunk/logback-examples/src/main/java/chapter8/ProfilerUsageExample.java
==============================================================================
--- (empty file)
+++ 
logback/trunk/logback-examples/src/main/java/chapter8/ProfilerUsageExample.java 
    Tue May  6 22:23:31 2008
@@ -0,0 +1,40 @@
+package chapter8;
+
+import ch.qos.logback.classic.stopwatch.Profiler;
+
+public class ProfilerUsageExample {
+
+  public static void main(String[] args) {
+    Profiler profiler = new Profiler("BASIC");
+    profiler.start("A");
+    doA();
+       
+    profiler.start("B");
+    for (int i = 0; i < 5; i++) {
+      doB(i);
+    }
+    profiler.start("Other");
+    doOther();
+    profiler.stop().print();
+  }
+
+  static void doA() {
+    delay(10);
+  }
+  
+  static void doB(int millis) {
+    delay(millis);
+  }
+
+  static void doOther() {
+    delay(10);
+  }
+
+  
+  static  void delay(int millis) {
+    try {
+      Thread.sleep(millis);
+    } catch (InterruptedException e) {
+    }
+  }
+}
_______________________________________________
logback-dev mailing list
[email protected]
http://qos.ch/mailman/listinfo/logback-dev

Reply via email to