Reviewers: jbrosenberg, conroy,

Description:
Adds a 10 second flush timer to the Speed Tracer logger.


Please review this at http://gwt-code-reviews.appspot.com/1361801/

Affected files:
M dev/core/src/com/google/gwt/dev/util/log/speedtracer/SpeedTracerLogger.java


Index: dev/core/src/com/google/gwt/dev/util/log/speedtracer/SpeedTracerLogger.java
===================================================================
--- dev/core/src/com/google/gwt/dev/util/log/speedtracer/SpeedTracerLogger.java (revision 9755) +++ dev/core/src/com/google/gwt/dev/util/log/speedtracer/SpeedTracerLogger.java (working copy)
@@ -35,6 +35,7 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;

 /**
* Logs performance metrics for internal development purposes. The output is
@@ -334,6 +335,7 @@
    * Thread that converts log requests to JSON in the background.
    */
   private class LogWriterThread extends Thread {
+    private static final int FLUSH_TIMER_MSECS = 10000;
     private final String fileName;
     private final BlockingQueue<Event> threadEventQueue;
     private final Writer writer;
@@ -348,13 +350,22 @@

     @Override
     public void run() {
+      long lastFlush = System.currentTimeMillis();
       try {
-        boolean shuttingDown = false;
-        while (!threadEventQueue.isEmpty() || !shuttingDown) {
-          // Blocks until an event is queued
-          Event event = threadEventQueue.take();
-          if (event == shutDownSentinel) {
-            shuttingDown = true;
+        while (true) {
+          // Blocks until an event is queued or a timeout
+          long nextFlushInterval =
+              FLUSH_TIMER_MSECS - (System.currentTimeMillis() - lastFlush);
+          Event event =
+ threadEventQueue.poll(nextFlushInterval, TimeUnit.MILLISECONDS);
+          if (System.currentTimeMillis() - lastFlush > FLUSH_TIMER_MSECS) {
+            writer.flush();
+            lastFlush = System.currentTimeMillis();
+          }
+          if (event == null) {
+            // ignore.
+          } else if (event == shutDownSentinel) {
+            break;
           } else if (event == flushSentinel) {
             writer.flush();
             flushLatch.countDown();


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to