[jboss-cvs] JBossAS SVN: r78247 - projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Sep 9 09:08:40 EDT 2008


Author: adrian at jboss.org
Date: 2008-09-09 09:08:40 -0400 (Tue, 09 Sep 2008)
New Revision: 78247

Added:
   projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractControllerMBean.java
   projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/BasicStatistic.java
   projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/StateStatistic.java
   projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/StateStatistics.java
Modified:
   projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java
Log:
[JBMICROCONT-352] - Expose install time stats for each stage and context

Modified: projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java	2008-09-09 12:41:05 UTC (rev 78246)
+++ projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java	2008-09-09 13:08:40 UTC (rev 78247)
@@ -60,7 +60,7 @@
  * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision$
  */
-public class AbstractController extends JBossObject implements Controller, ControllerStateModel, GraphController
+public class AbstractController extends JBossObject implements Controller, ControllerStateModel, GraphController, AbstractControllerMBean
 {
    /** The lock */
    private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
@@ -99,6 +99,12 @@
    /** Whether an on demand context has been enabled */
    private boolean onDemandEnabled = true;
 
+   /** Whether stats are enabled */
+   private boolean collectStats = false;
+   
+   /** The install stats */
+   private StateStatistics installStats = null;
+   
    /**
     * Create an abstract controller
     */
@@ -223,6 +229,33 @@
 
    }
 
+   /**
+    * Get the collectStats.
+    * 
+    * @return the collectStats.
+    */
+   public boolean isCollectStats()
+   {
+      return collectStats;
+   }
+
+   /**
+    * Set the collectStats.
+    * 
+    * @param collectStats the collectStats.
+    */
+   public void setCollectStats(boolean collectStats)
+   {
+      this.collectStats = collectStats;
+   }
+
+   public String listStateTimes(boolean details)
+   {
+      if (installStats == null)
+         return "No statistics available";
+      return installStats.listTimes(details);
+   }
+
    public void addState(ControllerState state, ControllerState before)
    {
       lockWrite();
@@ -1519,7 +1552,32 @@
     */
    protected void install(ControllerContext context, ControllerState fromState, ControllerState toState) throws Throwable
    {
-      context.install(fromState, toState);
+      long time = 0;
+      boolean collectStats = this.collectStats;
+      if (collectStats)
+         time = System.currentTimeMillis();
+      try
+      {
+         context.install(fromState, toState);
+      }
+      finally
+      {
+         if (collectStats)
+         {
+            time = System.currentTimeMillis() - time;
+            if (time > 0)
+            {
+               synchronized (this)
+               {
+                  if (installStats == null)
+                     installStats = new StateStatistics();;
+                  String state = toState.getStateString();
+                  String name = context.getName().toString();
+                  installStats.addStatistic(state, name, time);
+               }
+            }
+         }
+      }
    }
 
    /**

Added: projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractControllerMBean.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractControllerMBean.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractControllerMBean.java	2008-09-09 13:08:40 UTC (rev 78247)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.dependency.plugins;
+
+/**
+ * AbstractControllerMBean.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface AbstractControllerMBean
+{
+   /**
+    * List the state times
+    * 
+    * @param details whether to show details
+    * @return the deployer times
+    */
+   String listStateTimes(boolean details);
+}

Added: projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/BasicStatistic.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/BasicStatistic.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/BasicStatistic.java	2008-09-09 13:08:40 UTC (rev 78247)
@@ -0,0 +1,94 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.dependency.plugins;
+
+/**
+ * BasicStatistic.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class BasicStatistic implements Comparable<BasicStatistic>
+{
+   /** The name */
+   private String name;
+   
+   /** The total time */
+   private long time = 0;
+   
+   /**
+    * Create a new BasicStatistic.
+    * 
+    * @param name the name
+    */
+   public BasicStatistic(String name)
+   {
+      this.name = name;
+   }
+   
+   /**
+    * Create a new BasicStatistic with the given time.
+    * 
+    * @param name the name
+    * @param time the time
+    */
+   public BasicStatistic(String name, long time)
+   {
+      this.name = name;
+      this.time = time;
+   }
+
+   /**
+    * Get the name.
+    * 
+    * @return the name.
+    */
+   public String getName()
+   {
+      return name;
+   }
+
+   /**
+    * Get the time.
+    * 
+    * @return the time.
+    */
+   public long getTime()
+   {
+      return time;
+   }
+   
+   /**
+    * Add some time
+    * 
+    * @param time the time to add
+    */
+   public void addTime(long time)
+   {
+      this.time += time;
+   }
+
+   public int compareTo(BasicStatistic o)
+   {
+      return (int) (o.getTime() - getTime());
+   }
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/StateStatistic.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/StateStatistic.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/StateStatistic.java	2008-09-09 13:08:40 UTC (rev 78247)
@@ -0,0 +1,73 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.dependency.plugins;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * StateStatistic.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class StateStatistic extends BasicStatistic
+{
+   /** The details */
+   private Map<String, BasicStatistic> details = new ConcurrentHashMap<String, BasicStatistic>();
+   
+   /**
+    * Create a new StateStatistic.
+    * 
+    * @param name the name
+    */
+   public StateStatistic(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Get the details.
+    * 
+    * @return the details.
+    */
+   public Map<String, BasicStatistic> getDetails()
+   {
+      return details;
+   }
+   
+   /**
+    * Add a detail
+    * 
+    * @param name the name
+    * @param time the time
+    */
+   public synchronized void addDetail(String name, long time)
+   {
+      BasicStatistic previous = details.get(name);
+      if (previous != null)
+         previous.addTime(time);
+      else
+         details.put(name, new BasicStatistic(name, time));
+      addTime(time);
+   }
+}

Added: projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/StateStatistics.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/StateStatistics.java	                        (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/java/org/jboss/dependency/plugins/StateStatistics.java	2008-09-09 13:08:40 UTC (rev 78247)
@@ -0,0 +1,95 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.dependency.plugins;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * StateStatistics.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class StateStatistics
+{
+   /** The stage statistics */
+   private Map<String, StateStatistic> states = new ConcurrentHashMap<String, StateStatistic>();
+   
+   /**
+    * Add a statistic
+    * 
+    * @param state the stage name
+    * @param name the name
+    * @param time the time
+    */
+   public synchronized void addStatistic(String state, String name, long time)
+   {
+      StateStatistic stat = states.get(state);
+      if (stat == null)
+      {
+         stat = new StateStatistic(state);
+         states.put(state, stat);
+      }
+      stat.addDetail(name, time);
+   }
+   
+   /**
+    * List the times
+    * 
+    * @param details whether to show details
+    * @return the times
+    */
+   public String listTimes(boolean details)
+   {
+      List<StateStatistic> stats = new ArrayList<StateStatistic>(states.values());
+      Collections.sort(stats);
+      
+      StringBuilder builder = new StringBuilder();
+      builder.append("<table><tr><th>State/Name</th><th>Time (milliseconds)</th></tr>");
+      for (StateStatistic stat : stats)
+      {
+         builder.append("<tr>");
+         builder.append("<td>").append(stat.getName()).append("</td>");
+         builder.append("<td>").append(stat.getTime()).append("</td>");
+         builder.append("</tr>");
+         if (details)
+         {
+            List<BasicStatistic> list = new ArrayList<BasicStatistic>(stat.getDetails().values());
+            Collections.sort(list);
+            for (BasicStatistic detail : list)
+            {
+               builder.append("<tr>");
+               builder.append("<td>`-- ").append(detail.getName()).append("</td>");
+               builder.append("<td>").append(detail.getTime()).append("</td>");
+               builder.append("</tr>");
+            }
+         }
+      }
+      builder.append("</table>");
+      return builder.toString();
+
+   }
+}




More information about the jboss-cvs-commits mailing list