source: DCWoRMS/branches/coolemall/src/example/load/AppBasedProcessorLoadEstimationPlugin.java @ 1452

Revision 1452, 1.5 KB checked in by wojtekp, 10 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package example.load;
2
3import schedframe.resources.computing.Processor;
4import schedframe.resources.computing.profiles.energy.ResourceEvent;
5import schedframe.resources.devices.PhysicalResource;
6import schedframe.scheduling.manager.tasks.JobRegistry;
7import schedframe.scheduling.tasks.phases.PhaseSystemLoad;
8import dcworms.schedframe.scheduling.ExecTask;
9
10public class AppBasedProcessorLoadEstimationPlugin  extends BaseLoadEstimationPlugin{
11       
12        public double estimateUtlization(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
13                Processor proc = (Processor) resource;
14                double sumCoresLoad = 0;
15               
16                double nrOfThreadsOnCpu = proc.getCores().size() > 0 ? proc.getCores().size() : 1;
17               
18                if(proc.getResourceCharacteristic().getParameters().get("threads") != null){
19                        nrOfThreadsOnCpu = nrOfThreadsOnCpu * Integer.valueOf(proc.getResourceCharacteristic().getParameters().get("threads").get(0).getContent()).intValue();
20                }
21
22                for(ExecTask task: jobRegistry.getRunningTasks()){
23                        double cpuUsage = 1 / nrOfThreadsOnCpu;
24
25                        for(PhaseSystemLoad pb: task.getExecutionProfile().getCurrentExecutionPhase().getSystemLoad()){
26                                if(pb.getResouceName().equals("PM_CPU_Usage")){
27                                        cpuUsage = pb.getUtilization();
28                                        break;
29                                }
30                        }
31                        sumCoresLoad = sumCoresLoad + cpuUsage;
32                }
33
34
35                double processorLoad = 100 * sumCoresLoad;     
36                double calendarLoad = resource.getLoadInterface().getLoadCalendar().getCurrentLoad();
37                double totalLoad = processorLoad + calendarLoad;
38                if (totalLoad > 100)
39                        return 100;
40                else return totalLoad;
41        }
42
43
44}
Note: See TracBrowser for help on using the repository browser.