[logback-dev] svn commit: r1689 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic/stopwatch logback-classic/src/test/java/ch/qos/logback/classic/stopwatch logback-site/src/site/pages/manual

noreply.ceki at qos.ch noreply.ceki at qos.ch
Mon May 5 22:32:25 CEST 2008


Author: ceki
Date: Mon May  5 22:32:25 2008
New Revision: 1689

Added:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/stopwatch/ProfilerRegistry.java
   logback/trunk/logback-site/src/site/pages/manual/profilers.html
Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/stopwatch/Profiler.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/ProfilerTest.java
   logback/trunk/logback-site/src/site/pages/manual/contextSelector.html
   logback/trunk/logback-site/src/site/pages/manual/index_menu.js

Log:
- created a new chapter on profilers
- ProfilerRegistry instance are intended to help developers track profilers

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/stopwatch/Profiler.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/stopwatch/Profiler.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/stopwatch/Profiler.java	Mon May  5 22:32:25 2008
@@ -18,7 +18,7 @@
 
 public class Profiler {
 
-  final static int MIN_SW_NAME_LENGTH = 10;
+  final static int MIN_SW_NAME_LENGTH = 12;
   final static int MIN_SW_ELAPSED_TIME_NUMBER_LENGTH = 6;
 
   final String name;
@@ -27,11 +27,21 @@
   List<StopWatch> stopwatchList = new ArrayList<StopWatch>();
   List<Object> childList = new ArrayList<Object>();
 
+  ProfilerRegistry profilerRegistry;
+  
   public Profiler(String name) {
     this.name = name;
     this.globalStopWatch = new StopWatch(name);
   }
 
+  public ProfilerRegistry getProfilerRegistry() {
+    return profilerRegistry;
+  }
+
+  public void setProfilerRegistry(ProfilerRegistry profilerRegistry) {
+    this.profilerRegistry = profilerRegistry;
+  }
+
   public void start(String name) {
     stopLastStopWatch();
     StopWatch childSW = new StopWatch(name);
@@ -41,6 +51,7 @@
 
   public Profiler startNested(String name) {
     Profiler nestedProfiler = new Profiler(name);
+    nestedProfiler.setProfilerRegistry(profilerRegistry);
     childList.add(nestedProfiler);
     return nestedProfiler;
   }

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/stopwatch/ProfilerRegistry.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/stopwatch/ProfilerRegistry.java	Mon May  5 22:32:25 2008
@@ -0,0 +1,37 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 1999-2008, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
+package ch.qos.logback.classic.stopwatch;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A miniminalistic registry of profilers.
+ * 
+ * @author Ceki
+ */
+public class ProfilerRegistry {
+
+  
+  Map<String, Profiler> profilerMap = new HashMap<String, Profiler>();
+  
+  public void put(String name, Profiler profiler) {
+    profilerMap.put(name, profiler);
+  }
+  
+  public Profiler get(String name) {
+    return profilerMap.get(name);
+  }
+  
+  public void clear() {
+    profilerMap.clear();
+  }
+}

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/ProfilerTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/ProfilerTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/ProfilerTest.java	Mon May  5 22:32:25 2008
@@ -34,6 +34,23 @@
   }
 
   @Test
+  public void X() {
+    Profiler profiler = new Profiler("BASIC");
+  
+
+  profiler.start("Subtask_1");
+  doX(1);
+     
+  profiler.start("Subtask_1");
+  for (int i = 0; i < 5; i++) {
+    doX(i);
+  }
+  profiler.start("doOther");
+  doX(2);
+  profiler.stop().print();
+  }
+
+  @Test
   public void testNestedProfiling() {
     Profiler profiler = new Profiler("BAS");
 
@@ -58,12 +75,12 @@
   public void doSubtask(Profiler nested) {
     nested.start("n1");
     doX(1);
-    
+
     nested.start("n2");
     doX(5);
     nested.stop();
   }
-  
+
   void doY(int millis) {
     delay(millis);
   }

Modified: logback/trunk/logback-site/src/site/pages/manual/contextSelector.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/contextSelector.html	(original)
+++ logback/trunk/logback-site/src/site/pages/manual/contextSelector.html	Mon May  5 22:32:25 2008
@@ -20,7 +20,7 @@
 </div>
 <div id="content">	
 	
-	<h2>Chapter 8: Context Selectors</h2>
+	<h2>Chapter 9: Context Selectors</h2>
 
   <div class="quote">
     <p><em>It is not knowledge, but the act of learning, not

Modified: logback/trunk/logback-site/src/site/pages/manual/index_menu.js
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/index_menu.js	(original)
+++ logback/trunk/logback-site/src/site/pages/manual/index_menu.js	Mon May  5 22:32:25 2008
@@ -7,5 +7,6 @@
 document.write('<p class="menu"><a href="layouts.html"><b>Ch5: Layouts</b></a>');
 document.write('<p class="menu"><a href="filters.html"><b>Ch6: Filter chains</b></a>');
 document.write('<p class="menu"><a href="mdc.html"><b>Ch7: Mapped Diagnostic Contexts</b></a>');
-document.write('<p class="menu"><a href="contextSelector.html"><b>Ch8: Context Selectors</b></a>');
+document.write('<p class="menu"><a href="profilers.html"><b>Ch8: Profilers</b></a>');
+document.write('<p class="menu"><a href="contextSelector.html"><b>Ch9: Context Selectors</b></a>');
 

Added: logback/trunk/logback-site/src/site/pages/manual/profilers.html
==============================================================================
--- (empty file)
+++ logback/trunk/logback-site/src/site/pages/manual/profilers.html	Mon May  5 22:32:25 2008
@@ -0,0 +1,72 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
+<title>Chapter 5: Layouts</title>
+<link rel="stylesheet" type="text/css" media="screen" href="../css/site.css" />
+<link rel="stylesheet" type="text/css" media="print" href="../css/print.css" />
+
+</head>
+<body>
+		<script>
+prefix='../';	
+</script>
+<script src="../templates/header.js"></script>
+<div id="left">
+  <script src="../templates/left.js"></script>
+</div>
+<div id="right">
+  <script src="index_menu.js"></script>
+</div>
+<div id="content">
+	
+		<h1>Chapter 8: Profilers</h1>
+	
+    <div class="quote">
+      <p>We should forget about small efficiencies, say about 97% of
+      the time: premature optimization is the root of all evil.
+      </p>
+      <p>&mdash; Donald Knuth, JON POSTEL, Structured Programming with
+    go to Statements</p> </div>
+
+    <script src="../templates/creative.js"></script>
+    <script src="../templates/setup.js"></script>
+     
+		<h2>What is a profiler?</h2>
+    
+    <p>According to wikipedia, <a
+    href="http://en.wikipedia.org/wiki/Profiler_%28computer_science%29">profiling</a>
+    is is the investigation of a program's behavior using information
+    gathered as the program runs (i.e. it is a form of dynamic program
+    analysis, as opposed to static code analysis). The usual goal of
+    performance analysis is to determine which parts of a program to
+    optimize for speed or memory usage.
+    </p>
+
+    <p>A logback profiler help the developer gather performance data
+    by managing one or more stopwatches driven by statements inserted
+    in the source code. An example, should make the point clearer.
+    </p>
+
+    <p class="source">
+  doSomethingBasic() {
+   Profiler profiler = new Profiler("BASIC");
+
+   profiler.start("Subtask_1");
+   doSubtaskOne();
+      
+   profiler.start("Subtask_1");
+   for (int i = 0; i &lt; 5; i++) {
+     doSubtaskTwo(i);
+   }
+   profiler.start("Other");
+   doOther();
+   profiler.stop().print();</p>
+
+    <p class="source">+ Profiler [BASIC]
+|-- elapsed time        [Subtask_1]  9.987 milliseconds.
+|-- elapsed time        [Subtask_1] 47.263 milliseconds.
+|-- elapsed time            [Other]  2.790 milliseconds.
+|-- Total elapsed time      [BASIC] 60.092 milliseconds.
+</p>
+</div>
\ No newline at end of file



More information about the logback-dev mailing list