[lib] Enhance Logger: gpu_metrics + enable console out
* Updates:
- Env variable RSMI_LOGGING=0 or any other value
-> all logging off
- Env variable RSMI_LOGGING=1 -> logs only
- Env variable RSMI_LOGGING=2 -> console only
- Env variable RSMI_LOGGING=3 -> both logs + console
- Metrics output includes hexdump of current file
and decoded metrics (functions: logHexDump
and log_gpu_metrics)
- System info gathered, now includes if system's
perceived endianness - little or big endian
helpful for viewing decoded hexdump or any
binary translation
- Added templates for printing unsigned hex
(print_unsigned_hex_and_int), unsigned integers
(print_unsigned_int), and printing both unsigned
hex and int with an optional header
(print_unsigned_hex_and_int)
- Fixed some build compile warnings/errors -
ex. doing strncpys for sku or board names
this operation is expected and needed
and for temp file writes if unsuccessful
we now properly send RSMI_STATUS_FILE_ERROR
- Fixed on RHEL 8.8/9.x logrotate does not properly
initialize
Change-Id: Ifa0f0218c9cafd0a8cd6aa8e7f94d61e9107200f
Signed-off-by: Charis Poag <Charis.Poag@amd.com>
[ROCm/amdsmi commit: 9c7eed7edc]
This commit is contained in:
@@ -100,6 +100,7 @@ typedef enum LOG_TYPE {
|
||||
NO_LOG = 1,
|
||||
CONSOLE = 2,
|
||||
FILE_LOG = 3,
|
||||
BOTH_FILE_AND_CONSOLE = 4
|
||||
} LogType;
|
||||
|
||||
class Logger {
|
||||
|
||||
@@ -115,6 +115,7 @@ class RocmSMI {
|
||||
const RocmSMI_env_vars& getEnv(void);
|
||||
void printEnvVarInfo(void);
|
||||
bool isLoggingOn(void);
|
||||
uint32_t getLogSetting(void);
|
||||
static const std::map<amd::smi::DevInfoTypes, std::string> devInfoTypesStrings;
|
||||
|
||||
private:
|
||||
|
||||
@@ -48,6 +48,9 @@
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <type_traits>
|
||||
|
||||
#include "rocm_smi/rocm_smi_device.h"
|
||||
|
||||
@@ -94,8 +97,52 @@ GetDevBinaryBlob(amd::smi::DevInfoTypes type,
|
||||
rsmi_status_t ErrnoToRsmiStatus(int err);
|
||||
std::string getRSMIStatusString(rsmi_status_t ret);
|
||||
std::tuple<bool, std::string, std::string, std::string, std::string,
|
||||
std::string, std::string, std::string> getSystemDetails(void);
|
||||
std::string, std::string, std::string, std::string>
|
||||
getSystemDetails(void);
|
||||
void logSystemDetails(void);
|
||||
void logHexDump(const char *desc, const void *addr, const size_t len,
|
||||
size_t perLine);
|
||||
bool isSystemBigEndian();
|
||||
template <typename T>
|
||||
std::string print_int_as_hex(T i, bool showHexNotation=true) {
|
||||
std::stringstream ss;
|
||||
if (showHexNotation) {
|
||||
ss << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex;
|
||||
} else {
|
||||
ss << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex;
|
||||
}
|
||||
|
||||
if (std::is_same<std::uint8_t, T>::value) {
|
||||
ss << static_cast<unsigned int>(i|0);
|
||||
} else if (std::is_same<std::int8_t, T>::value) {
|
||||
ss << static_cast<int>(static_cast<uint8_t>(i|0));
|
||||
} else if (std::is_signed<T>::value) {
|
||||
ss << static_cast<long long int>(i | 0);
|
||||
} else {
|
||||
ss << static_cast<unsigned long long int>(i | 0);
|
||||
}
|
||||
ss << std::dec;
|
||||
return ss.str();
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
std::string print_unsigned_int(T i) {
|
||||
std::stringstream ss;
|
||||
ss << static_cast<unsigned long long int>(i | 0);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string print_unsigned_hex_and_int(T i, std::string heading="") {
|
||||
std::stringstream ss;
|
||||
if (heading.empty() == false) {
|
||||
ss << "\n" << heading << " = ";
|
||||
}
|
||||
ss << "Hex (MSB): " << print_int_as_hex(i) << ", "
|
||||
<< "Unsigned int: " << print_unsigned_int(i) << ", "
|
||||
<< "Byte Size: " << sizeof(T);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
struct pthread_wrap {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user