2021-08-08 15:58:53 -04:00
|
|
|
local format = require 'format'
|
2022-07-13 01:38:18 -04:00
|
|
|
local pure = require 'pure'
|
2021-07-29 22:18:29 -04:00
|
|
|
local common = require 'common'
|
|
|
|
local geometry = require 'geometry'
|
2021-08-08 19:12:31 -04:00
|
|
|
local sys = require 'sys'
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2022-07-14 20:13:29 -04:00
|
|
|
return function(update_freq, battery, point)
|
2021-07-18 00:21:20 -04:00
|
|
|
local TEXT_SPACING = 20
|
|
|
|
local PLOT_SEC_BREAK = 20
|
|
|
|
local PLOT_HEIGHT = 56
|
2021-08-08 19:12:31 -04:00
|
|
|
local read_pkg0_joules = sys.intel_powercap_reader('intel-rapl:0')
|
|
|
|
local read_dram_joules = sys.intel_powercap_reader('intel-rapl:0:2')
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-08-08 19:12:31 -04:00
|
|
|
local _read_battery_power = sys.battery_power_reader(battery)
|
2021-07-19 23:58:58 -04:00
|
|
|
|
|
|
|
local read_battery_power = function(is_using_ac)
|
|
|
|
if is_using_ac then
|
|
|
|
return 0
|
|
|
|
else
|
2021-08-08 19:12:31 -04:00
|
|
|
return _read_battery_power()
|
2021-07-19 23:58:58 -04:00
|
|
|
end
|
|
|
|
end
|
2021-07-11 20:26:02 -04:00
|
|
|
|
2021-07-18 19:18:14 -04:00
|
|
|
local power_label_function = function(plot_max)
|
2021-07-29 22:18:29 -04:00
|
|
|
local fmt = common.y_label_format_string(plot_max, 'W')
|
2021-07-18 19:18:14 -04:00
|
|
|
return function(watts) return string.format(fmt, watts) end
|
|
|
|
end
|
2021-07-18 00:21:20 -04:00
|
|
|
|
2021-07-19 23:58:58 -04:00
|
|
|
local format_rapl = function(watts)
|
2021-08-08 15:58:53 -04:00
|
|
|
return format.precision_round_to_string(watts, 3)..' W'
|
2021-07-11 20:26:02 -04:00
|
|
|
end
|
|
|
|
|
2022-07-13 01:38:18 -04:00
|
|
|
local mk_static = function(obj)
|
|
|
|
return pure.partial(common.tagged_scaled_timeseries_draw_static, obj)
|
|
|
|
end
|
|
|
|
|
|
|
|
local mk_dynamic = function(obj)
|
|
|
|
return pure.partial(common.tagged_scaled_timeseries_draw_dynamic, obj)
|
|
|
|
end
|
|
|
|
|
|
|
|
local mk_rate_plot = function(label, read, y)
|
|
|
|
local obj = common.make_rate_timeseries(
|
2022-07-14 20:13:29 -04:00
|
|
|
point.x,
|
2021-07-18 00:21:20 -04:00
|
|
|
y,
|
2021-07-29 22:18:29 -04:00
|
|
|
geometry.SECTION_WIDTH,
|
2021-07-18 00:21:20 -04:00
|
|
|
PLOT_HEIGHT,
|
2021-07-19 23:58:58 -04:00
|
|
|
format_rapl,
|
2021-07-18 00:21:20 -04:00
|
|
|
power_label_function,
|
|
|
|
PLOT_SEC_BREAK,
|
|
|
|
label,
|
|
|
|
0,
|
2021-07-19 23:58:58 -04:00
|
|
|
update_freq,
|
2022-07-13 01:38:18 -04:00
|
|
|
read()
|
|
|
|
)
|
|
|
|
return common.mk_acc(
|
2022-07-16 00:00:06 -04:00
|
|
|
geometry.SECTION_WIDTH,
|
2022-07-13 01:38:18 -04:00
|
|
|
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
|
|
|
function(_) common.update_rate_timeseries(obj, read()) end,
|
|
|
|
mk_static(obj),
|
|
|
|
mk_dynamic(obj)
|
2021-07-18 00:21:20 -04:00
|
|
|
)
|
|
|
|
end
|
2021-07-05 23:27:43 -04:00
|
|
|
|
2021-07-19 23:58:58 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- package 0 power plot
|
|
|
|
|
2022-07-13 01:38:18 -04:00
|
|
|
local mk_pkg0 = pure.partial(mk_rate_plot, 'PKG0', read_pkg0_joules)
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2021-07-18 00:21:20 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- DRAM power plot
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2022-07-13 01:38:18 -04:00
|
|
|
local mk_dram = pure.partial(mk_rate_plot, 'DRAM', read_dram_joules)
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2021-07-18 00:21:20 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- battery power plot
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2021-07-19 23:58:58 -04:00
|
|
|
local format_ac = function(watts)
|
2021-07-18 00:21:20 -04:00
|
|
|
if watts == 0 then
|
|
|
|
return "A/C"
|
|
|
|
else
|
2021-07-19 23:58:58 -04:00
|
|
|
return format_rapl(watts)
|
2021-07-18 00:21:20 -04:00
|
|
|
end
|
|
|
|
end
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2022-07-13 01:38:18 -04:00
|
|
|
local mk_bat = function(y)
|
|
|
|
local obj = common.make_tagged_scaled_timeseries(
|
2022-07-14 20:13:29 -04:00
|
|
|
point.x,
|
2022-07-13 01:38:18 -04:00
|
|
|
y,
|
|
|
|
geometry.SECTION_WIDTH,
|
|
|
|
PLOT_HEIGHT,
|
|
|
|
format_ac,
|
|
|
|
power_label_function,
|
|
|
|
PLOT_SEC_BREAK,
|
|
|
|
'Battery Draw',
|
|
|
|
0,
|
|
|
|
update_freq
|
|
|
|
)
|
|
|
|
return common.mk_acc(
|
2022-07-16 00:00:06 -04:00
|
|
|
geometry.SECTION_WIDTH,
|
2022-07-13 01:38:18 -04:00
|
|
|
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
2022-07-16 00:00:06 -04:00
|
|
|
function(state)
|
|
|
|
common.tagged_scaled_timeseries_set(obj, read_battery_power(state.is_using_ac))
|
2022-07-13 01:38:18 -04:00
|
|
|
end,
|
|
|
|
mk_static(obj),
|
|
|
|
mk_dynamic(obj)
|
|
|
|
)
|
|
|
|
end
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-18 00:21:20 -04:00
|
|
|
-----------------------------------------------------------------------------
|
2021-07-19 23:58:58 -04:00
|
|
|
-- main functions
|
2021-07-18 00:21:20 -04:00
|
|
|
|
2022-07-14 20:13:29 -04:00
|
|
|
return common.reduce_blocks_(
|
2022-07-14 22:49:08 -04:00
|
|
|
'POWER',
|
|
|
|
point,
|
|
|
|
geometry.SECTION_WIDTH,
|
2022-07-13 01:38:18 -04:00
|
|
|
{
|
|
|
|
common.mk_block(mk_pkg0, true, 0),
|
|
|
|
common.mk_block(mk_dram, true, TEXT_SPACING),
|
|
|
|
common.mk_block(mk_bat, true, TEXT_SPACING),
|
|
|
|
}
|
|
|
|
)
|
2021-07-17 00:17:22 -04:00
|
|
|
end
|