1 package org.jacorb.test.notification.perf; 2 3 import java.util.Hashtable ; 4 import java.util.Iterator ; 5 import java.util.Map ; 6 7 import org.omg.CORBA.Any ; 8 import org.omg.CosNotification.StructuredEvent; 9 10 import org.jacorb.test.notification.TimingTest; 11 import org.jacorb.test.notification.TimingTestHelper; 12 import org.jacorb.test.notification.PerformanceListener; 13 14 class PerformanceLogger implements PerformanceListener 15 { 16 17 private long minimum = Long.MAX_VALUE; 18 public long getMinimum() 19 { 20 calc(); 21 return minimum; 22 } 23 24 private long maximum = 0; 25 public long getMaximum() 26 { 27 calc(); 28 return maximum; 29 } 30 31 private long average = 0; 32 public long getAverage() 33 { 34 calc(); 35 return average; 36 } 37 38 39 private boolean calced_ = false; 40 41 class LogEntry 42 { 43 long receiveTime; 44 long sendTime; 45 long getTotalTime() 46 { 47 return receiveTime - sendTime; 48 } 49 } 50 51 Map allEntries_ = new Hashtable (); 52 53 public void calc() 54 { 55 if ( calced_ ) 56 { 57 return ; 58 } 59 60 minimum = Long.MAX_VALUE; 61 maximum = 0; 62 average = 0; 63 int _sum = 0; 64 65 Iterator _i = allEntries_.values().iterator(); 66 67 while ( _i.hasNext() ) 68 { 69 LogEntry _e = ( LogEntry ) _i.next(); 70 long _v = _e.getTotalTime(); 71 72 if ( _v > maximum ) 73 { 74 maximum = _v; 75 } 76 77 if ( _v < minimum ) 78 { 79 minimum = _v; 80 } 81 82 _sum += _v; 83 } 84 85 average = _sum / allEntries_.size(); 86 87 calced_ = true; 88 } 89 90 public String toString() 91 { 92 StringBuffer _b = new StringBuffer (); 93 94 _b.append( "Number of Events: " + allEntries_.size() ); 95 _b.append( "\n" ); 96 int size = allEntries_.size(); 97 98 calc(); 99 100 _b.append( "Min: " + minimum ); 101 _b.append( "\n" ); 102 _b.append( "Max: " + maximum ); 103 _b.append( "\n" ); 104 _b.append( "Avg: " + average ); 105 106 return _b.toString(); 107 } 108 109 public void eventSent( Any event, long currentTime, long took ) 110 { 111 } 121 122 public void eventReceived( StructuredEvent event, long currentTime ) 123 { 124 eventReceived( event.remainder_of_body, currentTime ); 125 } 126 127 public void eventReceived( Any event, long currentTime ) 128 { 129 TimingTest _t = TimingTestHelper.extract( event ); 130 Integer _key = new Integer ( _t.id ); 131 132 synchronized ( allEntries_ ) 133 { 134 LogEntry _entry = ( LogEntry ) allEntries_.get( _key ); 135 136 if ( _entry == null ) 137 { 138 _entry = new LogEntry(); 139 } 140 141 _entry.sendTime = _t.currentTime; 142 _entry.receiveTime = ( int ) currentTime; 143 allEntries_.put( _key, _entry ); 144 } 145 } 146 147 public void eventFailed( Any event, Exception e ) 148 {} 149 150 } 151 | Popular Tags |