2018-08-05 11:22:07 -04:00
|
|
|
local M = {}
|
|
|
|
|
2017-07-19 00:43:44 -04:00
|
|
|
local Util = require 'Util'
|
2021-07-05 23:27:43 -04:00
|
|
|
local Common = require 'Common'
|
2021-07-16 23:25:44 -04:00
|
|
|
local Geometry = require 'Geometry'
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-05-12 12:54:58 -04:00
|
|
|
local _MODULE_Y_ = 380
|
2017-07-19 00:36:15 -04:00
|
|
|
local _TEXT_SPACING_ = 20
|
|
|
|
local _PLOT_SEC_BREAK_ = 20
|
2021-02-02 18:21:32 -05:00
|
|
|
local _PLOT_HEIGHT_ = 56
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local power_label_function = function(watts) return watts..' W' end
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local calculate_power = function(prev_cnt, cnt, update_frequency)
|
2017-07-19 00:36:15 -04:00
|
|
|
if cnt > prev_cnt then
|
|
|
|
return (cnt - prev_cnt) * update_frequency * 0.000001
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-11 20:26:02 -04:00
|
|
|
local power_format_function = function(watts)
|
|
|
|
return Util.precision_round_to_string(watts, 3).." W"
|
|
|
|
end
|
|
|
|
|
|
|
|
local ac_format_function = function(watts)
|
|
|
|
if watts == 0 then
|
|
|
|
return "A/C"
|
|
|
|
else
|
|
|
|
return power_format_function(watts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local header = Common.Header(
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.RIGHT_X,
|
2021-07-05 23:27:43 -04:00
|
|
|
_MODULE_Y_,
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.SECTION_WIDTH,
|
2021-07-05 23:27:43 -04:00
|
|
|
'POWER'
|
|
|
|
)
|
|
|
|
|
|
|
|
local pkg0 = Common.initLabeledScalePlot(
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.RIGHT_X,
|
2021-07-05 23:27:43 -04:00
|
|
|
header.bottom_y,
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.SECTION_WIDTH,
|
2021-07-05 23:27:43 -04:00
|
|
|
_PLOT_HEIGHT_,
|
2021-07-11 20:26:02 -04:00
|
|
|
power_format_function,
|
2021-07-05 23:27:43 -04:00
|
|
|
power_label_function,
|
|
|
|
_PLOT_SEC_BREAK_,
|
2021-07-13 22:54:41 -04:00
|
|
|
'PKG0',
|
|
|
|
0
|
2021-07-05 23:27:43 -04:00
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2018-08-05 18:04:22 -04:00
|
|
|
local _CORE_Y_ = header.bottom_y + _TEXT_SPACING_ + _PLOT_SEC_BREAK_ + _PLOT_HEIGHT_
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local dram = Common.initLabeledScalePlot(
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.RIGHT_X,
|
2021-07-05 23:27:43 -04:00
|
|
|
_CORE_Y_,
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.SECTION_WIDTH,
|
2021-07-05 23:27:43 -04:00
|
|
|
_PLOT_HEIGHT_,
|
2021-07-11 20:26:02 -04:00
|
|
|
power_format_function,
|
2021-07-05 23:27:43 -04:00
|
|
|
power_label_function,
|
|
|
|
_PLOT_SEC_BREAK_,
|
2021-07-13 22:54:41 -04:00
|
|
|
'DRAM',
|
|
|
|
0
|
2021-07-05 23:27:43 -04:00
|
|
|
)
|
|
|
|
dram.value.append_end = ' W'
|
|
|
|
|
|
|
|
local battery_draw = Common.initLabeledScalePlot(
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.RIGHT_X,
|
2021-07-05 23:27:43 -04:00
|
|
|
_CORE_Y_ + _PLOT_SEC_BREAK_ * 2 + _PLOT_HEIGHT_,
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.SECTION_WIDTH,
|
2021-07-05 23:27:43 -04:00
|
|
|
_PLOT_HEIGHT_,
|
2021-07-11 20:26:02 -04:00
|
|
|
ac_format_function,
|
2021-07-05 23:27:43 -04:00
|
|
|
power_label_function,
|
|
|
|
_PLOT_SEC_BREAK_,
|
2021-07-13 22:54:41 -04:00
|
|
|
'Battery Draw',
|
|
|
|
0
|
2021-07-05 23:27:43 -04:00
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local PKG0_PATH = '/sys/class/powercap/intel-rapl:0/energy_uj'
|
|
|
|
local DRAM_PATH = '/sys/class/powercap/intel-rapl:0:2/energy_uj'
|
|
|
|
|
2017-07-19 00:43:44 -04:00
|
|
|
local prev_pkg0_uj_cnt = Util.read_file(PKG0_PATH, nil, '*n')
|
|
|
|
local prev_dram_uj_cnt = Util.read_file(DRAM_PATH, nil, '*n')
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local update = function(cr, update_frequency, is_using_ac)
|
2021-07-05 23:27:43 -04:00
|
|
|
local pkg0_uj_cnt = Util.read_file(PKG0_PATH, nil, '*n')
|
|
|
|
local dram_uj_cnt = Util.read_file(DRAM_PATH, nil, '*n')
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local pkg0_power = calculate_power(prev_pkg0_uj_cnt, pkg0_uj_cnt, update_frequency)
|
|
|
|
|
2021-07-11 20:26:02 -04:00
|
|
|
-- Common.annotated_scale_plot_set(pkg0, cr, Util.precision_round_to_string(pkg0_power, 3), pkg0_power)
|
|
|
|
Common.annotated_scale_plot_set(pkg0, cr, pkg0_power)
|
2021-07-05 23:27:43 -04:00
|
|
|
|
|
|
|
local dram_power = calculate_power(prev_dram_uj_cnt, dram_uj_cnt, update_frequency)
|
|
|
|
|
2021-07-11 20:26:02 -04:00
|
|
|
-- Common.annotated_scale_plot_set(dram, cr, Util.precision_round_to_string(dram_power, 3), dram_power)
|
|
|
|
Common.annotated_scale_plot_set(dram, cr, dram_power)
|
2021-07-05 23:27:43 -04:00
|
|
|
|
|
|
|
prev_pkg0_uj_cnt = pkg0_uj_cnt
|
|
|
|
prev_dram_uj_cnt = dram_uj_cnt
|
|
|
|
|
|
|
|
if is_using_ac then
|
2021-07-11 20:26:02 -04:00
|
|
|
-- Common.annotated_scale_plot_set(battery_draw, cr, 'A/C', 0)
|
|
|
|
Common.annotated_scale_plot_set(battery_draw, cr, 0)
|
2021-07-05 23:27:43 -04:00
|
|
|
else
|
|
|
|
local current = Util.read_file('/sys/class/power_supply/BAT0/current_now', nil, '*n')
|
|
|
|
local voltage = Util.read_file('/sys/class/power_supply/BAT0/voltage_now', nil, '*n')
|
|
|
|
local power = current * voltage * 0.000000000001
|
2021-07-11 20:26:02 -04:00
|
|
|
-- local t = Util.precision_round_to_string(power, 3)..' W'
|
|
|
|
-- Common.annotated_scale_plot_set(battery_draw, cr, t, power)
|
|
|
|
Common.annotated_scale_plot_set(battery_draw, cr, power)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
_MODULE_Y_ = nil
|
|
|
|
_TEXT_SPACING_ = nil
|
|
|
|
_PLOT_SEC_BREAK_ = nil
|
|
|
|
_PLOT_HEIGHT_ = nil
|
2018-02-10 13:41:10 -05:00
|
|
|
_CORE_Y_ = nil
|
2018-08-05 11:22:07 -04:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
M.draw_static = function(cr)
|
|
|
|
Common.drawHeader(cr, header)
|
|
|
|
Common.annotated_scale_plot_draw_static(pkg0, cr)
|
|
|
|
Common.annotated_scale_plot_draw_static(dram, cr)
|
|
|
|
Common.annotated_scale_plot_draw_static(battery_draw, cr)
|
2018-08-05 11:22:07 -04:00
|
|
|
end
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
M.draw_dynamic = function(cr, update_frequency, is_using_ac)
|
2018-08-05 11:08:37 -04:00
|
|
|
update(cr, update_frequency, is_using_ac)
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.annotated_scale_plot_draw_dynamic(pkg0, cr)
|
|
|
|
Common.annotated_scale_plot_draw_dynamic(dram, cr)
|
|
|
|
Common.annotated_scale_plot_draw_dynamic(battery_draw, cr)
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
2018-08-05 11:22:07 -04:00
|
|
|
return M
|