[104] | 1 | package simulator.stats.implementation; |
---|
| 2 | |
---|
| 3 | import gssim.schedframe.scheduling.AbstractExecutable; |
---|
| 4 | |
---|
| 5 | import java.util.List; |
---|
| 6 | |
---|
| 7 | import simulator.stats.implementation.out.StatsSerializer; |
---|
| 8 | |
---|
| 9 | /** |
---|
| 10 | * |
---|
| 11 | * @author Marcin Krystek |
---|
| 12 | * |
---|
| 13 | */ |
---|
| 14 | public class TaskStats implements StatsInterface { |
---|
| 15 | protected List<String> processorsName; |
---|
| 16 | protected double reservationStartDate; |
---|
| 17 | protected double reservationFinishDate; |
---|
| 18 | |
---|
| 19 | protected AbstractExecutable task; |
---|
| 20 | protected long startSimulationTimeSek; |
---|
| 21 | |
---|
| 22 | private String headers[] = { "JobID", "TaskID", "UserDN", "ResName", "CpuCnt", |
---|
| 23 | "ExecStartDate", "ExecFinishDate", "ExecEndDate", "GB_SubDate", |
---|
| 24 | "LB_SubDate", "CompletionTime", "ExecStartTime", |
---|
| 25 | "ExecutionTime", "ReadyTime", "StartTime", "FlowTime", |
---|
| 26 | "WaitingTime", "GQ_WaitingTime", "Lateness", "Tardiness", |
---|
| 27 | "ReservStartDate", "ReservFinishDate", "ProcessorName", "Energy"}; |
---|
| 28 | |
---|
| 29 | public TaskStats(AbstractExecutable task, long startSimulationTime) { |
---|
| 30 | this.task = task; |
---|
| 31 | this.startSimulationTimeSek = startSimulationTime / 1000; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | public Object serialize(StatsSerializer serializer) { |
---|
| 35 | return serializer.visit(this); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | public String getJobID() { |
---|
| 39 | return this.task.getJobId(); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | public String getTaskID() { |
---|
| 43 | return this.task.getId(); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | public String getUserDN() { |
---|
| 47 | return this.task.getUserDn(); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | public String getResName() { |
---|
| 51 | String resNames[] = this.task.getAllResourceName(); |
---|
| 52 | String resName = ""; |
---|
| 53 | for (int i = 0; i < resNames.length; i++) { |
---|
| 54 | resName += resNames[i]; |
---|
| 55 | if (resNames.length > 1) |
---|
| 56 | resName += " "; |
---|
| 57 | } |
---|
| 58 | return resName; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | public long getCpuCnt() { |
---|
| 62 | long cpuCnt = -1; |
---|
| 63 | try { |
---|
| 64 | cpuCnt = Double.valueOf(task.getCpuCntRequest()).longValue(); |
---|
| 65 | } catch (NoSuchFieldException e) { |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | return cpuCnt; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | public double getExecStartDate() { |
---|
| 72 | return task.getExecStartTime(); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | public double getExecFinishDate() { |
---|
| 76 | return task.getFinishTime(); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | public double getExecEndDate() { |
---|
| 80 | double ret = -1; |
---|
| 81 | try { |
---|
| 82 | ret = task.getExecutionEndTime().getMillis() / 1000; |
---|
| 83 | } catch (NoSuchFieldException e) { |
---|
| 84 | ret = task.getFinishTime(); |
---|
| 85 | } |
---|
| 86 | return ret; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | public double getGB_SubDate() { |
---|
| 90 | return task.getSubmissionTimeToBroker().getMillis() / 1000; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | public double getLB_SubDate() { |
---|
| 94 | return task.getSubmissionTime(); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | public double getCompletionTime() { |
---|
| 98 | return task.getFinishTime() - startSimulationTimeSek; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | public double getExecutionTime() { |
---|
| 102 | return task.getFinishTime() - task.getExecStartTime(); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | public double getExecStartTime() { |
---|
| 106 | return task.getExecStartTime() - startSimulationTimeSek; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | public double getReadyTime() { |
---|
| 110 | double readyTime = 0; |
---|
| 111 | |
---|
| 112 | try { |
---|
| 113 | readyTime = task.getExecutionStartTime().getMillis() / 1000 |
---|
| 114 | - startSimulationTimeSek; |
---|
| 115 | } catch (Exception ex) { |
---|
| 116 | readyTime = task.getSubmissionTimeToBroker().getMillis()/1000 - startSimulationTimeSek; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | return readyTime; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | public double getStartTime() { |
---|
| 123 | return task.getExecStartTime() |
---|
| 124 | - task.getSubmissionTimeToBroker().getMillis() / 1000; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | public double getFlowTime() { |
---|
| 128 | return getCompletionTime() - getReadyTime(); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | public double getWaitingTime() { |
---|
| 132 | return task.getWaitingTime(); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | public double getGQ_WaitingTime() { |
---|
| 136 | return task.getSubmissionTime() |
---|
| 137 | - task.getSubmissionTimeToBroker().getMillis() / 1000; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | public double getLateness() { |
---|
| 141 | double execEndDate = getExecEndDate(); |
---|
| 142 | double lateness = 0; |
---|
| 143 | if (execEndDate != -1) { |
---|
| 144 | lateness = task.getFinishTime() - execEndDate; |
---|
| 145 | } |
---|
| 146 | return lateness; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | public double getTardiness() { |
---|
| 150 | return Math.max(getLateness(), 0.0); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | public void setProcessorsName(List<String> value) { |
---|
| 154 | this.processorsName = value; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | public void setReservationStartDate(double value) { |
---|
| 158 | this.reservationStartDate = value; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | public void setReservationFinishDate(double value) { |
---|
| 162 | this.reservationFinishDate = value; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | public List<String> getProcessorsName() { |
---|
| 166 | return processorsName; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | public double getReservationStartDate() { |
---|
| 170 | return reservationStartDate; |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | public double getReservationFinishDate() { |
---|
| 174 | return reservationFinishDate; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | public String[] getHeaders() { |
---|
| 178 | return headers; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | } |
---|