[logback-dev] svn commit: r1683 - logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Sun May 4 20:17:09 CEST 2008
Author: ceki
Date: Sun May 4 20:17:08 2008
New Revision: 1683
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/StopWatchTest.java
Log:
- ongoing work on StopWatch and poor man's profiler functionality
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 Sun May 4 20:17:08 2008
@@ -1,21 +1,14 @@
package ch.qos.logback.classic.stopwatch;
-
+import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import ch.qos.logback.core.BasicStatusManager;
-import ch.qos.logback.core.status.ErrorStatus;
-import ch.qos.logback.core.status.InfoStatus;
-import ch.qos.logback.core.status.Status;
-import ch.qos.logback.core.status.StatusManager;
-import ch.qos.logback.core.util.StatusPrinter;
-
public class ProfilerTest {
Logger logger = LoggerFactory.getLogger(ProfilerTest.class);
-
+
@Test
public void smoke() {
Profiler profiler = new Profiler("SMOKE");
@@ -23,56 +16,62 @@
profiler.stop();
}
+ @Ignore
@Test
- public void X() {
- StatusManager sm = new BasicStatusManager();
- Status g = new InfoStatus("global", this);
- Status g1 = new InfoStatus("g1", this);
- Status g2 = new InfoStatus("g2", this);
- Status g11 = new InfoStatus("g11", this);
- Status g12 = new InfoStatus("g11", this);
- Status g21 = new InfoStatus("g21", this);
-
-
- g.add(g1);
- g.add(g2);
-
- g1.add(g11);
- g1.add(g12);
- g2.add(g21);
-
- sm.add(g);
- StatusPrinter.print(sm);
-
+ public void testBasicProfiling() {
+ Profiler profiler = new Profiler("BAS");
+
+ profiler.start("doX");
+ doX(1);
+
+ profiler.start("doYYYYY");
+ for (int i = 0; i < 5; i++) {
+ doY(i);
+ }
+ profiler.start("doZ");
+ doZ(2);
+ profiler.stop().print();
}
+
@Test
- public void testBasicProfiling() {
+ public void testNestedProfiling() {
Profiler profiler = new Profiler("BAS");
-
+
profiler.start("doX");
doX(1);
-
+
profiler.start("doYYYYY");
- for(int i = 0; i < 5; i++) {
+ for (int i = 0; i < 5; i++) {
doY(i);
}
+ Profiler nested = profiler.startNested("subtask");
+ doSubtask(nested);
profiler.start("doZ");
doZ(2);
- profiler.stop();
+ profiler.stop().print();
}
-
+
void doX(int millis) {
delay(millis);
}
+
+ public void doSubtask(Profiler nested) {
+ nested.start("n1");
+ doX(1);
+
+ nested.start("n2");
+ doX(5);
+ nested.stop();
+ }
void doY(int millis) {
- delay(millis);
+ delay(millis);
}
-
+
void doZ(int millis) {
- delay(millis);
+ delay(millis);
}
-
+
void delay(int millis) {
try {
Thread.sleep(millis);
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/StopWatchTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/StopWatchTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/stopwatch/StopWatchTest.java Sun May 4 20:17:08 2008
@@ -16,46 +16,13 @@
super.tearDown();
}
- public void testBasic() throws InterruptedException {
- StopWatch sw = new StopWatch("testBasic");
-
- {
- long d = sw.startTime+10;
- String s = sw.stop(d).toString();
- assertTrue(s.endsWith("10 nanoseconds."));
- }
-
- {
- long d = sw.startTime+9*Util.NANOS_IN_ONE_MICROSECOND;
- String s = sw.stop(d).toString();
- assertTrue(s.endsWith("9000 nanoseconds."));
- }
-
- {
- long d = sw.startTime+11*Util.NANOS_IN_ONE_MICROSECOND;
- String s = sw.stop(d).toString();
- assertTrue(s.endsWith("11 microseconds."));
- }
- {
- long d = sw.startTime+9*Util.NANOS_IN_ONE_MILLISECOND;
- String s = sw.stop(d).toString();
- assertTrue(s.endsWith("9000 microseconds."));
- }
- {
- long d = sw.startTime+3*Util.NANOS_IN_ONE_SECOND;
- String s = sw.stop(d).toString();
- System.out.println(s);
- assertTrue(s.endsWith("3.000 seconds."));
- }
- }
-
public void testSelectDurationUnitForDisplay() throws InterruptedException {
assertEquals(DurationUnit.NANOSECOND, Util.selectDurationUnitForDisplay(10));
assertEquals(DurationUnit.NANOSECOND, Util.selectDurationUnitForDisplay(9*Util.NANOS_IN_ONE_MICROSECOND));
assertEquals(DurationUnit.MICROSECOND, Util.selectDurationUnitForDisplay(11*Util.NANOS_IN_ONE_MICROSECOND));
assertEquals(DurationUnit.MICROSECOND, Util.selectDurationUnitForDisplay(9*Util.NANOS_IN_ONE_MILLISECOND));
assertEquals(DurationUnit.MILLISSECOND, Util.selectDurationUnitForDisplay(11*Util.NANOS_IN_ONE_MILLISECOND));
- assertEquals(DurationUnit.SECOND, Util.selectDurationUnitForDisplay(3*Util.NANOS_IN_ONE_SECOND));
+ assertEquals(DurationUnit.SECOND, Util.selectDurationUnitForDisplay(11*Util.NANOS_IN_ONE_SECOND));
}
}
More information about the logback-dev
mailing list