001: package org.cougaar.core.qos.profile;
002:
003: import java.lang.reflect.*;
004: import java.io.*;
005: import java.text.*;
006: import java.util.*;
007: import java.util.regex.*;
008: import org.cougaar.core.agent.*;
009: import org.cougaar.core.component.*;
010: import org.cougaar.core.mts.*;
011: import org.cougaar.core.node.*;
012: import org.cougaar.core.qos.metrics.*;
013: import org.cougaar.core.service.*;
014: import org.cougaar.core.service.wp.*;
015: import org.cougaar.core.thread.*;
016: import org.cougaar.core.wp.resolver.*;
017: import org.cougaar.util.*;
018:
019: /**
020: * This component profiles the aggregate message traffic of
021: * all local agents to any target.
022: * <p>
023: * Example output:<pre>
024: * nt - #send_avg_queue_len,
025: * send_msg_bytes, send_header_bytes, send_ack_bytes, send_bytes, send_node_count, send_count,
026: * recv_msg_bytes, recv_header_bytes, recv_ack_bytes, recv_bytes, recv_node_count, recv_count,
027: * histogram_100_bytes, histogram_200_bytes, histogram_500_bytes, histogram_1000_bytes, histogram_2000_bytes, histogram_5000_bytes, histogram_10000_bytes, histogram_20000_bytes, histogram_50000_bytes, histogram_100000_bytes, histogram_200000_bytes, histogram_500000_bytes, histogram_1000000_bytes, histogram_2000000_bytes, histogram_5000000_bytes, histogram_10000000_bytes,
028: * nt - 0.87,
029: * 228327741, 87931736, 87931242, 404190719, 552, 178546,
030: * 161952252, 87931242, 93093562, 342977056, 552, 178545,
031: * 0, 0, 2, 70, 177922, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
032: * <pre>
033: *
034: * @see ProfilerCoordinator required coordinator component
035: */
036: public class NodeTraffic extends ProfilerBase {
037: private static final DecimalFormat FORMAT_DECIMAL = new DecimalFormat(
038: "#0.00");
039: private static final String[] FIELDS;
040: static {
041: List l = new ArrayList();
042: l.add("send_avg_queue_len");
043: l.add("send_msg_bytes");
044: l.add("send_header_bytes");
045: l.add("send_ack_bytes");
046: l.add("send_bytes");
047: l.add("send_node_count");
048: l.add("send_count");
049: l.add("recv_msg_bytes");
050: l.add("recv_header_bytes");
051: l.add("recv_ack_bytes");
052: l.add("recv_bytes");
053: l.add("recv_node_count");
054: l.add("recv_count");
055: for (int i = 1; i < MessageStatistics.NBINS; i++) {
056: l.add("histogram_" + MessageStatistics.BIN_SIZES[i]
057: + "_bytes");
058: }
059: FIELDS = (String[]) l.toArray(new String[0]);
060: };
061: private static final String HEADER = toHeader(FIELDS);
062:
063: public MessageStatisticsService mss;
064:
065: public void load() {
066: super .load();
067: findServiceLater("mss",
068: "org.cougaar.core.service.MessageStatisticsService");
069: }
070:
071: public void run() {
072: log("org.cougaar.core.qos.profile.node_traffic.nt", HEADER,
073: getNodeTraffic());
074: }
075:
076: private String getNodeTraffic() {
077: final MessageStatistics.Statistics stats = mss
078: .getMessageStatistics(false);
079: if (stats == null) {
080: return "err";
081: }
082: StringBuffer buf = new StringBuffer();
083: buf.append(
084: FORMAT_DECIMAL.format(stats.averageMessageQueueLength))
085: .append(", ");
086: long[] numbers = new long[] {
087: stats.totalSentMessageBytes,
088: stats.totalSentHeaderBytes,
089: stats.totalSentAckBytes,
090: (stats.totalSentMessageBytes
091: + stats.totalSentHeaderBytes + stats.totalSentAckBytes),
092: stats.histogram[0],
093: stats.totalSentMessageCount,
094: stats.totalRecvMessageBytes,
095: stats.totalRecvHeaderBytes,
096: stats.totalRecvAckBytes,
097: (stats.totalRecvMessageBytes
098: + stats.totalRecvHeaderBytes + stats.totalRecvAckBytes),
099: stats.histogram[0], stats.totalRecvMessageCount, };
100: for (int i = 0; i < numbers.length; i++) {
101: buf.append(numbers[i]).append(", ");
102: }
103: for (int i = 1; i < MessageStatistics.NBINS; i++) {
104: buf.append(stats.histogram[i]).append(", ");
105: }
106: return buf.toString();
107: }
108: }
|