source: DCWoRMS/trunk/src/test/article/recs/plugins/energy/RecsNodeBaseEEP.java @ 656

Revision 656, 2.5 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.article.recs.plugins.energy;
2
3import java.io.FileInputStream;
4import java.io.FileNotFoundException;
5import java.io.IOException;
6import java.util.Map;
7import java.util.PropertyResourceBundle;
8import java.util.ResourceBundle;
9
10import schedframe.resources.computing.Core;
11import schedframe.resources.computing.Processor;
12import schedframe.resources.units.PEUnit;
13import schedframe.resources.units.ProcessingElements;
14import schedframe.resources.units.ResourceUnit;
15import schedframe.resources.units.ResourceUnitName;
16import schedframe.resources.units.StandardResourceUnitName;
17import test.article.recs.utils.AppType;
18import test.article.recs.utils.TaskToApp;
19import dcworms.schedframe.scheduling.ExecTask;
20import dcworms.schedframe.scheduling.Executable;
21import example.energy.BaseEnergyEstimationPlugin;
22
23public abstract class RecsNodeBaseEEP extends BaseEnergyEstimationPlugin{
24       
25        private static String powerDataFileName = "src/test/article/recs/data/power_data.properties";
26        private TaskToApp taskToApp = new TaskToApp();
27
28        protected String createQuery(ExecTask task) {
29                Executable exec = (Executable)task;
30                Map<ResourceUnitName, ResourceUnit> allocatedResources = exec.getUsedResources().getLast().getResourceUnits();
31                PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE);
32               
33                String query = getApplicationType(task) + "." + getNodeCategory(peUnit) + "." + getFrequency(peUnit) + "." + getCoreCnt(task);
34                return query;
35        }
36
37        private String getApplicationType(ExecTask task){       
38                AppType appType = taskToApp.getAppType(task);
39                return appType.toString();
40        }
41       
42        private String getNodeCategory(PEUnit peUnit){
43               
44                ProcessingElements pe = (ProcessingElements) peUnit;
45                Core core = (Core)pe.get(0);
46                return core.getParent().getParent().getCategory();
47        }
48       
49        private int getFrequency(PEUnit peUnit){
50                ProcessingElements pe = (ProcessingElements) peUnit;
51                Core core = (Core)pe.get(0);
52                Processor proc = (Processor) core.getParent();
53                double freq;
54                try{
55                        freq = proc.getPowerInterface().getFrequency();
56                } catch(Exception e){
57                        freq = 800;
58                }
59                return Double.valueOf(freq).intValue();
60               
61        }
62       
63        private int getCoreCnt(ExecTask task){ 
64                double cpuReq;
65                try {
66                        cpuReq = task.getCpuCntRequest();
67                } catch (NoSuchFieldException e) {
68                                cpuReq = 1;
69                }
70                return Double.valueOf(cpuReq).intValue();
71        }
72       
73        protected double getMeasuredPower(String query) throws FileNotFoundException, IOException{
74                ResourceBundle bundle = new PropertyResourceBundle(new FileInputStream(powerDataFileName));
75
76                return Double.valueOf(bundle.getString(query)).doubleValue();
77        }
78}
Note: See TracBrowser for help on using the repository browser.