Ignore:
Timestamp:
06/03/14 15:12:11 (11 years ago)
Author:
wojtekp
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • DCWoRMS/branches/coolemall/src/simulator/stats/implementation/DCWormsStatistics.java

    r1357 r1362  
    1616import java.util.HashMap; 
    1717import java.util.HashSet; 
     18import java.util.LinkedList; 
    1819import java.util.List; 
    1920import java.util.Map; 
     
    7879import schedframe.resources.units.ResourceUnitName; 
    7980import schedframe.resources.units.StandardResourceUnitName; 
     81import schedframe.scheduling.ExecutionHistoryItem; 
    8082import schedframe.scheduling.ResourceHistoryItem; 
    8183import schedframe.scheduling.Scheduler; 
     
    104106import eduni.simjava.Sim_stat; 
    105107import example.energy.coolemall.CoolEmAllTestbedMeasurements; 
     108import gridsim.dcworms.DCWormsTags; 
    106109 
    107110public class DCWormsStatistics implements SimulationStatistics { 
     
    407410                } 
    408411                 
    409                 pesStats = gatherPEStats(jr.getTasks()); 
     412                pesStats = gatherPEStatsMulti(jr.getTasks()); 
    410413                peStatsPostProcessing(pesStats); 
    411414                basicResLoad = calculatePELoad(pesStats); 
     
    763766                        Executable exec = (Executable) execTask; 
    764767 
    765                         List<ResourceHistoryItem> resHistItemList = exec.getUsedResources(); 
    766                         if(resHistItemList.size() == 0) 
     768 
     769                        LinkedList<ResourceHistoryItem> resourceHistory = exec.getAllocatedResources(); 
     770                        if(resourceHistory.size() == 0) 
    767771                                continue; 
    768                         Map<ResourceUnitName, ResourceUnit> res = resHistItemList.get(resHistItemList.size() - 1).getResourceUnits(); 
     772                        Map<ResourceUnitName, ResourceUnit> res = exec.getAllocatedResources().getLast().getResourceUnits(); 
    769773                        ResourceUnit resUnit = res.get(StandardResourceUnitName.PE); 
    770774                        //ProcessingElements pes = (ProcessingElements) resUnit ; 
     
    820824                } 
    821825                return basicResStats; 
     826        } 
     827         
     828        private Map<String, List<ResStat>> gatherPEStatsMulti(ExecutablesList executables) { 
     829                 
     830                Map<String, List<ResStat>> basicResStats = new TreeMap<String, List<ResStat>>(new MapPEIdComparator()); 
     831                for (ExecTask execTask:executables) { 
     832                        Executable exec = (Executable) execTask; 
     833 
     834                        LinkedList<ResourceHistoryItem> resourceHistory = exec.getAllocatedResources(); 
     835                        if(resourceHistory.size() == 0) 
     836                                continue; 
     837 
     838                        for(int i = 0; i < resourceHistory .size(); i++){ 
     839                                ResourceHistoryItem resHistItem = resourceHistory.get(i); 
     840                                Map<ResourceUnitName, ResourceUnit> res = resHistItem.getResourceUnits(); 
     841                                ResourceUnit resUnit = res.get(StandardResourceUnitName.PE); 
     842                                //ProcessingElements pes = (ProcessingElements) resUnit ; 
     843                                LinkedList<ExecutionHistoryItem> execHistory = exec.getExecHistory(); 
     844                                long st = -1, et; 
     845                                for(int j = 0; j < execHistory .size(); j++){ 
     846                                        ExecutionHistoryItem execHistItem = execHistory.get(j); 
     847                                        if(execHistItem.getStatus() == DCWormsTags.PAUSED || execHistItem.getResIndex() != i){ 
     848                                                continue; 
     849                                        } 
     850                                        if(st == -1){ 
     851                                                st = execHistItem.getTimeStamp().getMillis(); 
     852                                        } 
     853                                                 
     854                                        if(j < execHistory.size() - 1 && (execHistory.get(j + 1).getResIndex() != execHistItem.getResIndex() || execHistory.get(j + 1).getStatus() == DCWormsTags.PAUSED) || j + 1 == execHistory.size()){ 
     855                                                if(j < execHistory.size() -1 && (execHistory.get(j + 1).getResIndex() != execHistItem.getResIndex() || execHistory.get(j + 1).getStatus() == DCWormsTags.PAUSED)) 
     856                                                        et = execHistory.get(j + 1).getTimeStamp().getMillis();  
     857                                                else et = Double.valueOf(exec.getFinishTime()).longValue() * MILLI_SEC;  
     858                                                if(resUnit instanceof ProcessingElements){ 
     859                                                        ProcessingElements pes = (ProcessingElements) resUnit; 
     860                                                        for(ComputingResource pe: pes){ 
     861                                                                String peName = pe.getFullName(); 
     862                                                                long startDate = st; 
     863                                                                long endDate; 
     864                                                                if(i == resourceHistory.size() - 1){ 
     865                                                                        endDate = Double.valueOf(exec.getFinishTime()).longValue() * MILLI_SEC; 
     866                                                                }else { 
     867                                                                        endDate = et; 
     868                                                                } 
     869 
     870                                                                String appID = getAppId(execTask); 
     871                                                                 
     872                                                                ResStat resStat = new ResStat(peName, pe.getType(), startDate, endDate, appID); 
     873                                                                 
     874                                                                List<ResStat> resStats = basicResStats.get(peName); 
     875                                                                if (resStats == null) { 
     876                                                                        resStats = new ArrayList<ResStat>(); 
     877                                                                        resStats.add(resStat); 
     878                                                                        basicResStats.put(peName, resStats); 
     879                                                                } else { 
     880                                                                        resStats.add(resStat); 
     881                                                                } 
     882                                                                 
     883                                                                String uniqueTaskID = getUniqueTaskId(execTask); 
     884 
     885                                                                Set<ComputingResource> peNames = task_processorsMap.get(uniqueTaskID); 
     886                                                                if (peNames == null) { 
     887                                                                        peNames = new HashSet<ComputingResource>(); 
     888                                                                        peNames.add(pe); 
     889                                                                        task_processorsMap.put(uniqueTaskID, peNames); 
     890                                                                } else { 
     891                                                                        peNames.add(pe); 
     892                                                                } 
     893 
     894                                                                try{ 
     895                                                                        double usefulWork = execTask.getResourceConsumptionProfile().getUsefulWork()/pes.size(); 
     896                                                                        usefulWork = ((et - st) / (1000 * getExecutionTime(execTask))) * usefulWork; 
     897                                                                        GSSAccumulator uwAcc; 
     898                                                                        if(metCalc.getMetricsData().containsKey("UW_" + pe.getFullName())){ 
     899                                                                                uwAcc = metCalc.getMetricsData().get("UW_" + pe.getFullName()).get(0); 
     900                                                                                uwAcc.add(usefulWork); 
     901                                                                        } else { 
     902                                                                                uwAcc = new GSSAccumulator(); 
     903                                                                                uwAcc.add(usefulWork); 
     904                                                                                metCalc.addMetricsData("UW_" + pe.getFullName(), uwAcc); 
     905                                                                        } 
     906                                                                }  catch (Exception e){ 
     907                                                                         
     908                                                                } 
     909                                                                 
     910                                                        } 
     911                                                }  
     912                                                st = -1; 
     913                                        } 
     914                                } 
     915                        } 
     916                } 
     917                return basicResStats; 
     918        } 
     919         
     920        private double getExecutionTime(ExecTask execTask) { 
     921                double executionTime = 0; 
     922                long previousTimestamp = 0; 
     923                int previousStatus = DCWormsTags.CREATED; 
     924                for(ExecutionHistoryItem execHistItem: execTask.getExecHistory()){ 
     925                        if(previousStatus == DCWormsTags.INEXEC){ 
     926                                executionTime = executionTime  + (execHistItem.getTimeStamp().getMillis()/1000 - previousTimestamp); 
     927                        }  
     928                        previousTimestamp  = execHistItem.getTimeStamp().getMillis()/1000; 
     929                        previousStatus = execHistItem.getStatus(); 
     930                } 
     931                return executionTime; 
     932                //return task.getFinishTime() - task.getExecStartTime(); 
    822933        } 
    823934         
Note: See TracChangeset for help on using the changeset viewer.