Revision: 9757
Author: [email protected]
Date: Wed Feb 23 12:33:24 2011
Log: Adds a 10 second flush timer to the Speed Tracer logger.
Review at http://gwt-code-reviews.appspot.com/1361801
http://code.google.com/p/google-web-toolkit/source/detail?r=9757
Modified:
/trunk/dev/core/src/com/google/gwt/dev/util/log/speedtracer/SpeedTracerLogger.java
=======================================
---
/trunk/dev/core/src/com/google/gwt/dev/util/log/speedtracer/SpeedTracerLogger.java
Fri Feb 4 12:13:36 2011
+++
/trunk/dev/core/src/com/google/gwt/dev/util/log/speedtracer/SpeedTracerLogger.java
Wed Feb 23 12:33:24 2011
@@ -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,16 @@
@Override
public void run() {
+ long nextFlush = System.currentTimeMillis() + FLUSH_TIMER_MSECS;
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) {
+ Event event =
+ threadEventQueue.poll(nextFlush - System.currentTimeMillis(),
+ TimeUnit.MILLISECONDS);
+ if (event == null) {
+ // ignore.
+ } else if (event == shutDownSentinel) {
+ break;
} else if (event == flushSentinel) {
writer.flush();
flushLatch.countDown();
@@ -363,6 +368,10 @@
json.write(writer);
writer.write('\n');
}
+ if (System.currentTimeMillis() >= nextFlush) {
+ writer.flush();
+ nextFlush = System.currentTimeMillis() + FLUSH_TIMER_MSECS;
+ }
}
// All queued events have been written.
if (outputFormat.equals(Format.HTML)) {
@@ -670,6 +679,8 @@
/**
* Notifies the background thread to finish processing all data in the
queue.
+ * Blocks the current thread until the data is flushed in the Log Writer
+ * thread.
*/
void flush() {
try {
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors