package simulator.stats.implementation; import gridsim.dcworms.DCWormsTags; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.TreeSet; import schedframe.resources.computing.ComputingResource; import schedframe.resources.computing.Core; import schedframe.resources.computing.Node; import schedframe.resources.computing.Processor; import schedframe.scheduling.ExecutionHistoryItem; import simulator.stats.implementation.out.StatsSerializer; import dcworms.schedframe.scheduling.Executable; /** * * @author Marcin Krystek * */ public class TaskStats implements StatsInterface { protected Set processingElements; protected double reservationStartDate; protected double reservationFinishDate; protected Executable task; protected long startSimulationTimeSek; private String headers[] = { "JobID", "TaskID", "UserDN", "SchedName", "CpuCnt", "ExecStartDate", "ExecFinishDate", "ExecEndDate", "GB_SubDate", "LB_SubDate", "CompletionTime", "ExecStartTime", "ExecutionTime", "ReadyTime", "StartTime", "FlowTime", "WaitingTime", "GQ_WaitingTime", "Lateness", "Tardiness", "ReservStartDate", "ReservFinishDate", "HostNames", "ProcessorName", "Energy", "AppName",}; public TaskStats(Executable task, long startSimulationTime) { this.task = task; this.startSimulationTimeSek = startSimulationTime / 1000; } public Object serialize(StatsSerializer serializer) { return serializer.visit(this); } public String getJobID() { return this.task.getJobId(); } public String getTaskID() { return this.task.getId(); } public String getUserDN() { return this.task.getUserDN(); } public String getResName() { String resName = this.task.getSchedulerName(); return resName; } public long getCpuCnt() { long cpuCnt = -1; try { cpuCnt = Double.valueOf(task.getCpuCntRequest()).longValue(); } catch (NoSuchFieldException e) { } return cpuCnt; } public double getExecStartDate() { return task.getExecStartTime(); } public double getExecFinishDate() { return task.getFinishTime(); } public double getExecEndDate() { double ret = -1; try { ret = task.getExecutionEndTime().getMillis() / 1000; } catch (NoSuchFieldException e) { ret = task.getFinishTime(); } return ret; } public double getGB_SubDate() { return task.getSubmissionTimeToBroker().getMillis() / 1000; } public double getLB_SubDate() { return task.getSubmissionTime(); } public double getCompletionTime() { return task.getFinishTime() - startSimulationTimeSek; } public double getExecutionTime() { double executionTime = 0; long previousTimestamp = 0; int previousStatus = DCWormsTags.CREATED; for(ExecutionHistoryItem execHistItem: task.getExecutionHistory()){ if(previousStatus == DCWormsTags.INEXEC){ executionTime = executionTime + (execHistItem.getTimeStamp()/1000 - previousTimestamp); } previousTimestamp = execHistItem.getTimeStamp()/1000; previousStatus = execHistItem.getStatus(); } return executionTime; //return task.getFinishTime() - task.getExecStartTime(); } public double getExecStartTime() { return task.getExecStartTime() - startSimulationTimeSek; } public double getReadyTime() { double readyTime = 0; try { readyTime = task.getExecutionStartTime().getMillis() / 1000 - startSimulationTimeSek; } catch (Exception ex) { readyTime = task.getSubmissionTimeToBroker().getMillis()/1000 - startSimulationTimeSek; } return readyTime; } public double getStartTime() { return task.getExecStartTime() - task.getSubmissionTimeToBroker().getMillis() / 1000; } public double getFlowTime() { return getCompletionTime() - getReadyTime(); } public double getWaitingTime() { return task.getWaitingTime(); } public double getGQ_WaitingTime() { return task.getSubmissionTime() - task.getSubmissionTimeToBroker().getMillis() / 1000; } public double getLateness() { double execEndDate = getExecEndDate(); double lateness = 0; if (execEndDate != -1) { lateness = task.getFinishTime() - execEndDate; } return lateness; } public double getTardiness() { return Math.max(getLateness(), 0.0); } public void setProcessors(Set value) { this.processingElements = value; } public void setReservationStartDate(double value) { this.reservationStartDate = value; } public void setReservationFinishDate(double value) { this.reservationFinishDate = value; } public Set getProcessingElementsName() { Set processingElementsNames = new TreeSet(); Iterator it = processingElements.iterator(); while(it.hasNext()) { ComputingResource compRes = it.next(); processingElementsNames.add(compRes.getFullName()); } return processingElementsNames; } public Set getHostName() { Set hostNames = new TreeSet (); Iterator it = processingElements.iterator(); while(it.hasNext()) { ComputingResource compRes = it.next(); Node node = null; if(compRes instanceof Core){ Core core =(Core) compRes; node = (Node)core.getNode(); } else if(compRes instanceof Processor){ Processor proc = (Processor) compRes; node = (Node)proc.getNode(); } else if(compRes instanceof Node){ node = (Node)compRes; } if(node != null) hostNames.add(node.getFullName()); } return hostNames; } public double getReservationStartDate() { return reservationStartDate; } public double getReservationFinishDate() { return reservationFinishDate; } public String getExecName() { String execName = null; if(task.getDescription().getExecution() != null) { if(task.getDescription().getExecution().getStdin()!= null && task.getDescription().getExecution().getStdin().length > 0) execName = task.getDescription().getExecution().getStdin()[0].getName(); else if(task.getDescription().getExecution().getExecutable() != null && task.getDescription().getExecution().getExecutable().getApplication() != null) execName = task.getDescription().getExecution().getExecutable().getApplication().getName(); } return execName; } public String[] getHeaders() { return headers; } }