001: package org.jgroups.tests.perf;
002:
003: import org.jgroups.util.Streamable;
004: import org.jgroups.util.Util;
005:
006: import java.io.DataInputStream;
007: import java.io.DataOutputStream;
008: import java.io.IOException;
009: import java.text.NumberFormat;
010:
011: /**
012: * @author Bela Ban Jan 22
013: * @author 2004
014: * @version $Id: MemberInfo.java,v 1.8 2006/09/04 12:38:41 belaban Exp $
015: */
016: public class MemberInfo implements Streamable {
017: public long start = 0;
018: public long stop = 0;
019: public long num_msgs_expected = 0;
020: public long num_msgs_received = 0;
021: boolean done = false;
022: long total_bytes_received = 0;
023:
024: static NumberFormat f;
025:
026: static {
027: f = NumberFormat.getNumberInstance();
028: f.setGroupingUsed(false);
029: f.setMaximumFractionDigits(2);
030: }
031:
032: public MemberInfo() {
033: }
034:
035: public MemberInfo(long num_msgs_expected) {
036: this .num_msgs_expected = num_msgs_expected;
037: }
038:
039: public double getMessageSec() {
040: long total_time = stop - start;
041: return num_msgs_received / (total_time / 1000.0);
042: }
043:
044: // public String toString() {
045: // StringBuffer sb=new StringBuffer();
046: // double msgs_sec, throughput_kb=0, throughput_mb=0, kb_received=0, mb_received=0;
047: // long total_time=stop-start;
048: // double loss_rate=0;
049: // long missing_msgs=num_msgs_expected - num_msgs_received;
050: // kb_received=total_bytes_received/1000.0;
051: // if(kb_received >= 1000)
052: // mb_received=kb_received / 1000.0;
053: // msgs_sec=num_msgs_received / (total_time/1000.0);
054: // throughput_kb=kb_received / (total_time / 1000.0);
055: // if(throughput_kb >= 1000)
056: // throughput_mb=throughput_kb / 1000.0;
057: // loss_rate=missing_msgs >= num_msgs_expected? 100.0 : (100.0 / num_msgs_expected) * missing_msgs;
058: // sb.append("num_msgs_expected=").append(num_msgs_expected).append(", num_msgs_received=");
059: // sb.append(num_msgs_received);
060: // sb.append(" (loss rate=").append(loss_rate).append("%)");
061: // if(mb_received > 0)
062: // sb.append(", received=").append(f.format(mb_received)).append("MB");
063: // else
064: // sb.append(", received=").append(f.format(kb_received)).append("KB");
065: // sb.append(", time=").append(f.format(total_time)).append("ms");
066: // sb.append(", msgs/sec=").append(f.format(msgs_sec));
067: // if(throughput_mb > 0)
068: // sb.append(", throughput=").append(f.format(throughput_mb)).append("MB/sec");
069: // else
070: // sb.append(", throughput=").append(f.format(throughput_kb)).append("KB/sec");
071: // return sb.toString();
072: // }
073:
074: public String toString() {
075: StringBuffer sb = new StringBuffer();
076: double msgs_sec, throughput = 0;
077: long total_time = stop - start;
078: double loss_rate = 0;
079: long missing_msgs = num_msgs_expected - num_msgs_received;
080: msgs_sec = num_msgs_received / (total_time / 1000.0);
081: throughput = total_bytes_received / (total_time / 1000.0);
082: loss_rate = missing_msgs >= num_msgs_expected ? 100.0
083: : (100.0 / num_msgs_expected) * missing_msgs;
084: sb.append("num_msgs_expected=").append(num_msgs_expected)
085: .append(", num_msgs_received=");
086: sb.append(num_msgs_received);
087: sb.append(" (loss rate=").append(loss_rate).append("%)");
088: sb.append(", received=").append(
089: Util.printBytes(total_bytes_received));
090: sb.append(", time=").append(f.format(total_time)).append("ms");
091: sb.append(", msgs/sec=").append(f.format(msgs_sec));
092: sb.append(", throughput=").append(Util.printBytes(throughput));
093: return sb.toString();
094: }
095:
096: public void writeTo(DataOutputStream out) throws IOException {
097: out.writeLong(start);
098: out.writeLong(stop);
099: out.writeLong(num_msgs_expected);
100: out.writeLong(num_msgs_received);
101: out.writeBoolean(done);
102: out.writeLong(total_bytes_received);
103: }
104:
105: public void readFrom(DataInputStream in) throws IOException,
106: IllegalAccessException, InstantiationException {
107: start = in.readLong();
108: stop = in.readLong();
109: num_msgs_expected = in.readLong();
110: num_msgs_received = in.readLong();
111: done = in.readBoolean();
112: total_bytes_received = in.readLong();
113:
114: }
115: }
|