KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > varia > stats > report > GeneralReportGenerator


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.varia.stats.report;
23
24 import org.jboss.varia.stats.TxReport;
25 import org.jboss.varia.stats.StatisticalItem;
26 import org.jboss.varia.stats.TxStatistics;
27
28 import java.util.Iterator JavaDoc;
29 import java.util.Map JavaDoc;
30
31 /**
32  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
33  * @version <tt>$Revision: 37459 $</tt>
34  */

35 public class GeneralReportGenerator
36    extends ReportGenerator
37 {
38    public void content(String JavaDoc reportName, StringBuffer JavaDoc buf) throws Exception JavaDoc
39    {
40       buf.append("<table><tr valign='top'><td>");
41
42       buf.append("<table>");
43       buf.append("<tr><th>Transaction started by</th><th>total</th>");
44       buf.append("</tr>");
45
46       TxStatistics stats = getTxStatistics();
47       for(Iterator JavaDoc iter = stats.getReports(); iter.hasNext();)
48       {
49          TxReport report = (TxReport) iter.next();
50
51          String JavaDoc name = report.getName();
52          buf.append("<tr valign='top'>")
53             .append("<td>");
54
55          boolean anchor = !name.equals(reportName) && reportName != null;
56          if(anchor)
57          {
58             buf.append("<a HREF='HtmlAdaptor?")
59                .append("action=invokeOpByName&name=")
60                .append(getServiceName())
61                .append("&methodName=generate&")
62                .append("argType=java.lang.String&arg0=")
63                .append(name)
64                .append("'>");
65          }
66
67          buf.append(name)
68             .append("</td><td>")
69             .append(report.getCount())
70             .append("</td>");
71
72          if(anchor)
73          {
74             buf.append("</a>");
75          }
76
77          buf.append("</td></tr>");
78       }
79
80       buf.append("</table>");
81       buf.append("</td><td>");
82
83       TxReport report = stats.getReports(reportName);
84       if(report != null)
85       {
86          buf.append("<table><tr>");
87
88          String JavaDoc[] itemNames = stats.getCollectedItemNames();
89          for(int i = 0; i < itemNames.length; ++i)
90          {
91             buf.append("<th>").append(itemNames[i]).append("</th>");
92          }
93
94          buf.append("</tr><tr valign='top'>");
95
96          for(int i = 0; i < itemNames.length; ++i)
97          {
98             buf.append("<td>");
99             String JavaDoc itemName = itemNames[i];
100
101             Map JavaDoc itemMap = (Map JavaDoc) report.getStats().get(itemName);
102             if(itemMap != null && !itemMap.isEmpty())
103             {
104                buf.append("<table width='100%'>")
105                   .append("<tr><th>item</th><th>%</th><th>avg</th><th>min</th><th>max</th></tr>");
106
107                for(Iterator JavaDoc itemIter = itemMap.values().iterator(); itemIter.hasNext();)
108                {
109                   StatisticalItem item = (StatisticalItem) itemIter.next();
110                   buf.append("<tr><td>")
111                      .append(item.getValue())
112                      .append("</td><td>")
113                      .append(100*((double)item.getMergedItemsTotal() / report.getCount()))
114                      .append("</td><td>")
115                      .append(((double) item.getCount()) / report.getCount())
116                      .append("</td><td>")
117                      .append(item.getMinCountPerTx())
118                      .append("</td><td>")
119                      .append(item.getMaxCountPerTx())
120                      .append("</td>");
121                }
122
123                buf.append("</table>");
124             }
125
126             buf.append("</td>");
127          }
128
129          buf.append("</tr></table>");
130       }
131
132       buf.append("</td></tr></table>");
133
134       buf.append("<ul>")
135          .append("<li><b>Transaction started by</b> - the method which started the transaction</li>")
136          .append("<li><b>total</b> - the total number of transactions in the run</li>")
137          .append("<li><b>%</b> - the percentage of transactions this item took place in</li>")
138          .append("<li><b>avg</b> - the average number of times the item took place in the given transaction</li>")
139          .append("<li><b>min</b> - the minimum number of times the item took place in the given transaction</li>")
140          .append("<li><b>max</b> - the maximum number of times the item took place in the given transaction</li>")
141          .append("</ul>");
142    }
143 }
144
Popular Tags