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