[477] | 1 | package simulator.stats.implementation; |
---|
| 2 | |
---|
| 3 | |
---|
[1362] | 4 | import gridsim.dcworms.DCWormsTags; |
---|
| 5 | |
---|
[1567] | 6 | import java.util.ArrayList; |
---|
| 7 | import java.util.Collections; |
---|
| 8 | import java.util.Comparator; |
---|
[1207] | 9 | import java.util.HashSet; |
---|
| 10 | import java.util.Iterator; |
---|
[1567] | 11 | import java.util.List; |
---|
[1207] | 12 | import java.util.Set; |
---|
[1570] | 13 | import java.util.TreeSet; |
---|
[477] | 14 | |
---|
[1207] | 15 | import schedframe.resources.computing.ComputingResource; |
---|
| 16 | import schedframe.resources.computing.Core; |
---|
[1567] | 17 | import schedframe.resources.computing.Node; |
---|
[1207] | 18 | import schedframe.resources.computing.Processor; |
---|
[1362] | 19 | import schedframe.scheduling.ExecutionHistoryItem; |
---|
[477] | 20 | import simulator.stats.implementation.out.StatsSerializer; |
---|
[1207] | 21 | import dcworms.schedframe.scheduling.Executable; |
---|
[477] | 22 | |
---|
[1567] | 23 | |
---|
[477] | 24 | /** |
---|
| 25 | * |
---|
| 26 | * @author Marcin Krystek |
---|
| 27 | * |
---|
| 28 | */ |
---|
| 29 | public class TaskStats implements StatsInterface { |
---|
[1207] | 30 | protected Set<ComputingResource> processingElements; |
---|
[477] | 31 | protected double reservationStartDate; |
---|
| 32 | protected double reservationFinishDate; |
---|
| 33 | |
---|
| 34 | protected Executable task; |
---|
| 35 | protected long startSimulationTimeSek; |
---|
| 36 | |
---|
[1199] | 37 | private String headers[] = { "JobID", "TaskID", "UserDN", "SchedName", "CpuCnt", |
---|
[477] | 38 | "ExecStartDate", "ExecFinishDate", "ExecEndDate", "GB_SubDate", |
---|
| 39 | "LB_SubDate", "CompletionTime", "ExecStartTime", |
---|
| 40 | "ExecutionTime", "ReadyTime", "StartTime", "FlowTime", |
---|
| 41 | "WaitingTime", "GQ_WaitingTime", "Lateness", "Tardiness", |
---|
[1207] | 42 | "ReservStartDate", "ReservFinishDate", "HostNames", "ProcessorName", "Energy", "AppName",}; |
---|
[477] | 43 | |
---|
| 44 | public TaskStats(Executable task, long startSimulationTime) { |
---|
| 45 | this.task = task; |
---|
| 46 | this.startSimulationTimeSek = startSimulationTime / 1000; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | public Object serialize(StatsSerializer serializer) { |
---|
| 50 | return serializer.visit(this); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | public String getJobID() { |
---|
| 54 | return this.task.getJobId(); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | public String getTaskID() { |
---|
| 58 | return this.task.getId(); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | public String getUserDN() { |
---|
[480] | 62 | return this.task.getUserDN(); |
---|
[477] | 63 | } |
---|
| 64 | |
---|
| 65 | public String getResName() { |
---|
[481] | 66 | String resName = this.task.getSchedulerName(); |
---|
| 67 | |
---|
[477] | 68 | return resName; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | public long getCpuCnt() { |
---|
| 72 | long cpuCnt = -1; |
---|
| 73 | try { |
---|
| 74 | cpuCnt = Double.valueOf(task.getCpuCntRequest()).longValue(); |
---|
| 75 | } catch (NoSuchFieldException e) { |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | return cpuCnt; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | public double getExecStartDate() { |
---|
| 82 | return task.getExecStartTime(); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | public double getExecFinishDate() { |
---|
| 86 | return task.getFinishTime(); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | public double getExecEndDate() { |
---|
| 90 | double ret = -1; |
---|
| 91 | try { |
---|
| 92 | ret = task.getExecutionEndTime().getMillis() / 1000; |
---|
| 93 | } catch (NoSuchFieldException e) { |
---|
| 94 | ret = task.getFinishTime(); |
---|
| 95 | } |
---|
| 96 | return ret; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | public double getGB_SubDate() { |
---|
| 100 | return task.getSubmissionTimeToBroker().getMillis() / 1000; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | public double getLB_SubDate() { |
---|
| 104 | return task.getSubmissionTime(); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | public double getCompletionTime() { |
---|
| 108 | return task.getFinishTime() - startSimulationTimeSek; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | public double getExecutionTime() { |
---|
[1362] | 112 | double executionTime = 0; |
---|
| 113 | long previousTimestamp = 0; |
---|
| 114 | int previousStatus = DCWormsTags.CREATED; |
---|
[1396] | 115 | for(ExecutionHistoryItem execHistItem: task.getExecutionHistory()){ |
---|
[1362] | 116 | if(previousStatus == DCWormsTags.INEXEC){ |
---|
[1423] | 117 | executionTime = executionTime + (execHistItem.getTimeStamp()/1000 - previousTimestamp); |
---|
[1362] | 118 | } |
---|
[1423] | 119 | previousTimestamp = execHistItem.getTimeStamp()/1000; |
---|
[1362] | 120 | previousStatus = execHistItem.getStatus(); |
---|
| 121 | } |
---|
| 122 | return executionTime; |
---|
| 123 | //return task.getFinishTime() - task.getExecStartTime(); |
---|
[477] | 124 | } |
---|
| 125 | |
---|
| 126 | public double getExecStartTime() { |
---|
| 127 | return task.getExecStartTime() - startSimulationTimeSek; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | public double getReadyTime() { |
---|
| 131 | double readyTime = 0; |
---|
| 132 | |
---|
| 133 | try { |
---|
| 134 | readyTime = task.getExecutionStartTime().getMillis() / 1000 |
---|
| 135 | - startSimulationTimeSek; |
---|
| 136 | } catch (Exception ex) { |
---|
| 137 | readyTime = task.getSubmissionTimeToBroker().getMillis()/1000 - startSimulationTimeSek; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | return readyTime; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | public double getStartTime() { |
---|
| 144 | return task.getExecStartTime() |
---|
| 145 | - task.getSubmissionTimeToBroker().getMillis() / 1000; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | public double getFlowTime() { |
---|
| 149 | return getCompletionTime() - getReadyTime(); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | public double getWaitingTime() { |
---|
| 153 | return task.getWaitingTime(); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | public double getGQ_WaitingTime() { |
---|
| 157 | return task.getSubmissionTime() |
---|
| 158 | - task.getSubmissionTimeToBroker().getMillis() / 1000; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | public double getLateness() { |
---|
| 162 | double execEndDate = getExecEndDate(); |
---|
| 163 | double lateness = 0; |
---|
| 164 | if (execEndDate != -1) { |
---|
| 165 | lateness = task.getFinishTime() - execEndDate; |
---|
| 166 | } |
---|
| 167 | return lateness; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | public double getTardiness() { |
---|
| 171 | return Math.max(getLateness(), 0.0); |
---|
| 172 | } |
---|
| 173 | |
---|
[1207] | 174 | public void setProcessors(Set<ComputingResource> value) { |
---|
| 175 | this.processingElements = value; |
---|
[477] | 176 | } |
---|
| 177 | |
---|
| 178 | public void setReservationStartDate(double value) { |
---|
| 179 | this.reservationStartDate = value; |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | public void setReservationFinishDate(double value) { |
---|
| 183 | this.reservationFinishDate = value; |
---|
| 184 | } |
---|
| 185 | |
---|
[1570] | 186 | public Set<String> getProcessingElementsName() { |
---|
| 187 | Set<String> processingElementsNames = new TreeSet<String>(); |
---|
[1207] | 188 | Iterator<ComputingResource> it = processingElements.iterator(); |
---|
| 189 | while(it.hasNext()) { |
---|
| 190 | ComputingResource compRes = it.next(); |
---|
| 191 | processingElementsNames.add(compRes.getFullName()); |
---|
| 192 | } |
---|
| 193 | return processingElementsNames; |
---|
[477] | 194 | } |
---|
| 195 | |
---|
[1207] | 196 | public Set<String> getHostName() { |
---|
[1570] | 197 | Set<String> hostNames = new TreeSet <String>(); |
---|
[1207] | 198 | Iterator<ComputingResource> it = processingElements.iterator(); |
---|
| 199 | while(it.hasNext()) { |
---|
| 200 | ComputingResource compRes = it.next(); |
---|
[1247] | 201 | Node node = null; |
---|
[1207] | 202 | if(compRes instanceof Core){ |
---|
| 203 | Core core =(Core) compRes; |
---|
[1247] | 204 | node = (Node)core.getNode(); |
---|
[1207] | 205 | } else if(compRes instanceof Processor){ |
---|
| 206 | Processor proc = (Processor) compRes; |
---|
[1247] | 207 | node = (Node)proc.getNode(); |
---|
| 208 | } else if(compRes instanceof Node){ |
---|
| 209 | node = (Node)compRes; |
---|
[1207] | 210 | } |
---|
| 211 | if(node != null) |
---|
| 212 | hostNames.add(node.getFullName()); |
---|
| 213 | } |
---|
[1570] | 214 | |
---|
[1207] | 215 | return hostNames; |
---|
| 216 | } |
---|
| 217 | |
---|
[477] | 218 | public double getReservationStartDate() { |
---|
| 219 | return reservationStartDate; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | public double getReservationFinishDate() { |
---|
| 223 | return reservationFinishDate; |
---|
| 224 | } |
---|
[1207] | 225 | |
---|
| 226 | public String getExecName() { |
---|
| 227 | String execName = null; |
---|
| 228 | if(task.getDescription().getExecution() != null) { |
---|
| 229 | if(task.getDescription().getExecution().getStdin()!= null && task.getDescription().getExecution().getStdin().length > 0) |
---|
| 230 | execName = task.getDescription().getExecution().getStdin()[0].getName(); |
---|
| 231 | else if(task.getDescription().getExecution().getExecutable() != null && task.getDescription().getExecution().getExecutable().getApplication() != null) |
---|
| 232 | execName = task.getDescription().getExecution().getExecutable().getApplication().getName(); |
---|
| 233 | } |
---|
| 234 | return execName; |
---|
| 235 | } |
---|
[477] | 236 | |
---|
| 237 | public String[] getHeaders() { |
---|
| 238 | return headers; |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | } |
---|