KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > tool > reports > plugins > ThroughputReportPlugin


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.tool.reports.plugins;
19
20 import org.apache.activemq.tool.reports.PerformanceStatisticsUtil;
21
22 import java.util.Map JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.StringTokenizer JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Set JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 public class ThroughputReportPlugin implements ReportPlugin {
31     public static final String JavaDoc KEY_SYS_TOTAL_TP = "SystemTotalTP";
32     public static final String JavaDoc KEY_SYS_TOTAL_CLIENTS = "SystemTotalClients";
33     public static final String JavaDoc KEY_SYS_AVE_TP = "SystemAveTP";
34     public static final String JavaDoc KEY_SYS_AVE_EMM_TP = "SystemAveEMMTP";
35     public static final String JavaDoc KEY_SYS_AVE_CLIENT_TP = "SystemAveClientTP";
36     public static final String JavaDoc KEY_SYS_AVE_CLIENT_EMM_TP = "SystemAveClientEMMTP";
37     public static final String JavaDoc KEY_MIN_CLIENT_TP = "MinClientTP";
38     public static final String JavaDoc KEY_MAX_CLIENT_TP = "MaxClientTP";
39     public static final String JavaDoc KEY_MIN_CLIENT_TOTAL_TP = "MinClientTotalTP";
40     public static final String JavaDoc KEY_MAX_CLIENT_TOTAL_TP = "MaxClientTotalTP";
41     public static final String JavaDoc KEY_MIN_CLIENT_AVE_TP = "MinClientAveTP";
42     public static final String JavaDoc KEY_MAX_CLIENT_AVE_TP = "MaxClientAveTP";
43     public static final String JavaDoc KEY_MIN_CLIENT_AVE_EMM_TP = "MinClientAveEMMTP";
44     public static final String JavaDoc KEY_MAX_CLIENT_AVE_EMM_TP = "MaxClientAveEMMTP";
45
46     protected Map JavaDoc clientThroughputs = new HashMap JavaDoc();
47
48     public void handleCsvData(String JavaDoc csvData) {
49         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(csvData, ",");
50         String JavaDoc data, key, val, clientName = null;
51         Long JavaDoc throughput = null;
52         while (tokenizer.hasMoreTokens()) {
53             data = tokenizer.nextToken();
54             key = data.substring(0, data.indexOf("="));
55             val = data.substring(data.indexOf("=") + 1);
56
57             if (key.equalsIgnoreCase("clientName")) {
58                 clientName = val;
59             } else if (key.equalsIgnoreCase("throughput")) {
60                 throughput = Long.valueOf(val);
61             } else {
62                 // Ignore unknown token
63
}
64         }
65         addToClientTPList(clientName, throughput);
66     }
67
68     public Map JavaDoc getSummary() {
69         // Check if tp sampler wasn't used.
70
if (clientThroughputs.size() == 0) {
71             return new HashMap JavaDoc();
72         }
73
74         long minClientTP = Long.MAX_VALUE, // TP = throughput
75
maxClientTP = Long.MIN_VALUE,
76                minClientTotalTP = Long.MAX_VALUE,
77                maxClientTotalTP = Long.MIN_VALUE,
78                systemTotalTP = 0;
79
80         double minClientAveTP = Double.MAX_VALUE,
81                maxClientAveTP = Double.MIN_VALUE,
82                minClientAveEMMTP = Double.MAX_VALUE, // EMM = Excluding Min/Max
83
maxClientAveEMMTP = Double.MIN_VALUE,
84                systemAveTP = 0.0,
85                systemAveEMMTP = 0.0;
86
87         String JavaDoc nameMinClientTP = "",
88                nameMaxClientTP = "",
89                nameMinClientTotalTP = "",
90                nameMaxClientTotalTP = "",
91                nameMinClientAveTP = "",
92                nameMaxClientAveTP = "",
93                nameMinClientAveEMMTP = "",
94                nameMaxClientAveEMMTP = "";
95
96         Set JavaDoc clientNames = clientThroughputs.keySet();
97         String JavaDoc clientName;
98         List JavaDoc clientTPList;
99         long tempLong;
100         double tempDouble;
101         int clientCount = 0;
102         for (Iterator JavaDoc i=clientNames.iterator(); i.hasNext();) {
103             clientName = (String JavaDoc)i.next();
104             clientTPList = (List JavaDoc)clientThroughputs.get(clientName);
105             clientCount++;
106
107             tempLong = PerformanceStatisticsUtil.getMin(clientTPList);
108             if (tempLong < minClientTP) {
109                 minClientTP = tempLong;
110                 nameMinClientTP = clientName;
111             }
112
113             tempLong = PerformanceStatisticsUtil.getMax(clientTPList);
114             if (tempLong > maxClientTP) {
115                 maxClientTP = tempLong;
116                 nameMaxClientTP = clientName;
117             }
118
119             tempLong = PerformanceStatisticsUtil.getSum(clientTPList);
120             systemTotalTP += tempLong; // Accumulate total TP
121
if (tempLong < minClientTotalTP) {
122                 minClientTotalTP = tempLong;
123                 nameMinClientTotalTP = clientName;
124             }
125
126             if (tempLong > maxClientTotalTP) {
127                 maxClientTotalTP = tempLong;
128                 nameMaxClientTotalTP = clientName;
129             }
130
131             tempDouble = PerformanceStatisticsUtil.getAve(clientTPList);
132             systemAveTP += tempDouble; // Accumulate ave throughput
133
if (tempDouble < minClientAveTP) {
134                 minClientAveTP = tempDouble;
135                 nameMinClientAveTP = clientName;
136             }
137
138             if (tempDouble > maxClientAveTP) {
139                 maxClientAveTP = tempDouble;
140                 nameMaxClientAveTP = clientName;
141             }
142
143             tempDouble = PerformanceStatisticsUtil.getAveEx(clientTPList);
144             systemAveEMMTP += tempDouble; // Accumulate ave throughput excluding min/max
145
if (tempDouble < minClientAveEMMTP) {
146                 minClientAveEMMTP = tempDouble;
147                 nameMinClientAveEMMTP = clientName;
148             }
149
150             if (tempDouble > maxClientAveEMMTP) {
151                 maxClientAveEMMTP = tempDouble;
152                 nameMaxClientAveEMMTP = clientName;
153             }
154         }
155
156         Map JavaDoc summary = new HashMap JavaDoc();
157         summary.put(KEY_SYS_TOTAL_TP, String.valueOf(systemTotalTP));
158         summary.put(KEY_SYS_TOTAL_CLIENTS, String.valueOf(clientCount));
159         summary.put(KEY_SYS_AVE_TP, String.valueOf(systemAveTP));
160         summary.put(KEY_SYS_AVE_EMM_TP, String.valueOf(systemAveEMMTP));
161         summary.put(KEY_SYS_AVE_CLIENT_TP, String.valueOf(systemAveTP / clientCount));
162         summary.put(KEY_SYS_AVE_CLIENT_EMM_TP, String.valueOf(systemAveEMMTP / clientCount));
163         summary.put(KEY_MIN_CLIENT_TP, nameMinClientTP + "=" + minClientTP);
164         summary.put(KEY_MAX_CLIENT_TP, nameMaxClientTP + "=" + maxClientTP);
165         summary.put(KEY_MIN_CLIENT_TOTAL_TP, nameMinClientTotalTP + "=" + minClientTotalTP);
166         summary.put(KEY_MAX_CLIENT_TOTAL_TP, nameMaxClientTotalTP + "=" + maxClientTotalTP);
167         summary.put(KEY_MIN_CLIENT_AVE_TP, nameMinClientAveTP + "=" + minClientAveTP);
168         summary.put(KEY_MAX_CLIENT_AVE_TP, nameMaxClientAveTP + "=" + maxClientAveTP);
169         summary.put(KEY_MIN_CLIENT_AVE_EMM_TP, nameMinClientAveEMMTP + "=" + minClientAveEMMTP);
170         summary.put(KEY_MAX_CLIENT_AVE_EMM_TP, nameMaxClientAveEMMTP + "=" + maxClientAveEMMTP);
171
172         return summary;
173     }
174
175     protected void addToClientTPList(String JavaDoc clientName, Long JavaDoc throughput) {
176         // Write to client's throughput list
177
if (clientName == null || throughput == null) {
178             throw new IllegalArgumentException JavaDoc("Invalid Throughput CSV Data: clientName=" + clientName + ", throughput=" + throughput);
179         }
180
181         List JavaDoc clientTPList = (List JavaDoc)clientThroughputs.get(clientName);
182         if (clientTPList == null) {
183             clientTPList = new ArrayList JavaDoc();
184             clientThroughputs.put(clientName, clientTPList);
185         }
186         clientTPList.add(throughput);
187     }
188 }
189
Popular Tags