# SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: LicenseRef-NvidiaProprietary # # NVIDIA CORPORATION, its affiliates and licensors retain all intellectual # property and proprietary rights in and to this material, related # documentation and any modifications thereto. Any use, reproduction, # disclosure or distribution of this material and related documentation # without an express license agreement from NVIDIA CORPORATION or # its affiliates is strictly prohibited. """This package defines commonly used utility objects.""" import re from pylibjetsonpower import ( engine_get_names, thermal_get_sensor_names, rail_get_names, fan_get_names, ) update_period = 1000 # update power data and dynamic graph every 1000ms err_symbol = "-" tsensor_off_ret = -256000 int_compiled = re.compile(r"^[+-]?[0-9]+$") float_compiled = re.compile(r"^[+-]?[0-9]+\.[0-9]+$") class PAttrs(): """Define power-related attributes.""" # NVPMODEL POWER_MODE = "POWER_MODE" # Clock STATE = "STATE" CURR_FREQ = "CURR_FREQ" CURR_LOAD = "CURR_LOAD" # Thermal CURR_TEMP = "CURR_TEMP" SW_THROTTLING_TEMP = "SW_THROTTLING_TEMP" SW_SHUTDOWN_TEMP = "SW_SHUTDOWN_TEMP" # Power IN_CURRENT = "IN_CURRENT" IN_POWER = "IN_POWER" IN_VOLTAGE = "IN_VOLTAGE" CRIT_CURRENT = "CRIT_CURRENT" WARN_CURRENT = "WARN_CURRENT" AVG_POWER = "AVG_POWER" # Fan FAN_PROFILE = "FAN_PROFILE" FAN_GOVERNOR = "FAN_GOVERNOR" FAN_CONTROL = "FAN_CONTROL" CURR_PWM = "CURR_PWM" RPM_MEASURED = "RPM_MEASURED" TACH_ENABLE = "TACH_ENABLE" # Disk USED_SIZE = "USED_SIZE" TOTAL_SIZE = "TOTAL_SIZE" class PNames(): """Define power-related names.""" NVPMODEL = "NVPMODEL" CPU = "CPU" IGPU = "IGPU" EMC = "EMC" MEM = "MEM" SWAP = "SWAP" DISK = "DISK" ENGINE_NAMES = engine_get_names() THERMAL_SENSOR_NAMES = sorted(thermal_get_sensor_names()) RAIL_NAMES = rail_get_names() FAN_NAMES = fan_get_names() def str_to_val(val_in_str): """Convert string value into integer or float value if convertible. Args: val_in_str (str): string to be converted to int value or float value Returns: converted value (int or float or None): int value (if convertible) or float value (if convertible) or None otherwise """ int_res = int_compiled.match(val_in_str) float_res = float_compiled.match(val_in_str) if int_res: return int(int_res[0]) elif float_res: return float(float_res[0]) else: return None def kHz2mHz(kHz): return kHz / 1000 def millC2C(milliC): return round(milliC / 1000, 1)