From e408c46775f740966ddd5375d90be3eff182d966 Mon Sep 17 00:00:00 2001 From: Maisam Arif Date: Sun, 24 Sep 2023 01:17:54 -0500 Subject: [PATCH] Added energy counter in metric --energy Change-Id: I8ea09af79a1a37f53038d06a89eeac0882c47a1d Signed-off-by: Maisam Arif [ROCm/amdsmi commit: 842b290a446dea71e9051462bfe5859d8a52266f] --- projects/amdsmi/amdsmi_cli/amdsmi_commands.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py index 41ccfc4fe1..179296ff40 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py @@ -1106,7 +1106,21 @@ class AMDSMICommands(): values_dict['xgmi_err'] = "N/A" logging.debug("Failed to get xgmi error status for gpu %s | %s", args.gpu, e.get_error_info()) if args.energy: - pass + try: + energy_dict = amdsmi_interface.amdsmi_get_energy_count(args.gpu) + + energy = energy_dict['power'] * round(energy_dict['counter_resolution'], 1) + energy /= 1000000 + energy = round(energy, 3) + + if self.logger.is_human_readable_format(): + unit = 'J' + energy = f"{energy} {unit}" + + values_dict['energy'] = {"total_energy_consumption" : energy} + except amdsmi_interface.AmdSmiLibraryException as e: + values_dict['energy'] = "N/A" + logging.debug("Failed to get energy usage for gpu %s | %s", args.gpu, e.get_error_info()) if self.helpers.is_linux() and (self.helpers.is_baremetal() or self.helpers.is_virtual_os()): if args.mem_usage: