1 23 24 package org.objectweb.clif.datacollector.lib; 25 26 27 import org.objectweb.clif.storage.api.ActionEvent; 28 import java.io.Serializable ; 29 30 31 45 public class InjectorDataCollector extends AbstractDataCollector 46 { 47 static public final String [] LABELS = { 48 "time frame (ms)", 49 "average response time (ms)", 50 "min response time (ms)", 51 "max response time (ms)", 52 "number of actions", 53 "action throughput (actions/s)", 54 "number of errors", 55 "error throughput (errors/s)", 56 "error rate (%)" }; 57 58 59 60 protected long statStartTime; 61 62 protected long successfullActions; 63 64 protected long errors; 65 66 protected long actionMinDuration; 67 68 protected long actionMaxDuration; 69 70 protected long actionTotalDuration; 71 72 protected long cumulativeSuccessfullActions; 73 74 protected long cumulativeErrors; 75 76 77 public InjectorDataCollector() 78 { 79 super(); 80 } 81 82 83 86 private void resetStats() 87 { 88 statStartTime = System.currentTimeMillis(); 89 successfullActions = 0; 90 errors = 0; 91 actionMinDuration = Long.MAX_VALUE; 92 actionMaxDuration = Long.MIN_VALUE; 93 actionTotalDuration = 0; 94 } 95 96 97 101 public void init(Serializable testId, String scenarioId) 102 { 103 super.init(testId, scenarioId); 104 resetStats(); 105 cumulativeSuccessfullActions = 0; 106 cumulativeErrors = 0; 107 } 108 109 110 113 public void add(ActionEvent event) 114 { 115 super.add(event); 116 if (event.isSuccessful()) 117 { 118 ++successfullActions; 119 actionTotalDuration += event.duration; 120 if (event.duration > actionMaxDuration) 121 { 122 actionMaxDuration = event.duration; 123 } 124 if (event.duration < actionMinDuration) 125 { 126 actionMinDuration = event.duration; 127 } 128 } 129 else 130 { 131 ++errors; 132 } 133 } 134 135 136 140 141 145 public long[] getStat() 146 { 147 long[] stats = new long[LABELS.length]; 148 stats[0] = System.currentTimeMillis() - statStartTime; 150 if (successfullActions == 0) 152 { 153 stats[1] = 0; stats[2] = 0; stats[3] = 0; if (errors == 0) { 159 stats[8] = 0; 160 } 161 else 162 { 163 stats[8] = 100; 164 } 165 } 166 else 167 { 168 stats[1] = actionTotalDuration / successfullActions; stats[2] = actionMinDuration; stats[3] = actionMaxDuration; stats[8] = (errors * 100) / (successfullActions + errors); } 173 cumulativeSuccessfullActions += successfullActions; 174 stats[4] = cumulativeSuccessfullActions; 175 stats[5] = (successfullActions * 1000) / stats[0]; 177 cumulativeErrors += errors; 178 stats[6] = cumulativeErrors; 179 stats[7] = (errors * 1000) / stats[0]; 181 resetStats(); 182 return stats; 183 } 184 185 186 public String [] getLabels() 187 { 188 return LABELS; 189 } 190 } 191 | Popular Tags |