1 | package simulator.stats; |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | import java.io.File; |
---|
6 | import java.io.FileOutputStream; |
---|
7 | import java.io.IOException; |
---|
8 | import java.io.PrintStream; |
---|
9 | import java.util.ArrayList; |
---|
10 | import java.util.List; |
---|
11 | |
---|
12 | import simulator.stats.implementation.DCWormsStatistics; |
---|
13 | import gridsim.Accumulator; |
---|
14 | |
---|
15 | |
---|
16 | public class AccumulatedStatistics { |
---|
17 | |
---|
18 | protected static final String ACCUMULATED_SIMULATIONS_STATISTICS_OUTPUT_FILE_NAME = "Stats_Accumulated_Simulations.txt"; |
---|
19 | |
---|
20 | protected List<SimulationStatistics> simulations; |
---|
21 | |
---|
22 | public AccumulatedStatistics(int noOfSimulations) { |
---|
23 | simulations = new ArrayList<SimulationStatistics>(noOfSimulations); |
---|
24 | } |
---|
25 | |
---|
26 | public AccumulatedStatistics() { |
---|
27 | simulations = new ArrayList<SimulationStatistics>(); |
---|
28 | } |
---|
29 | |
---|
30 | public void add(SimulationStatistics simulationStatistics) { |
---|
31 | simulations.add(simulationStatistics); |
---|
32 | } |
---|
33 | |
---|
34 | public void saveStatistics() { |
---|
35 | |
---|
36 | SimulationStatistics simulationStatisticsNew = simulations.get(0); |
---|
37 | |
---|
38 | if(!simulationStatisticsNew.accumulatedStats()) |
---|
39 | return; |
---|
40 | String dirName = simulationStatisticsNew.getOutputFolderName(); |
---|
41 | if(dirName == null) |
---|
42 | return; |
---|
43 | |
---|
44 | PrintStream out = null; |
---|
45 | try { |
---|
46 | File file = new File(dirName + ACCUMULATED_SIMULATIONS_STATISTICS_OUTPUT_FILE_NAME); |
---|
47 | out = new PrintStream(new FileOutputStream(file)); |
---|
48 | } catch (IOException e) { |
---|
49 | e.printStackTrace(); |
---|
50 | } |
---|
51 | |
---|
52 | GSSAccumulator resourceLoad = getAccumulatedResourceLoad(); |
---|
53 | GSSAccumulator reservationLoad = getAccumulatedReservationLoad(); |
---|
54 | GSSAccumulator makespan = getAccumulatedMakespan(); |
---|
55 | GSSAccumulator taskExecutionTime = getAccumulatedJobExecutionTime(); |
---|
56 | GSSAccumulator taskQueueLength = getAccumulatedQueueJobCount(); |
---|
57 | GSSAccumulator taskCompletionTime = getAccumulatedCompletionTime(); |
---|
58 | GSSAccumulator taskWaitingTime = getAccumulatedWaitingTime(); |
---|
59 | GSSAccumulator taskFlowTime = getAccumulatedJobFlowTime(); |
---|
60 | GSSAccumulator taskLateness = getAccumulatedLateness(); |
---|
61 | GSSAccumulator delayedTasks = getAccumulatedDelayedTasks(); |
---|
62 | GSSAccumulator taskTardiness = getAccumulatedTardiness(); |
---|
63 | GSSAccumulator failedRequests = getAccumulatedFailedRequests(); |
---|
64 | |
---|
65 | out.print("Delayed tasks (accumulated)"); |
---|
66 | out.println(delayedTasks); |
---|
67 | out.print("Failed requests (accumulated)"); |
---|
68 | out.println(failedRequests); |
---|
69 | out.print("Makespan (accumulated)"); |
---|
70 | out.println(makespan); |
---|
71 | out.print("Resources queue length (accumulated)"); |
---|
72 | out.println(taskQueueLength); |
---|
73 | out.print("Mean (accumulated) resource load"); |
---|
74 | out.println(resourceLoad); |
---|
75 | out.print("Mean (accumulated) reservation load"); |
---|
76 | out.println(reservationLoad); |
---|
77 | out.print("Task completion time (accumulated)"); |
---|
78 | out.println(taskCompletionTime); |
---|
79 | out.print("Task execution time (accumulated)"); |
---|
80 | out.println(taskExecutionTime); |
---|
81 | out.print("Task flow time (accumulated)"); |
---|
82 | out.println(taskFlowTime); |
---|
83 | out.print("Task waiting time (accumulated)"); |
---|
84 | out.println(taskWaitingTime); |
---|
85 | out.print("Task lateness (accumulated)"); |
---|
86 | out.println(taskLateness); |
---|
87 | out.print("Task tardiness (accumulated)"); |
---|
88 | out.println(taskTardiness); |
---|
89 | out.println(); |
---|
90 | out.close(); |
---|
91 | } |
---|
92 | |
---|
93 | public GSSAccumulator getAccumulatedResourceLoad() { |
---|
94 | GSSAccumulator resourceMeanLoad = new GSSAccumulator(); |
---|
95 | for (SimulationStatistics simStat : simulations) { |
---|
96 | GSSAccumulator simulationResTotalLoad = simStat.getStats(SimulationStatistics.RESOURCES_TOTAL_LOAD); |
---|
97 | resourceMeanLoad.add(simulationResTotalLoad.getMean()); |
---|
98 | } |
---|
99 | return resourceMeanLoad; |
---|
100 | } |
---|
101 | |
---|
102 | public GSSAccumulator getAccumulatedReservationLoad(){ |
---|
103 | GSSAccumulator reservationMean = new GSSAccumulator(); |
---|
104 | for (SimulationStatistics simStat : simulations) { |
---|
105 | Accumulator simulationResvTotalLoad = simStat.getStats(SimulationStatistics.RESOURCES_RESERVATION_LOAD); |
---|
106 | reservationMean.add(simulationResvTotalLoad.getMean()); |
---|
107 | } |
---|
108 | return reservationMean; |
---|
109 | } |
---|
110 | |
---|
111 | /*public GSSAccumulator getAccumulatedBokrerThroughput() { |
---|
112 | GSSAccumulator meanThroughput = new GSSAccumulator(); |
---|
113 | |
---|
114 | for (SimulationStatisticsNew simStat : simulations) { |
---|
115 | double simulationMeanThroughput = simStat.getBrokerStats().average(Sim_stat.THROUGHPUT); |
---|
116 | meanThroughput.add(simulationMeanThroughput); |
---|
117 | } |
---|
118 | return meanThroughput; |
---|
119 | }*/ |
---|
120 | |
---|
121 | public GSSAccumulator getAccumulatedJobFlowTime() { |
---|
122 | GSSAccumulator meanJobFlowTime = new GSSAccumulator(); |
---|
123 | for (SimulationStatistics simStat : simulations) { |
---|
124 | Accumulator simulationJobFlowTime = simStat.getStats(SimulationStatistics.TASK_FLOW_TIME); |
---|
125 | meanJobFlowTime.add(simulationJobFlowTime.getMean()); |
---|
126 | } |
---|
127 | return meanJobFlowTime; |
---|
128 | } |
---|
129 | |
---|
130 | public GSSAccumulator getAccumulatedLateness() { |
---|
131 | GSSAccumulator meanLateness = new GSSAccumulator(); |
---|
132 | for (SimulationStatistics simStat : simulations) { |
---|
133 | Accumulator simulationLateness = simStat.getStats(SimulationStatistics.TASK_LATENESS); |
---|
134 | meanLateness.add(simulationLateness.getMean()); |
---|
135 | } |
---|
136 | return meanLateness; |
---|
137 | } |
---|
138 | |
---|
139 | public GSSAccumulator getAccumulatedFailedRequests() { |
---|
140 | GSSAccumulator meanFailedRequests = new GSSAccumulator(); |
---|
141 | for (SimulationStatistics simStat : simulations) { |
---|
142 | Accumulator simulationFailedRequestes = simStat.getStats(SimulationStatistics.FAILED_REQUESTS); |
---|
143 | meanFailedRequests.add(simulationFailedRequestes.getMean()); |
---|
144 | } |
---|
145 | return meanFailedRequests; |
---|
146 | } |
---|
147 | |
---|
148 | public GSSAccumulator getAccumulatedTardiness() { |
---|
149 | GSSAccumulator meanTardiness = new GSSAccumulator(); |
---|
150 | for (SimulationStatistics simStat : simulations) { |
---|
151 | Accumulator simulationJobTardiness = simStat.getStats(SimulationStatistics.TASK_TARDINESS); |
---|
152 | meanTardiness.add(simulationJobTardiness.getMean()); |
---|
153 | } |
---|
154 | return meanTardiness; |
---|
155 | } |
---|
156 | |
---|
157 | public GSSAccumulator getAccumulatedDelayedTasks() { |
---|
158 | GSSAccumulator delayedTasks = new GSSAccumulator(); |
---|
159 | for (SimulationStatistics simStat : simulations) { |
---|
160 | Accumulator simulationDelayedTasks = simStat.getStats(SimulationStatistics.DELAYED_TASKS); |
---|
161 | delayedTasks.add(simulationDelayedTasks.getMean()); |
---|
162 | } |
---|
163 | return delayedTasks; |
---|
164 | } |
---|
165 | |
---|
166 | public GSSAccumulator getAccumulatedCompletionTime() { |
---|
167 | GSSAccumulator meanJobCompletionTime = new GSSAccumulator(); |
---|
168 | |
---|
169 | for (SimulationStatistics simStat : simulations) { |
---|
170 | Accumulator simulationJobTurnaroundTime = simStat.getStats(SimulationStatistics.TASK_COMPLETION_TIME); |
---|
171 | meanJobCompletionTime.add(simulationJobTurnaroundTime.getMean()); |
---|
172 | } |
---|
173 | return meanJobCompletionTime; |
---|
174 | } |
---|
175 | |
---|
176 | public GSSAccumulator getAccumulatedMakespan() { |
---|
177 | GSSAccumulator meanMakespan = new GSSAccumulator(); |
---|
178 | for (SimulationStatistics simStat : simulations) { |
---|
179 | meanMakespan.add(simStat.getStats(SimulationStatistics.MAKESPAN).getMean()); |
---|
180 | } |
---|
181 | return meanMakespan; |
---|
182 | } |
---|
183 | |
---|
184 | public GSSAccumulator getAccumulatedWaitingTime() { |
---|
185 | GSSAccumulator meanWaitingTime = new GSSAccumulator(); |
---|
186 | for (SimulationStatistics simStat : simulations) |
---|
187 | meanWaitingTime.add(simStat.getStats(SimulationStatistics.TASK_WAITING_TIME).getMean()); |
---|
188 | return meanWaitingTime; |
---|
189 | } |
---|
190 | |
---|
191 | public GSSAccumulator getAccumulatedJobExecutionTime() { |
---|
192 | GSSAccumulator meanJobExecutionTime = new GSSAccumulator(); |
---|
193 | for (SimulationStatistics simStat : simulations) |
---|
194 | meanJobExecutionTime.add(simStat.getStats(SimulationStatistics.TASK_EXECUTION_TIME).getMean()); |
---|
195 | return meanJobExecutionTime; |
---|
196 | } |
---|
197 | |
---|
198 | public GSSAccumulator getAccumulatedQueueJobCount() { |
---|
199 | GSSAccumulator meanQueuJobCount = new GSSAccumulator(); |
---|
200 | for (SimulationStatistics simStat : simulations) |
---|
201 | meanQueuJobCount.add(simStat.getStats(SimulationStatistics.RESOURCES_QUEUE_LENGTH).getMean()); |
---|
202 | return meanQueuJobCount; |
---|
203 | } |
---|
204 | |
---|
205 | } |
---|