package example.load; import schedframe.resources.computing.Processor; import schedframe.resources.computing.profiles.energy.ResourceEvent; import schedframe.resources.devices.PhysicalResource; import schedframe.scheduling.manager.tasks.JobRegistry; import schedframe.scheduling.tasks.phases.PhaseSystemLoad; import dcworms.schedframe.scheduling.ExecTask; public class AppBasedProcessorLoadEstimationPlugin extends BaseLoadEstimationPlugin{ public double estimateUtlization(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) { Processor proc = (Processor) resource; double sumCoresLoad = 0; double nrOfThreadsOnCpu = proc.getCores().size() > 0 ? proc.getCores().size() : 1; if(proc.getResourceCharacteristic().getParameters().get("threads") != null){ nrOfThreadsOnCpu = nrOfThreadsOnCpu * Integer.valueOf(proc.getResourceCharacteristic().getParameters().get("threads").get(0).getContent()).intValue(); } for(ExecTask task: jobRegistry.getRunningTasks()){ double cpuUsage = 1 / nrOfThreadsOnCpu; for(PhaseSystemLoad pb: task.getExecutionProfile().getCurrentExecutionPhase().getSystemLoad()){ if(pb.getResouceName().equals("PM_CPU_Usage")){ cpuUsage = pb.getUtilization(); break; } } sumCoresLoad = sumCoresLoad + cpuUsage; } double processorLoad = 100 * sumCoresLoad; double calendarLoad = resource.getLoadInterface().getLoadCalendar().getCurrentLoad(); double totalLoad = processorLoad + calendarLoad; if (totalLoad > 100) return 100; else return totalLoad; } }