package test.drs_tst.recs.plugins.energy; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Map; import java.util.PropertyResourceBundle; import java.util.Random; import java.util.ResourceBundle; import schedframe.resources.computing.Node; import schedframe.resources.computing.Core; import schedframe.resources.computing.Processor; import schedframe.resources.units.PEUnit; import schedframe.resources.units.ProcessingElements; import schedframe.resources.units.ResourceUnit; import schedframe.resources.units.ResourceUnitName; import schedframe.resources.units.StandardResourceUnitName; import test.drs_tst.recs.utils.TaskToApp; import test.drs_tst.recs.utils.appprofiles.ApplicationProfileBase; import test.drs_tst.recs.utils.appprofiles.ProfileGetter; import dcworms.schedframe.scheduling.ExecTask; import dcworms.schedframe.scheduling.Executable; import example.energy.BaseEnergyEstimationPlugin; public abstract class RecsNodeBaseEEP extends BaseEnergyEstimationPlugin{ private static String POWER_DATA_FILE_NAME = "src/test/drs_tst/recs/data/power_data.properties"; private ResourceBundle powBundle; private TaskToApp taskToApp = new TaskToApp(); private Random rand = new Random(); protected ApplicationProfileBase profile; protected String createQuery(ExecTask task) { Executable exec = (Executable)task; Map allocatedResources = exec.getAllocatedResources().getLast().getResourceUnits(); PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); //System.out.println(task.getJobId()); String query = getApplicationType(task) + "." + getNodeCategory(peUnit) + "." + getFrequency(peUnit) + "." + getCoreCnt(task); profile = getProfile(getApplicationType(task)); return query; } private String getApplicationType(ExecTask task){ return ((Executable)task).getApplicationName(); } private String getNodeCategory(PEUnit peUnit){ ProcessingElements pe = (ProcessingElements) peUnit; if(pe.get(0) instanceof Node) return ((Node)pe.get(0)).getCategory(); Core core = (Core)pe.get(0); return core.getParent().getParent().getCategory(); } private int getFrequency(PEUnit peUnit){ ProcessingElements pe = (ProcessingElements) peUnit; if(pe.get(0) instanceof Node) return Double.valueOf(((Node)pe.get(0)).getProcessors().get(0).getPowerInterface().getFrequency()).intValue(); Core core = (Core)pe.get(0); Processor proc = (Processor) core.getParent(); double freq = proc.getPowerInterface().getFrequency(); return Double.valueOf(freq).intValue(); } /* private int getCoreCnt(ExecTask task, PEUnit peUnit){ double cpuReq; ProcessingElements pe = (ProcessingElements) peUnit; try { cpuReq = task.getCpuCntRequest(); cpuReq = ((ComputingNode)pe.get(0)).getProcessors().get(0).getCores().size(); //System.out.println("cpuReq: "+cpuReq); } catch (NoSuchFieldException e) { cpuReq = 1; } return Double.valueOf(cpuReq).intValue(); }*/ private int getCoreCnt(ExecTask task){ double cpuReq; try { cpuReq = task.getCpuCntRequest(); //System.out.println("cpuReq: "+cpuReq); } catch (NoSuchFieldException e) { cpuReq = 1; } return Double.valueOf(cpuReq).intValue(); } protected double getMeasuredPower(String query) throws FileNotFoundException, IOException{ ResourceBundle powBundle = getPowBundle(); System.out.println(query); double measured = Double.valueOf(powBundle.getString(query)).doubleValue(); try{ measured = profile.getPower(query, measured); }catch(Exception e){ e.printStackTrace(); } System.out.println("power: "+ measured); return measured; } protected ApplicationProfileBase getProfile(String name){ return ProfileGetter.getProfileWithName(name); } private ResourceBundle getPowBundle() throws FileNotFoundException, IOException{ if(powBundle == null){ powBundle = new PropertyResourceBundle(new FileInputStream(POWER_DATA_FILE_NAME)); } return powBundle; } }