001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.varia.stats.report;
023:
024: import org.jboss.varia.stats.TxReport;
025: import org.jboss.varia.stats.StatisticalItem;
026: import org.jboss.varia.stats.TxStatistics;
027:
028: import java.util.Iterator;
029: import java.util.Map;
030:
031: /**
032: * @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
033: * @version <tt>$Revision: 57210 $</tt>
034: */
035: public class GeneralReportGenerator extends ReportGenerator {
036: public void content(String reportName, StringBuffer buf)
037: throws Exception {
038: buf.append("<table><tr valign='top'><td>");
039:
040: buf.append("<table>");
041: buf.append("<tr><th>Transaction started by</th><th>total</th>");
042: buf.append("</tr>");
043:
044: TxStatistics stats = getTxStatistics();
045: for (Iterator iter = stats.getReports(); iter.hasNext();) {
046: TxReport report = (TxReport) iter.next();
047:
048: String name = report.getName();
049: buf.append("<tr valign='top'>").append("<td>");
050:
051: boolean anchor = !name.equals(reportName)
052: && reportName != null;
053: if (anchor) {
054: buf.append("<a href='HtmlAdaptor?").append(
055: "action=invokeOpByName&name=").append(
056: getServiceName()).append(
057: "&methodName=generate&").append(
058: "argType=java.lang.String&arg0=").append(name)
059: .append("'>");
060: }
061:
062: buf.append(name).append("</td><td>").append(
063: report.getCount()).append("</td>");
064:
065: if (anchor) {
066: buf.append("</a>");
067: }
068:
069: buf.append("</td></tr>");
070: }
071:
072: buf.append("</table>");
073: buf.append("</td><td>");
074:
075: TxReport report = stats.getReports(reportName);
076: if (report != null) {
077: buf.append("<table><tr>");
078:
079: String[] itemNames = stats.getCollectedItemNames();
080: for (int i = 0; i < itemNames.length; ++i) {
081: buf.append("<th>").append(itemNames[i]).append("</th>");
082: }
083:
084: buf.append("</tr><tr valign='top'>");
085:
086: for (int i = 0; i < itemNames.length; ++i) {
087: buf.append("<td>");
088: String itemName = itemNames[i];
089:
090: Map itemMap = (Map) report.getStats().get(itemName);
091: if (itemMap != null && !itemMap.isEmpty()) {
092: buf
093: .append("<table width='100%'>")
094: .append(
095: "<tr><th>item</th><th>%</th><th>avg</th><th>min</th><th>max</th></tr>");
096:
097: for (Iterator itemIter = itemMap.values()
098: .iterator(); itemIter.hasNext();) {
099: StatisticalItem item = (StatisticalItem) itemIter
100: .next();
101: buf
102: .append("<tr><td>")
103: .append(item.getValue())
104: .append("</td><td>")
105: .append(
106: 100 * ((double) item
107: .getMergedItemsTotal() / report
108: .getCount())).append(
109: "</td><td>").append(
110: ((double) item.getCount())
111: / report.getCount())
112: .append("</td><td>").append(
113: item.getMinCountPerTx())
114: .append("</td><td>").append(
115: item.getMaxCountPerTx())
116: .append("</td>");
117: }
118:
119: buf.append("</table>");
120: }
121:
122: buf.append("</td>");
123: }
124:
125: buf.append("</tr></table>");
126: }
127:
128: buf.append("</td></tr></table>");
129:
130: buf
131: .append("<ul>")
132: .append(
133: "<li><b>Transaction started by</b> - the method which started the transaction</li>")
134: .append(
135: "<li><b>total</b> - the total number of transactions in the run</li>")
136: .append(
137: "<li><b>%</b> - the percentage of transactions this item took place in</li>")
138: .append(
139: "<li><b>avg</b> - the average number of times the item took place in the given transaction</li>")
140: .append(
141: "<li><b>min</b> - the minimum number of times the item took place in the given transaction</li>")
142: .append(
143: "<li><b>max</b> - the maximum number of times the item took place in the given transaction</li>")
144: .append("</ul>");
145: }
146: }
|