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

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