2021-07-29 22:39:38 -04:00
|
|
|
local util = require 'util'
|
2021-07-29 22:18:29 -04:00
|
|
|
local common = require 'common'
|
|
|
|
local geometry = require 'geometry'
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-18 00:21:20 -04:00
|
|
|
return function(update_freq)
|
|
|
|
local MODULE_Y = 380
|
|
|
|
local TEXT_SPACING = 20
|
|
|
|
local PLOT_SEC_BREAK = 20
|
|
|
|
local PLOT_HEIGHT = 56
|
|
|
|
local PKG0_PATH = '/sys/class/powercap/intel-rapl:0/energy_uj'
|
|
|
|
local DRAM_PATH = '/sys/class/powercap/intel-rapl:0:2/energy_uj'
|
2021-07-19 23:58:58 -04:00
|
|
|
local BAT_CURRENT_PATH = '/sys/class/power_supply/BAT0/current_now'
|
|
|
|
local BAT_VOLTAGE_PATH = '/sys/class/power_supply/BAT0/voltage_now'
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-19 23:58:58 -04:00
|
|
|
local read_milli = function(path)
|
2021-07-29 22:39:38 -04:00
|
|
|
return util.read_file(path, nil, '*n') * 0.000001
|
2021-07-19 23:58:58 -04:00
|
|
|
end
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-19 23:58:58 -04:00
|
|
|
local read_pkg0_joules = function()
|
|
|
|
return read_milli(PKG0_PATH)
|
|
|
|
end
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-19 23:58:58 -04:00
|
|
|
local read_dram_joules = function()
|
|
|
|
return read_milli(DRAM_PATH)
|
|
|
|
end
|
|
|
|
|
|
|
|
local read_battery_current = function()
|
|
|
|
return read_milli(BAT_CURRENT_PATH)
|
|
|
|
end
|
|
|
|
|
|
|
|
local read_battery_voltage = function()
|
|
|
|
return read_milli(BAT_VOLTAGE_PATH)
|
|
|
|
end
|
|
|
|
|
|
|
|
local read_battery_power = function(is_using_ac)
|
|
|
|
if is_using_ac then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return read_battery_current() * read_battery_voltage()
|
|
|
|
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-07-29 22:39:38 -04:00
|
|
|
return util.precision_round_to_string(watts, 3)..' W'
|
2021-07-11 20:26:02 -04:00
|
|
|
end
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
local make_rate_plot = function(y, label, init)
|
|
|
|
return common.make_rate_timeseries(
|
2021-07-29 22:18:29 -04:00
|
|
|
geometry.RIGHT_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,
|
|
|
|
init
|
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
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- header
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
local header = common.make_header(
|
2021-07-29 22:18:29 -04:00
|
|
|
geometry.RIGHT_X,
|
2021-07-19 23:58:58 -04:00
|
|
|
MODULE_Y,
|
2021-07-29 22:18:29 -04:00
|
|
|
geometry.SECTION_WIDTH,
|
2021-07-19 23:58:58 -04:00
|
|
|
'POWER'
|
|
|
|
)
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- package 0 power plot
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
local pkg0 = make_rate_plot(header.bottom_y, '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
|
|
|
|
2021-07-19 23:58:58 -04:00
|
|
|
local DRAM_Y = header.bottom_y + TEXT_SPACING + PLOT_SEC_BREAK + PLOT_HEIGHT
|
2021-07-29 23:04:39 -04:00
|
|
|
local dram = make_rate_plot(DRAM_Y, '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
|
|
|
|
2021-07-19 23:58:58 -04:00
|
|
|
local BAT_Y = DRAM_Y + PLOT_SEC_BREAK * 2 + PLOT_HEIGHT
|
2021-07-30 22:46:20 -04:00
|
|
|
local bat = common.make_tagged_scaled_timeseries(
|
2021-07-29 22:18:29 -04:00
|
|
|
geometry.RIGHT_X,
|
2021-07-19 23:58:58 -04:00
|
|
|
BAT_Y,
|
2021-07-29 22:18:29 -04:00
|
|
|
geometry.SECTION_WIDTH,
|
2021-07-19 23:58:58 -04:00
|
|
|
PLOT_HEIGHT,
|
|
|
|
format_ac,
|
|
|
|
power_label_function,
|
|
|
|
PLOT_SEC_BREAK,
|
2021-07-18 00:21:20 -04:00
|
|
|
'Battery Draw',
|
2021-07-19 23:58:58 -04:00
|
|
|
0,
|
|
|
|
update_freq
|
2021-07-17 16:43:00 -04:00
|
|
|
)
|
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
|
|
|
|
2021-07-26 23:45:54 -04:00
|
|
|
local update = function(is_using_ac)
|
2021-07-29 22:18:29 -04:00
|
|
|
common.update_rate_timeseries(pkg0, read_pkg0_joules())
|
|
|
|
common.update_rate_timeseries(dram, read_dram_joules())
|
2021-07-30 22:46:20 -04:00
|
|
|
common.tagged_scaled_timeseries_set(bat, read_battery_power(is_using_ac))
|
2021-07-17 00:17:22 -04:00
|
|
|
end
|
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
local draw_static = function(cr)
|
2021-07-29 23:04:39 -04:00
|
|
|
common.draw_header(cr, header)
|
2021-07-30 22:46:20 -04:00
|
|
|
common.tagged_scaled_timeseries_draw_static(pkg0, cr)
|
|
|
|
common.tagged_scaled_timeseries_draw_static(dram, cr)
|
|
|
|
common.tagged_scaled_timeseries_draw_static(bat, cr)
|
2021-07-17 16:43:00 -04:00
|
|
|
end
|
|
|
|
|
2021-07-27 23:47:26 -04:00
|
|
|
local draw_dynamic = function(cr)
|
2021-07-30 22:46:20 -04:00
|
|
|
common.tagged_scaled_timeseries_draw_dynamic(pkg0, cr)
|
|
|
|
common.tagged_scaled_timeseries_draw_dynamic(dram, cr)
|
|
|
|
common.tagged_scaled_timeseries_draw_dynamic(bat, cr)
|
2021-07-17 00:17:22 -04:00
|
|
|
end
|
|
|
|
|
2021-07-27 23:47:26 -04:00
|
|
|
return {static = draw_static, dynamic = draw_dynamic, update = update}
|
2021-07-17 00:17:22 -04:00
|
|
|
end
|