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

Revision 660, 2.8 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;
57                try{
58                        freq = proc.getPowerInterface().getFrequency();
59                } catch(Exception e){
60                        freq = 800;
61                }
62                return Double.valueOf(freq).intValue();
63               
64        }
65       
66        private int getCoreCnt(ExecTask task){ 
67                double cpuReq;
68                try {
69                        cpuReq = task.getCpuCntRequest();
70                } catch (NoSuchFieldException e) {
71                                cpuReq = 1;
72                }
73                return Double.valueOf(cpuReq).intValue();
74        }
75       
76        protected double getMeasuredPower(String query) throws FileNotFoundException, IOException{
77                ResourceBundle powBundle = getPowBundle();
78                return Double.valueOf(powBundle.getString(query)).doubleValue();
79        }
80       
81        private ResourceBundle getPowBundle() throws FileNotFoundException, IOException{
82                if(powBundle == null){
83                         powBundle = new PropertyResourceBundle(new FileInputStream(POWER_DATA_FILE_NAME));
84                }
85                return powBundle;
86        }
87}
Note: See TracBrowser for help on using the repository browser.