[slf4j-dev] svn commit: r1375 - slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/profiler

ceki at slf4j.org ceki at slf4j.org
Mon Jul 20 16:08:27 CEST 2009


Author: ceki
Date: Mon Jul 20 16:08:27 2009
New Revision: 1375

Modified:
   slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/profiler/Profiler.java
   slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/profiler/StopWatch.java

Log:
In response to bug 141, added getCopyOfChildTimeInstruments and getCopyOfGlobalStopWatch methods. This allows developers to create their own output formats for Profiler.
See also http://bugzilla.slf4j.org/show_bug.cgi?id=141


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 20 16:08:27 2009
@@ -59,7 +59,6 @@
   final String name;
   final StopWatch globalStopWatch;
 
-  // List<StopWatch> stopwatchList = new ArrayList<StopWatch>();
   List<TimeInstrument> childTimeInstrumentList = new ArrayList<TimeInstrument>();
 
   // optional field
@@ -210,6 +209,29 @@
     }
   }
 
+
+  /**
+   * Return a copy of the child instrument list for this Profiler instance.
+   * 
+   * @return a copy of this instance's child time instrument list
+   * @since 1.5.9
+   */
+  public List<TimeInstrument> getCopyOfChildTimeInstruments() {
+    List<TimeInstrument> copy = new ArrayList<TimeInstrument>(childTimeInstrumentList);
+    return copy;
+  }
+
+  /**
+   * Return a copy of the global stopwath of this Profiler instance.
+   * 
+   * @return a copy of this instance's global stop watch
+   * @since 1.5.9
+   */
+  public StopWatch getCopyOfGlobalStopWatch() {
+    StopWatch copy = new StopWatch(globalStopWatch);
+    return copy;
+  }
+  
   private String buildProfilerString(DurationUnit du, String firstPrefix,
       String label, String indentation) {
     StringBuffer buf = new StringBuffer();
@@ -251,5 +273,4 @@
     Util.appendDurationUnitAsStr(buf, du);
     buf.append(SpacePadder.LINE_SEP);
   }
-
 }

Modified: slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/profiler/StopWatch.java
==============================================================================
--- slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/profiler/StopWatch.java	(original)
+++ slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/profiler/StopWatch.java	Mon Jul 20 16:08:27 2009
@@ -42,6 +42,14 @@
     start(name);
   }
 
+  StopWatch(StopWatch original) {
+    this.name = original.name;
+    this.startTime = original.startTime;
+    this.stopTime = original.stopTime;
+    this.status = original.status;
+  }
+
+  
   public void start(String name) {
     this.name = name;
     startTime = System.nanoTime();



More information about the slf4j-dev mailing list