1 | package example.energy; |
---|
2 | |
---|
3 | import schedframe.resources.ResourceStatus; |
---|
4 | import schedframe.resources.computing.Processor; |
---|
5 | import schedframe.resources.computing.profiles.energy.ResourceEvent; |
---|
6 | import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName; |
---|
7 | import schedframe.resources.devices.PhysicalResource; |
---|
8 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
9 | |
---|
10 | public class ProcessorEnergyEstimationPlugin extends BaseEnergyEstimationPlugin { |
---|
11 | |
---|
12 | public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry, |
---|
13 | PhysicalResource resource) { |
---|
14 | double powerConsumption; |
---|
15 | |
---|
16 | Processor cpu = (Processor)resource; |
---|
17 | if(resource.getPowerInterface().getPowerState().equals(StandardPowerStateName.OFF)) |
---|
18 | powerConsumption = 0; |
---|
19 | else { |
---|
20 | if(resource.getStatus() == ResourceStatus.BUSY){ |
---|
21 | try { |
---|
22 | |
---|
23 | powerConsumption = cpu.getPowerInterface().getPowerConsumption(cpu.getPowerInterface().getPState()); |
---|
24 | } catch (NoSuchFieldException e) { |
---|
25 | try { |
---|
26 | powerConsumption = cpu.getPowerInterface().getPowerConsumption(StandardPowerStateName.ON); |
---|
27 | } catch (NoSuchFieldException e1) { |
---|
28 | powerConsumption = 10; |
---|
29 | } |
---|
30 | } |
---|
31 | } else{ |
---|
32 | try { |
---|
33 | powerConsumption = cpu.getPowerInterface().getPowerConsumption(cpu.getPowerInterface().getPState()); |
---|
34 | } catch (NoSuchFieldException e) { |
---|
35 | try { |
---|
36 | powerConsumption = cpu.getPowerInterface().getPowerConsumption(StandardPowerStateName.ON); |
---|
37 | } catch (NoSuchFieldException e1) { |
---|
38 | powerConsumption = 0; |
---|
39 | } |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | } |
---|
44 | if(cpu.getLoadInterface().getRecentUtilization().getValue() != 0.0){ |
---|
45 | powerConsumption = powerConsumption * cpu.getLoadInterface().getRecentUtilization().getValue()/100; |
---|
46 | } |
---|
47 | return powerConsumption; |
---|
48 | } |
---|
49 | |
---|
50 | } |
---|