source: DCWoRMS/branches/coolemall/src/simulator/stats/implementation/TaskStats.java @ 1570

Revision 1570, 6.2 KB checked in by wojtekp, 9 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package simulator.stats.implementation;
2
3
4import gridsim.dcworms.DCWormsTags;
5
6import java.util.ArrayList;
7import java.util.Collections;
8import java.util.Comparator;
9import java.util.HashSet;
10import java.util.Iterator;
11import java.util.List;
12import java.util.Set;
13import java.util.TreeSet;
14
15import schedframe.resources.computing.ComputingResource;
16import schedframe.resources.computing.Core;
17import schedframe.resources.computing.Node;
18import schedframe.resources.computing.Processor;
19import schedframe.scheduling.ExecutionHistoryItem;
20import simulator.stats.implementation.out.StatsSerializer;
21import dcworms.schedframe.scheduling.Executable;
22
23
24/**
25 *
26 * @author Marcin Krystek
27 *
28 */
29public class TaskStats implements StatsInterface {
30        protected Set<ComputingResource> processingElements;
31        protected double reservationStartDate;
32        protected double reservationFinishDate;
33
34        protected Executable task;
35        protected long startSimulationTimeSek;
36       
37        private String headers[] = { "JobID", "TaskID", "UserDN", "SchedName", "CpuCnt",
38                        "ExecStartDate", "ExecFinishDate", "ExecEndDate", "GB_SubDate",
39                        "LB_SubDate", "CompletionTime", "ExecStartTime",
40                        "ExecutionTime", "ReadyTime", "StartTime", "FlowTime",
41                        "WaitingTime", "GQ_WaitingTime", "Lateness", "Tardiness",
42                        "ReservStartDate", "ReservFinishDate", "HostNames", "ProcessorName", "Energy", "AppName",};
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() {
62                return this.task.getUserDN();
63        }
64
65        public String getResName() {
66                String resName = this.task.getSchedulerName();
67
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() {
112                double executionTime = 0;
113                long previousTimestamp = 0;             
114                int previousStatus = DCWormsTags.CREATED;
115                for(ExecutionHistoryItem execHistItem: task.getExecutionHistory()){
116                        if(previousStatus == DCWormsTags.INEXEC){
117                                executionTime = executionTime  + (execHistItem.getTimeStamp()/1000 - previousTimestamp);
118                        }
119                        previousTimestamp  = execHistItem.getTimeStamp()/1000;
120                        previousStatus = execHistItem.getStatus();
121                }
122                return executionTime;
123                //return task.getFinishTime() - task.getExecStartTime();
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
174        public void setProcessors(Set<ComputingResource> value) {
175                this.processingElements = value;
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
186        public Set<String> getProcessingElementsName() {
187                Set<String> processingElementsNames = new TreeSet<String>();
188                Iterator<ComputingResource> it = processingElements.iterator();
189                while(it.hasNext()) {
190                        ComputingResource compRes = it.next();
191                        processingElementsNames.add(compRes.getFullName());
192                }
193                return processingElementsNames;
194        }
195
196        public Set<String> getHostName() {
197                Set<String> hostNames = new TreeSet <String>();
198                Iterator<ComputingResource> it = processingElements.iterator();
199                while(it.hasNext()) {
200                        ComputingResource compRes = it.next();
201                        Node node = null;
202                        if(compRes instanceof Core){
203                                Core core =(Core) compRes;
204                                node = (Node)core.getNode();
205                        } else if(compRes instanceof Processor){
206                                Processor proc = (Processor) compRes;
207                                node = (Node)proc.getNode();
208                        } else if(compRes instanceof Node){
209                                node = (Node)compRes;
210                        }
211                        if(node != null)
212                                hostNames.add(node.getFullName());
213                }
214
215                return hostNames;
216        }
217       
218        public double getReservationStartDate() {
219                return reservationStartDate;
220        }
221
222        public double getReservationFinishDate() {
223                return reservationFinishDate;
224        }
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        }
236
237        public String[] getHeaders() {
238                return headers;
239        }
240
241}
Note: See TracBrowser for help on using the repository browser.