001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.activemq.tool.reports;
018
019import java.util.Arrays;
020import java.util.Iterator;
021import java.util.Map;
022import java.util.Properties;
023
024import org.apache.activemq.tool.reports.plugins.CpuReportPlugin;
025import org.apache.activemq.tool.reports.plugins.ThroughputReportPlugin;
026
027public class VerbosePerfReportWriter extends AbstractPerfReportWriter {
028
029    public void openReportWriter() {
030        // Do nothing
031    }
032
033    public void closeReportWriter() {
034        writeHeader("Performance Summary");
035        writePerfSummary();
036    }
037
038    public void writeInfo(String info) {
039        System.out.println("[PERF-INFO]: " + info);
040    }
041
042    public void writeCsvData(int csvType, String csvData) {
043        if (csvType == REPORT_PLUGIN_THROUGHPUT) {
044            System.out.println("[PERF-TP]: " + csvData);
045        } else if (csvType == REPORT_PLUGIN_CPU) {
046            System.out.println("[PERF-CPU]: " + csvData);
047        }
048        handleCsvData(csvType, csvData);
049    }
050
051    public void writeProperties(String header, Properties props) {
052        writeHeader(header);
053        writeProperties(props);
054    }
055
056    public void writeProperties(Properties props) {
057        for (Iterator i = props.keySet().iterator(); i.hasNext();) {
058            String key = (String)i.next();
059            String val = props.getProperty(key, "");
060            System.out.println("[PERF-PROP]: " + key + "=" + val);
061        }
062    }
063
064    public void writePerfSummary() {
065
066        Map summary;
067
068        summary = getSummary(REPORT_PLUGIN_THROUGHPUT);
069        if (summary != null && summary.size() > 0) {
070            writeThroughputSummary(summary);
071        }
072
073        summary = getSummary(REPORT_PLUGIN_CPU);
074        if (summary != null && summary.size() > 0) {
075            writeCpuSummary(summary);
076        }
077
078    }
079
080    protected void writeThroughputSummary(Map summary) {
081        writeHeader("SYSTEM THROUGHPUT SUMMARY");
082        System.out.println("[PERF-TP-SUMMARY] System Total Throughput: " + summary.get(ThroughputReportPlugin.KEY_SYS_TOTAL_TP));
083        System.out.println("[PERF-TP-SUMMARY] System Total Clients: " + summary.get(ThroughputReportPlugin.KEY_SYS_TOTAL_CLIENTS));
084        System.out.println("[PERF-TP-SUMMARY] System Average Throughput: " + summary.get(ThroughputReportPlugin.KEY_SYS_AVE_TP));
085        System.out.println("[PERF-TP-SUMMARY] System Average Throughput Excluding Min/Max: " + summary.get(ThroughputReportPlugin.KEY_SYS_AVE_EMM_TP));
086        System.out.println("[PERF-TP-SUMMARY] System Average Client Throughput: " + summary.get(ThroughputReportPlugin.KEY_SYS_AVE_CLIENT_TP));
087        System.out.println("[PERF-TP-SUMMARY] System Average Client Throughput Excluding Min/Max: " + summary.get(ThroughputReportPlugin.KEY_SYS_AVE_CLIENT_EMM_TP));
088        System.out.println("[PERF-TP-SUMMARY] Min Client Throughput Per Sample: " + summary.get(ThroughputReportPlugin.KEY_MIN_CLIENT_TP));
089        System.out.println("[PERF-TP-SUMMARY] Max Client Throughput Per Sample: " + summary.get(ThroughputReportPlugin.KEY_MAX_CLIENT_TP));
090        System.out.println("[PERF-TP-SUMMARY] Min Client Total Throughput: " + summary.get(ThroughputReportPlugin.KEY_MIN_CLIENT_TOTAL_TP));
091        System.out.println("[PERF-TP-SUMMARY] Max Client Total Throughput: " + summary.get(ThroughputReportPlugin.KEY_MAX_CLIENT_TOTAL_TP));
092        System.out.println("[PERF-TP-SUMMARY] Min Client Average Throughput: " + summary.get(ThroughputReportPlugin.KEY_MIN_CLIENT_AVE_TP));
093        System.out.println("[PERF-TP-SUMMARY] Max Client Average Throughput: " + summary.get(ThroughputReportPlugin.KEY_MAX_CLIENT_AVE_TP));
094        System.out.println("[PERF-TP-SUMMARY] Min Client Average Throughput Excluding Min/Max: " + summary.get(ThroughputReportPlugin.KEY_MIN_CLIENT_AVE_EMM_TP));
095        System.out.println("[PERF-TP-SUMMARY] Max Client Average Throughput Excluding Min/Max: " + summary.get(ThroughputReportPlugin.KEY_MAX_CLIENT_AVE_EMM_TP));
096    }
097
098    protected void writeCpuSummary(Map summary) {
099        writeHeader("SYSTEM CPU USAGE SUMMARY");
100        System.out.println("[PERF-CPU-SUMMARY] Total Blocks Received: " + summary.get(CpuReportPlugin.KEY_BLOCK_RECV));
101        System.out.println("[PERF-CPU-SUMMARY] Ave Blocks Received: " + summary.get(CpuReportPlugin.KEY_AVE_BLOCK_RECV));
102
103        System.out.println("[PERF-CPU-SUMMARY] Total Blocks Sent: " + summary.get(CpuReportPlugin.KEY_BLOCK_SENT));
104        System.out.println("[PERF-CPU-SUMMARY] Ave Blocks Sent: " + summary.get(CpuReportPlugin.KEY_AVE_BLOCK_SENT));
105
106        System.out.println("[PERF-CPU-SUMMARY] Total Context Switches: " + summary.get(CpuReportPlugin.KEY_CTX_SWITCH));
107        System.out.println("[PERF-CPU-SUMMARY] Ave Context Switches: " + summary.get(CpuReportPlugin.KEY_AVE_CTX_SWITCH));
108
109        System.out.println("[PERF-CPU-SUMMARY] Total User Time: " + summary.get(CpuReportPlugin.KEY_USER_TIME));
110        System.out.println("[PERF-CPU-SUMMARY] Ave User Time: " + summary.get(CpuReportPlugin.KEY_AVE_USER_TIME));
111
112        System.out.println("[PERF-CPU-SUMMARY] Total System Time: " + summary.get(CpuReportPlugin.KEY_SYS_TIME));
113        System.out.println("[PERF-CPU-SUMMARY] Ave System Time: " + summary.get(CpuReportPlugin.KEY_AVE_SYS_TIME));
114
115        System.out.println("[PERF-CPU-SUMMARY] Total Idle Time: " + summary.get(CpuReportPlugin.KEY_IDLE_TIME));
116        System.out.println("[PERF-CPU-SUMMARY] Ave Idle Time: " + summary.get(CpuReportPlugin.KEY_AVE_IDLE_TIME));
117
118        System.out.println("[PERF-CPU-SUMMARY] Total Wait Time: " + summary.get(CpuReportPlugin.KEY_WAIT_TIME));
119        System.out.println("[PERF-CPU-SUMMARY] Ave Wait Time: " + summary.get(CpuReportPlugin.KEY_AVE_WAIT_TIME));
120    }
121
122    protected void writeHeader(String header) {
123        char[] border = new char[header.length() + 8]; // +8 for spacing
124        Arrays.fill(border, '#');
125        String borderStr = new String(border);
126
127        System.out.println(borderStr);
128        System.out.println("#   " + header + "   #");
129        System.out.println(borderStr);
130    }
131
132}