[jboss-cvs] JBossAS SVN: r78248 - projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 9 09:09:14 EDT 2008
Author: adrian at jboss.org
Date: 2008-09-09 09:09:14 -0400 (Tue, 09 Sep 2008)
New Revision: 78248
Added:
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/BasicStatistic.java
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployerStatistic.java
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployerStatistics.java
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImplMBean.java
Modified:
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java
Log:
[JBDEPLOY-91] - Expose deploy times stats for each deployer and deployment
Added: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/BasicStatistic.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/BasicStatistic.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/BasicStatistic.java 2008-09-09 13:09:14 UTC (rev 78248)
@@ -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.deployers.plugins.deployers;
+
+/**
+ * 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());
+ }
+}
Added: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployerStatistic.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployerStatistic.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployerStatistic.java 2008-09-09 13:09:14 UTC (rev 78248)
@@ -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.deployers.plugins.deployers;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * DeployerStatistic.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class DeployerStatistic extends BasicStatistic
+{
+ /** The details */
+ private Map<String, BasicStatistic> details = new ConcurrentHashMap<String, BasicStatistic>();
+
+ /**
+ * Create a new DeployerStatistic.
+ *
+ * @param name the name
+ */
+ public DeployerStatistic(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/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployerStatistics.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployerStatistics.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployerStatistics.java 2008-09-09 13:09:14 UTC (rev 78248)
@@ -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.deployers.plugins.deployers;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * DeployerStatistics.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class DeployerStatistics
+{
+ /** The deployer statistics */
+ private Map<String, DeployerStatistic> deployers = new ConcurrentHashMap<String, DeployerStatistic>();
+
+ /**
+ * Add a statistic
+ *
+ * @param deployerName the deployer name
+ * @param unitName the unit name
+ * @param time the time
+ */
+ public synchronized void addStatistic(String deployerName, String unitName, long time)
+ {
+ DeployerStatistic stat = deployers.get(deployerName);
+ if (stat == null)
+ {
+ stat = new DeployerStatistic(deployerName);
+ deployers.put(deployerName, stat);
+ }
+ stat.addDetail(unitName, time);
+ }
+
+ /**
+ * List the times
+ *
+ * @param details whether to show details
+ * @return the times
+ */
+ public String listTimes(boolean details)
+ {
+ List<DeployerStatistic> stats = new ArrayList<DeployerStatistic>(deployers.values());
+ Collections.sort(stats);
+
+ StringBuilder builder = new StringBuilder();
+ builder.append("<table><tr><th>Deployer/Deployment</th><th>Time (milliseconds)</th></tr>");
+ for (DeployerStatistic 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();
+
+ }
+}
Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java 2008-09-09 13:08:40 UTC (rev 78247)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java 2008-09-09 13:09:14 UTC (rev 78248)
@@ -69,7 +69,7 @@
* @author <a href="ales.justin at jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
-public class DeployersImpl implements Deployers, ControllerContextActions
+public class DeployersImpl implements Deployers, ControllerContextActions, DeployersImplMBean
{
/**
* The log
@@ -81,6 +81,12 @@
*/
private AtomicBoolean shutdown = new AtomicBoolean(false);
+ /** Whether to record statistics */
+ private boolean collectStats = false;
+
+ /** The deployment time stats */
+ private DeployerStatistics deploymentTimes;
+
/**
* The dependency state machine
*/
@@ -167,6 +173,26 @@
}
/**
+ * 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;
+ }
+
+ /**
* Get the deployers.
*
* @return the deployers.
@@ -424,6 +450,13 @@
}
}
+ public String listDeployerTimes(boolean details)
+ {
+ if (deploymentTimes == null)
+ return "No statistics available";
+ return deploymentTimes.listTimes(details);
+ }
+
public DeploymentStage getDeploymentStage(DeploymentContext context) throws DeploymentException
{
DeploymentControllerContext deploymentControllerContext = context.getTransientAttachments().getAttachment(ControllerContext.class.getName(), DeploymentControllerContext.class);
@@ -967,7 +1000,7 @@
{
try
{
- deployer.deploy(unit);
+ doDeploy(deployer, unit);
}
catch (DeploymentException e)
{
@@ -1109,7 +1142,7 @@
{
try
{
- deployer.deploy(unit);
+ doDeploy(deployer, unit);
}
catch (DeploymentException e)
{
@@ -1186,7 +1219,7 @@
DeploymentUnit unit = context.getDeploymentUnit();
if (isRelevant(deployer, unit, context.isTopLevel(), context.isComponent()))
- deployer.undeploy(unit);
+ doUndeploy(deployer, unit);
else if (log.isTraceEnabled())
log.trace("Deployer " + deployer + " not relevant for " + context.getName());
}
@@ -1205,7 +1238,7 @@
{
DeploymentUnit unit = context.getDeploymentUnit();
if (isRelevant(deployer, unit, context.isTopLevel(), context.isComponent()))
- deployer.undeploy(unit);
+ doUndeploy(deployer, unit);
else if (log.isTraceEnabled())
log.trace("Deployer " + deployer + " not relevant for " + context.getName());
}
@@ -1235,6 +1268,54 @@
}
/**
+ * Do a deployment
+ *
+ * @param deployer the deployer
+ * @param unit the deployment unit
+ * @throws DeploymentException for any error
+ */
+ protected void doDeploy(Deployer deployer, DeploymentUnit unit) throws DeploymentException
+ {
+ long time = 0;
+ boolean collectStats = this.collectStats;
+ if (collectStats)
+ time = System.currentTimeMillis();
+ try
+ {
+ deployer.deploy(unit);
+ }
+ finally
+ {
+ if (collectStats)
+ {
+ time = System.currentTimeMillis() - time;
+ if (time > 0)
+ {
+ synchronized (this)
+ {
+ if (deploymentTimes == null)
+ deploymentTimes = new DeployerStatistics();;
+ String deployerName = deployer.toString();
+ String deploymentName = unit.getName();
+ deploymentTimes.addStatistic(deployerName, deploymentName, time);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Do an undeployment
+ *
+ * @param deployer the deployer
+ * @param unit the deployment unit
+ */
+ protected void doUndeploy(Deployer deployer, DeploymentUnit unit)
+ {
+ deployer.undeploy(unit);
+ }
+
+ /**
* Build a list of deployers for this stage
*
* @param stageName the stage name
Added: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImplMBean.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImplMBean.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImplMBean.java 2008-09-09 13:09:14 UTC (rev 78248)
@@ -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.deployers.plugins.deployers;
+
+/**
+ * DeployersImplMBean.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface DeployersImplMBean
+{
+ /**
+ * List the deployer times
+ *
+ * @param details whether to show details
+ * @return the deployer times
+ */
+ String listDeployerTimes(boolean details);
+}
More information about the jboss-cvs-commits
mailing list