You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2006/04/07 10:58:03 UTC

svn commit: r392223 - /incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/DebugPhaseListener.java

Author: weber
Date: Fri Apr  7 01:58:02 2006
New Revision: 392223

URL: http://svn.apache.org/viewcvs?rev=392223&view=rev
Log:
write response and phase time information to logs

Modified:
    incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/DebugPhaseListener.java

Modified: incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/DebugPhaseListener.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/DebugPhaseListener.java?rev=392223&r1=392222&r2=392223&view=diff
==============================================================================
--- incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/DebugPhaseListener.java (original)
+++ incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/DebugPhaseListener.java Fri Apr  7 01:58:02 2006
@@ -19,9 +19,12 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
+import java.util.Date;
+import java.util.Map;
 
 /**
  * Created by IntelliJ IDEA.
@@ -32,12 +35,64 @@
  */
 public class DebugPhaseListener implements PhaseListener {
   private static final Log LOG = LogFactory.getLog(DebugPhaseListener.class);
+  private static final String KEY = DebugPhaseListener.class.getName() + "_ID_";
   public void afterPhase(PhaseEvent phaseEvent) {
-    LOG.debug("After Phase :" + phaseEvent.getPhaseId());
+    if (LOG.isInfoEnabled()) {
+      Date end = new Date();
+      Map map = FacesContext.getCurrentInstance().getExternalContext()
+          .getRequestMap();
+      map.put(KEY + phaseEvent.getPhaseId().getOrdinal() + "E", end);
+
+      if (LOG.isTraceEnabled()) {
+        LOG.trace("After Phase :" + phaseEvent.getPhaseId()
+            + " Time=" + end.getTime());
+      }
+
+      if (LOG.isDebugEnabled()) {
+        Date start
+            = (Date) map.get(KEY + phaseEvent.getPhaseId().getOrdinal() + "S");
+        LOG.debug("Phase " + phaseEvent.getPhaseId() + " needs "
+            + (end.getTime() - start.getTime() + " milliseconds"));
+      }
+
+      if (phaseEvent.getPhaseId().getOrdinal() == 6) {
+        Date start = (Date) map.get(KEY + "1S");
+        if (start != null) {
+          LOG.info("Total response time : "
+              + (end.getTime() - start.getTime() + " milliseconds"));
+        }
+      }
+    }
+
   }
 
   public void beforePhase(PhaseEvent phaseEvent) {
-    LOG.debug("Before Phase :" + phaseEvent.getPhaseId());
+    if (LOG.isInfoEnabled()) {
+      Date start = null;
+      Map map = null;
+      if (LOG.isDebugEnabled() || phaseEvent.getPhaseId().getOrdinal() == 1) {
+        start = new Date();
+        map = FacesContext.getCurrentInstance().getExternalContext()
+            .getRequestMap();
+        map.put(KEY + phaseEvent.getPhaseId().getOrdinal() + "S", start);
+      }
+
+      if (LOG.isDebugEnabled()) {
+        Date end = null;
+        int ordinal = phaseEvent.getPhaseId().getOrdinal();
+        while (end == null && ordinal > 0) {
+          end = (Date) map.get(KEY + --ordinal + "E");
+        }
+        if (end != null) {
+          LOG.debug("Time between phases " + ordinal + " and " + phaseEvent.getPhaseId().getOrdinal() + ": "
+              + (start.getTime() - end.getTime()) + " milliseconds");
+        }
+      }
+      if (LOG.isTraceEnabled()) {
+        LOG.trace("Before Phase :" + phaseEvent.getPhaseId()
+            + " Time=" + start.getTime());
+      }
+    }
   }
 
   public PhaseId getPhaseId() {