KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > tests > perf > MemberInfo


1 package org.jgroups.tests.perf;
2
3 import java.io.Serializable JavaDoc;
4 import java.text.NumberFormat JavaDoc;
5
6 /**
7  * @author Bela Ban Jan 22
8  * @author 2004
9  * @version $Id: MemberInfo.java,v 1.3 2004/01/24 16:56:35 belaban Exp $
10  */

11 public class MemberInfo implements Serializable JavaDoc {
12     public long start=0;
13     public long stop=0;
14     public long num_msgs_expected=0;
15     public long num_msgs_received=0;
16     boolean done=false;
17     long total_bytes_received=0;
18     static NumberFormat JavaDoc f;
19
20     static {
21         f=NumberFormat.getNumberInstance();
22         f.setGroupingUsed(false);
23         f.setMaximumFractionDigits(2);
24     }
25
26     public MemberInfo(long num_msgs_expected) {
27         this.num_msgs_expected=num_msgs_expected;
28     }
29
30     public String JavaDoc toString() {
31         StringBuffer JavaDoc sb=new StringBuffer JavaDoc();
32         double msgs_sec, throughput_kb=0, throughput_mb=0, kb_received=0, mb_received=0;
33         long total_time=stop-start;
34         double loss_rate=0;
35         long missing_msgs=num_msgs_expected - num_msgs_received;
36         kb_received=total_bytes_received/1000.0;
37         if(kb_received >= 1000)
38             mb_received=kb_received / 1000.0;
39         msgs_sec=num_msgs_received / (total_time/1000.0);
40         throughput_kb=kb_received / (total_time / 1000.0);
41         if(throughput_kb >= 1000)
42             throughput_mb=throughput_kb / 1000.0;
43         loss_rate=missing_msgs >= num_msgs_expected? 100.0 : (100.0 / num_msgs_expected) * missing_msgs;
44         sb.append("num_msgs_expected=").append(num_msgs_expected).append(", num_msgs_received=");
45         sb.append(num_msgs_received);
46         sb.append(" (loss rate=").append(f.format(loss_rate)).append("%)");
47         if(mb_received > 0)
48             sb.append(", received=").append(f.format(mb_received)).append("MB");
49         else
50             sb.append(", received=").append(f.format(kb_received)).append("KB");
51         sb.append(", time=").append(f.format(total_time)).append("ms");
52         sb.append(", msgs/sec=").append(f.format(msgs_sec));
53         if(throughput_mb > 0)
54             sb.append(", throughput=").append(f.format(throughput_mb)).append("MB/sec");
55         else
56             sb.append(", throughput=").append(f.format(throughput_kb)).append("KB/sec");
57         return sb.toString();
58     }
59 }
60
Popular Tags