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

Revision 662, 2.7 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 POWER_DATA_FILE_NAME = "src/test/article/recs/data/power_data.properties";
26       
27        private ResourceBundle powBundle;
28       
29        private TaskToApp taskToApp = new TaskToApp();
30
31        protected String createQuery(ExecTask task) {
32                Executable exec = (Executable)task;
33                Map<ResourceUnitName, ResourceUnit> allocatedResources = exec.getUsedResources().getLast().getResourceUnits();
34                PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE);
35               
36                String query = getApplicationType(task) + "." + getNodeCategory(peUnit) + "." + getFrequency(peUnit) + "." + getCoreCnt(task);
37                return query;
38        }
39
40        private String getApplicationType(ExecTask task){       
41                AppType appType = taskToApp.getAppType(task);
42                return appType.toString();
43        }
44       
45        private String getNodeCategory(PEUnit peUnit){
46               
47                ProcessingElements pe = (ProcessingElements) peUnit;
48                Core core = (Core)pe.get(0);
49                return core.getParent().getParent().getCategory();
50        }
51       
52        private int getFrequency(PEUnit peUnit){
53                ProcessingElements pe = (ProcessingElements) peUnit;
54                Core core = (Core)pe.get(0);
55                Processor proc = (Processor) core.getParent();
56                double freq = proc.getPowerInterface().getFrequency();
57                return Double.valueOf(freq).intValue();
58               
59        }
60       
61        private int getCoreCnt(ExecTask task){ 
62                double cpuReq;
63                try {
64                        cpuReq = task.getCpuCntRequest();
65                } catch (NoSuchFieldException e) {
66                                cpuReq = 1;
67                }
68                return Double.valueOf(cpuReq).intValue();
69        }
70       
71        protected double getMeasuredPower(String query) throws FileNotFoundException, IOException{
72                ResourceBundle powBundle = getPowBundle();
73                return Double.valueOf(powBundle.getString(query)).doubleValue();
74        }
75       
76        private ResourceBundle getPowBundle() throws FileNotFoundException, IOException{
77                if(powBundle == null){
78                         powBundle = new PropertyResourceBundle(new FileInputStream(POWER_DATA_FILE_NAME));
79                }
80                return powBundle;
81        }
82}
Note: See TracBrowser for help on using the repository browser.