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

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