org.jboss.varia.stats.StatisticsCollector Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source.
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file 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.varia.stats;
import org.jboss.system.ServiceMBeanSupport;
import org.jboss.varia.stats.report.ReportGenerator;
import java.util.Iterator;
import java.util.Set;
import java.util.HashSet;
/**
* @author Alexey Loubyansky
* @version $Revision: 81038 $
* @jmx:mbean name="jboss.stats:service=StatisticsCollector"
* extends="org.jboss.system.ServiceMBean"
*/
public class StatisticsCollector
extends ServiceMBeanSupport
implements StatisticsCollectorMBean
{
private final TxStatistics stats = new TxStatistics();
private final Set reportGenerators = new HashSet();
/**
* @jmx.managed-operation
*/
public void registerReportGenerator(ReportGenerator reportGenerator)
{
reportGenerators.add(reportGenerator);
}
/**
* @jmx.managed-operation
*/
public void unregisterReportGenerator(ReportGenerator reportGenerator)
{
reportGenerators.remove(reportGenerator);
}
/**
* @jmx.managed-operation
*/
public void clearStatistics()
{
stats.clear();
}
/**
* @jmx.managed-operation
*/
public void addStatisticalItem(StatisticalItem item)
{
stats.addStatisticalItem(item);
}
/**
* @jmx.managed-operation
*/
public Iterator reportsIterator()
{
return stats.getReports();
}
/**
* @jmx.managed-operation
*/
public TxStatistics txStatistics()
{
return stats;
}
/**
* @jmx.managed-operation
*/
public synchronized String reports()
{
StringBuffer buf = new StringBuffer();
buf.append("Report Description ");
for(Iterator generators = reportGenerators.iterator(); generators.hasNext();)
{
ReportGenerator generator = (ReportGenerator)generators.next();
buf.append("")
.append("")
.append(generator.getName())
.append(" ")
.append(generator.getDescription())
.append(" ");
}
buf.append("
");
/*
buf.append("");
buf.append("");
buf.append("Transaction started by total ");
buf.append(" ");
for(Iterator iter = stats.getReports(); iter.hasNext();)
{
TxReport report = (TxReport) iter.next();
String name = report.getName();
buf.append("")
.append("");
boolean anchor = !name.equals(reportName) && reportName != null;
if(anchor)
{
buf.append("");
}
buf.append(name)
.append(" ")
.append(report.getCount())
.append(" ");
if(anchor)
{
buf.append("");
}
buf.append(" ");
}
buf.append("
");
buf.append(" ");
TxReport report = stats.getReports(reportName);
if(report != null)
{
buf.append("");
String[] itemNames = stats.getCollectedItemNames();
for(int i = 0; i < itemNames.length; ++i)
{
buf.append("").append(itemNames[i]).append(" ");
}
buf.append(" ");
for(int i = 0; i < itemNames.length; ++i)
{
buf.append("");
String itemName = itemNames[i];
Map itemMap = (Map) report.getStats().get(itemName);
if(itemMap != null && !itemMap.isEmpty())
{
buf.append("")
.append("item % avg min max ");
for(Iterator itemIter = itemMap.values().iterator(); itemIter.hasNext();)
{
StatisticalItem item = (StatisticalItem) itemIter.next();
buf.append("")
.append(item.getValue())
.append(" ")
.append(100*((double)item.getMergedItemsTotal() / report.getCount()))
.append(" ")
.append(((double) item.getCount()) / report.getCount())
.append(" ")
.append(item.getMinCountPerTx())
.append(" ")
.append(item.getMaxCountPerTx())
.append(" ");
}
buf.append("
");
}
buf.append(" ");
}
buf.append("
");
}
buf.append("
");
buf.append("")
.append("- Transaction started by - the method which started the transaction
")
.append("- total - the total number of transactions in the run
")
.append("- % - the percentage of transactions this item took place in
")
.append("- avg - the average number of times the item took place in the given transaction
")
.append("
");
*/
return buf.toString();
}
}