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-08-08 19:12:31 -04:00
|
|
|
local sys = require 'sys'
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2022-07-17 18:40:24 -04:00
|
|
|
return function(update_freq, config, common, width, point)
|
2021-07-18 00:21:20 -04:00
|
|
|
local TEXT_SPACING = 20
|
|
|
|
local PLOT_SEC_BREAK = 20
|
|
|
|
local PLOT_HEIGHT = 56
|
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
|
|
|
|
|
2022-07-16 23:48:01 -04:00
|
|
|
local mk_rate_plot = function(label, address, y)
|
|
|
|
local read_joules = sys.intel_powercap_reader(address)
|
2022-07-13 01:38:18 -04:00
|
|
|
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,
|
2022-07-17 12:40:36 -04:00
|
|
|
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-16 23:48:01 -04:00
|
|
|
read_joules()
|
2022-07-13 01:38:18 -04:00
|
|
|
)
|
2022-07-17 18:54:23 -04:00
|
|
|
return common.mk_acc(
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-13 01:38:18 -04:00
|
|
|
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
2022-07-16 23:48:01 -04:00
|
|
|
function(_) common.update_rate_timeseries(obj, read_joules()) end,
|
2022-07-13 01:38:18 -04:00
|
|
|
mk_static(obj),
|
|
|
|
mk_dynamic(obj)
|
2021-07-18 00:21:20 -04:00
|
|
|
)
|
|
|
|
end
|
2021-07-05 23:27:43 -04:00
|
|
|
|
2022-07-16 23:48:01 -04:00
|
|
|
local mk_rate_blockspec = function(spec)
|
2022-07-17 01:25:53 -04:00
|
|
|
local f = pure.partial(mk_rate_plot, spec.name, spec.address)
|
2022-07-16 23:48:01 -04:00
|
|
|
return {f, true, TEXT_SPACING}
|
|
|
|
end
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2021-07-18 00:21:20 -04:00
|
|
|
-----------------------------------------------------------------------------
|
2022-07-16 23:48:01 -04:00
|
|
|
-- battery power plot
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2022-07-16 23:48:01 -04:00
|
|
|
local _read_battery_power = sys.battery_power_reader(config.battery)
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2022-07-16 23:48:01 -04:00
|
|
|
local read_battery_power = function(is_using_ac)
|
|
|
|
if is_using_ac then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return _read_battery_power()
|
|
|
|
end
|
|
|
|
end
|
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)
|
2022-07-16 23:48:01 -04:00
|
|
|
local read_bat_status = sys.battery_status_reader(config.battery)
|
2022-07-13 01:38:18 -04:00
|
|
|
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,
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-13 01:38:18 -04:00
|
|
|
PLOT_HEIGHT,
|
|
|
|
format_ac,
|
|
|
|
power_label_function,
|
|
|
|
PLOT_SEC_BREAK,
|
|
|
|
'Battery Draw',
|
|
|
|
0,
|
|
|
|
update_freq
|
|
|
|
)
|
2022-07-17 18:54:23 -04:00
|
|
|
return common.mk_acc(
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-13 01:38:18 -04:00
|
|
|
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
2022-07-16 00:27:27 -04:00
|
|
|
function()
|
|
|
|
common.tagged_scaled_timeseries_set(
|
|
|
|
obj,
|
2022-07-16 23:48:01 -04:00
|
|
|
read_battery_power(read_bat_status())
|
|
|
|
)
|
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-17 19:12:31 -04:00
|
|
|
return {
|
|
|
|
header = 'POWER',
|
|
|
|
point = point,
|
|
|
|
width = width,
|
2022-07-17 22:30:38 -04:00
|
|
|
set_state = nil,
|
2022-07-17 19:12:31 -04:00
|
|
|
top = pure.concat(
|
2022-07-16 23:48:01 -04:00
|
|
|
pure.map(mk_rate_blockspec, config.rapl_specs),
|
2022-07-19 00:54:46 -04:00
|
|
|
{{mk_bat, config.battery ~= '', 0}}
|
2022-07-16 23:48:01 -04:00
|
|
|
)
|
2022-07-17 19:12:31 -04:00
|
|
|
}
|
2021-07-17 00:17:22 -04:00
|
|
|
end
|