1 18 package org.apache.activemq.tool.reports.plugins; 19 20 import org.apache.activemq.tool.reports.PerformanceStatisticsUtil; 21 22 import java.util.Map ; 23 import java.util.HashMap ; 24 import java.util.StringTokenizer ; 25 import java.util.List ; 26 import java.util.ArrayList ; 27 import java.util.Set ; 28 import java.util.Iterator ; 29 30 public class ThroughputReportPlugin implements ReportPlugin { 31 public static final String KEY_SYS_TOTAL_TP = "SystemTotalTP"; 32 public static final String KEY_SYS_TOTAL_CLIENTS = "SystemTotalClients"; 33 public static final String KEY_SYS_AVE_TP = "SystemAveTP"; 34 public static final String KEY_SYS_AVE_EMM_TP = "SystemAveEMMTP"; 35 public static final String KEY_SYS_AVE_CLIENT_TP = "SystemAveClientTP"; 36 public static final String KEY_SYS_AVE_CLIENT_EMM_TP = "SystemAveClientEMMTP"; 37 public static final String KEY_MIN_CLIENT_TP = "MinClientTP"; 38 public static final String KEY_MAX_CLIENT_TP = "MaxClientTP"; 39 public static final String KEY_MIN_CLIENT_TOTAL_TP = "MinClientTotalTP"; 40 public static final String KEY_MAX_CLIENT_TOTAL_TP = "MaxClientTotalTP"; 41 public static final String KEY_MIN_CLIENT_AVE_TP = "MinClientAveTP"; 42 public static final String KEY_MAX_CLIENT_AVE_TP = "MaxClientAveTP"; 43 public static final String KEY_MIN_CLIENT_AVE_EMM_TP = "MinClientAveEMMTP"; 44 public static final String KEY_MAX_CLIENT_AVE_EMM_TP = "MaxClientAveEMMTP"; 45 46 protected Map clientThroughputs = new HashMap (); 47 48 public void handleCsvData(String csvData) { 49 StringTokenizer tokenizer = new StringTokenizer (csvData, ","); 50 String data, key, val, clientName = null; 51 Long 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 } 64 } 65 addToClientTPList(clientName, throughput); 66 } 67 68 public Map getSummary() { 69 if (clientThroughputs.size() == 0) { 71 return new HashMap (); 72 } 73 74 long minClientTP = Long.MAX_VALUE, 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, maxClientAveEMMTP = Double.MIN_VALUE, 84 systemAveTP = 0.0, 85 systemAveEMMTP = 0.0; 86 87 String nameMinClientTP = "", 88 nameMaxClientTP = "", 89 nameMinClientTotalTP = "", 90 nameMaxClientTotalTP = "", 91 nameMinClientAveTP = "", 92 nameMaxClientAveTP = "", 93 nameMinClientAveEMMTP = "", 94 nameMaxClientAveEMMTP = ""; 95 96 Set clientNames = clientThroughputs.keySet(); 97 String clientName; 98 List clientTPList; 99 long tempLong; 100 double tempDouble; 101 int clientCount = 0; 102 for (Iterator i=clientNames.iterator(); i.hasNext();) { 103 clientName = (String )i.next(); 104 clientTPList = (List )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; 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; 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; 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 summary = new HashMap (); 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 clientName, Long throughput) { 176 if (clientName == null || throughput == null) { 178 throw new IllegalArgumentException ("Invalid Throughput CSV Data: clientName=" + clientName + ", throughput=" + throughput); 179 } 180 181 List clientTPList = (List )clientThroughputs.get(clientName); 182 if (clientTPList == null) { 183 clientTPList = new ArrayList (); 184 clientThroughputs.put(clientName, clientTPList); 185 } 186 clientTPList.add(throughput); 187 } 188 } 189 | Popular Tags |