KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > tool > reports > VerbosePerfReportWriter


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;
19
20 import org.apache.activemq.tool.reports.plugins.ThroughputReportPlugin;
21 import org.apache.activemq.tool.reports.plugins.CpuReportPlugin;
22
23 import java.util.Properties JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Arrays JavaDoc;
27
28 public class VerbosePerfReportWriter extends AbstractPerfReportWriter {
29
30     public void openReportWriter() {
31         // Do nothing
32
}
33
34     public void closeReportWriter() {
35         writeHeader("Performance Summary");
36         writePerfSummary();
37     }
38
39     public void writeInfo(String JavaDoc info) {
40         System.out.println("[PERF-INFO]: " + info);
41     }
42
43     public void writeCsvData(int csvType, String JavaDoc csvData) {
44         if (csvType == REPORT_PLUGIN_THROUGHPUT) {
45             System.out.println("[PERF-TP]: " + csvData);
46         } else if (csvType == REPORT_PLUGIN_CPU) {
47             System.out.println("[PERF-CPU]: " + csvData);
48         }
49         handleCsvData(csvType, csvData);
50     }
51
52     public void writeProperties(String JavaDoc header, Properties JavaDoc props) {
53         writeHeader(header);
54         writeProperties(props);
55     }
56
57     public void writeProperties(Properties JavaDoc props) {
58         for (Iterator JavaDoc i=props.keySet().iterator(); i.hasNext();) {
59             String JavaDoc key = (String JavaDoc)i.next();
60             String JavaDoc val = props.getProperty(key, "");
61             System.out.println("[PERF-PROP]: " + key + "=" + val);
62         }
63     }
64
65     public void writePerfSummary() {
66
67         Map JavaDoc summary;
68
69         summary = getSummary(REPORT_PLUGIN_THROUGHPUT);
70         if (summary != null && summary.size() > 0) {
71             writeThroughputSummary(summary);
72         }
73
74         summary = getSummary(REPORT_PLUGIN_CPU);
75         if (summary != null && summary.size() > 0) {
76             writeCpuSummary(summary);
77         }
78
79     }
80
81     protected void writeThroughputSummary(Map JavaDoc summary) {
82         writeHeader("SYSTEM THROUGHPUT SUMMARY");
83         System.out.println("[PERF-TP-SUMMARY] System Total Throughput: " + summary.get(ThroughputReportPlugin.KEY_SYS_TOTAL_TP));
84         System.out.println("[PERF-TP-SUMMARY] System Total Clients: " + summary.get(ThroughputReportPlugin.KEY_SYS_TOTAL_CLIENTS));
85         System.out.println("[PERF-TP-SUMMARY] System Average Throughput: " + summary.get(ThroughputReportPlugin.KEY_SYS_AVE_TP));
86         System.out.println("[PERF-TP-SUMMARY] System Average Throughput Excluding Min/Max: " + summary.get(ThroughputReportPlugin.KEY_SYS_AVE_EMM_TP));
87         System.out.println("[PERF-TP-SUMMARY] System Average Client Throughput: " + summary.get(ThroughputReportPlugin.KEY_SYS_AVE_CLIENT_TP));
88         System.out.println("[PERF-TP-SUMMARY] System Average Client Throughput Excluding Min/Max: " + summary.get(ThroughputReportPlugin.KEY_SYS_AVE_CLIENT_EMM_TP));
89         System.out.println("[PERF-TP-SUMMARY] Min Client Throughput Per Sample: " + summary.get(ThroughputReportPlugin.KEY_MIN_CLIENT_TP));
90         System.out.println("[PERF-TP-SUMMARY] Max Client Throughput Per Sample: " + summary.get(ThroughputReportPlugin.KEY_MAX_CLIENT_TP));
91         System.out.println("[PERF-TP-SUMMARY] Min Client Total Throughput: " + summary.get(ThroughputReportPlugin.KEY_MIN_CLIENT_TOTAL_TP));
92         System.out.println("[PERF-TP-SUMMARY] Max Client Total Throughput: " + summary.get(ThroughputReportPlugin.KEY_MAX_CLIENT_TOTAL_TP));
93         System.out.println("[PERF-TP-SUMMARY] Min Client Average Throughput: " + summary.get(ThroughputReportPlugin.KEY_MIN_CLIENT_AVE_TP));
94         System.out.println("[PERF-TP-SUMMARY] Max Client Average Throughput: " + summary.get(ThroughputReportPlugin.KEY_MAX_CLIENT_AVE_TP));
95         System.out.println("[PERF-TP-SUMMARY] Min Client Average Throughput Excluding Min/Max: " + summary.get(ThroughputReportPlugin.KEY_MIN_CLIENT_AVE_EMM_TP));
96         System.out.println("[PERF-TP-SUMMARY] Max Client Average Throughput Excluding Min/Max: " + summary.get(ThroughputReportPlugin.KEY_MAX_CLIENT_AVE_EMM_TP));
97     }
98
99     protected void writeCpuSummary(Map JavaDoc summary) {
100         writeHeader("SYSTEM CPU USAGE SUMMARY");
101         System.out.println("[PERF-CPU-SUMMARY] Total Blocks Received: " + summary.get(CpuReportPlugin.KEY_BLOCK_RECV));
102         System.out.println("[PERF-CPU-SUMMARY] Ave Blocks Received: " + summary.get(CpuReportPlugin.KEY_AVE_BLOCK_RECV));
103
104         System.out.println("[PERF-CPU-SUMMARY] Total Blocks Sent: " + summary.get(CpuReportPlugin.KEY_BLOCK_SENT));
105         System.out.println("[PERF-CPU-SUMMARY] Ave Blocks Sent: " + summary.get(CpuReportPlugin.KEY_AVE_BLOCK_SENT));
106
107         System.out.println("[PERF-CPU-SUMMARY] Total Context Switches: " + summary.get(CpuReportPlugin.KEY_CTX_SWITCH));
108         System.out.println("[PERF-CPU-SUMMARY] Ave Context Switches: " + summary.get(CpuReportPlugin.KEY_AVE_CTX_SWITCH));
109
110         System.out.println("[PERF-CPU-SUMMARY] Total User Time: " + summary.get(CpuReportPlugin.KEY_USER_TIME));
111         System.out.println("[PERF-CPU-SUMMARY] Ave User Time: " + summary.get(CpuReportPlugin.KEY_AVE_USER_TIME));
112
113         System.out.println("[PERF-CPU-SUMMARY] Total System Time: " + summary.get(CpuReportPlugin.KEY_SYS_TIME));
114         System.out.println("[PERF-CPU-SUMMARY] Ave System Time: " + summary.get(CpuReportPlugin.KEY_AVE_SYS_TIME));
115
116         System.out.println("[PERF-CPU-SUMMARY] Total Idle Time: " + summary.get(CpuReportPlugin.KEY_IDLE_TIME));
117         System.out.println("[PERF-CPU-SUMMARY] Ave Idle Time: " + summary.get(CpuReportPlugin.KEY_AVE_IDLE_TIME));
118
119         System.out.println("[PERF-CPU-SUMMARY] Total Wait Time: " + summary.get(CpuReportPlugin.KEY_WAIT_TIME));
120         System.out.println("[PERF-CPU-SUMMARY] Ave Wait Time: " + summary.get(CpuReportPlugin.KEY_AVE_WAIT_TIME));
121     }
122
123     protected void writeHeader(String JavaDoc header) {
124         char[] border = new char[header.length() + 8]; // +8 for spacing
125
Arrays.fill(border, '#');
126         String JavaDoc borderStr = new String JavaDoc(border);
127
128         System.out.println(borderStr);
129         System.out.println("# " + header + " #");
130         System.out.println(borderStr);
131     }
132
133 }
134
Popular Tags