wsl/hsakmt: Refactor logging function
Signed-off-by: Horatio Zhang <Hongkun.Zhang@amd.com> Reviewed-by: Flora Cui <flora.cui@amd.com> Reviewed-by: Shane Xiao <shane.xiao@amd.com> Part-of: <http://10.67.69.192/wsl/libhsakmt/-/merge_requests/40>
This commit is contained in:
zatwierdzone przez
Frank Min
rodzic
5cd49fb600
commit
f648688c45
+28
-8
@@ -90,15 +90,35 @@ extern int PAGE_SHIFT;
|
||||
|
||||
/* HSA Thunk logging usage */
|
||||
extern int hsakmt_debug_level;
|
||||
#define hsakmt_print(level, fmt, ...) \
|
||||
do { if (level <= hsakmt_debug_level) fprintf(stderr, fmt, ##__VA_ARGS__); } while (0)
|
||||
#define HSAKMT_DEBUG_LEVEL_DEFAULT -1
|
||||
#define HSAKMT_DEBUG_LEVEL_ERR 3
|
||||
#define HSAKMT_DEBUG_LEVEL_WARNING 4
|
||||
#define HSAKMT_DEBUG_LEVEL_INFO 6
|
||||
#define HSAKMT_DEBUG_LEVEL_DEBUG 7
|
||||
#define get_thread_id() \
|
||||
([]() -> std::string { \
|
||||
std::stringstream str_thrd_id; \
|
||||
str_thrd_id << std::hex << std::this_thread::get_id(); \
|
||||
return str_thrd_id.str(); \
|
||||
})()
|
||||
#define hsakmt_print_common(stream, fmt, ...) \
|
||||
do { \
|
||||
fprintf(stream, "pid:%d tid:0x%s [%s] " fmt, getpid(), get_thread_id().c_str(), __FUNCTION__, ##__VA_ARGS__); \
|
||||
fflush(stream); \
|
||||
} while (false)
|
||||
#ifdef NDEBUG
|
||||
#define hsakmt_print(level, fmt, ...) \
|
||||
do { } while (false)
|
||||
#else
|
||||
#define hsakmt_print(level, fmt, ...) \
|
||||
do { \
|
||||
if (level <= hsakmt_debug_level) { \
|
||||
hsakmt_print_common(stdout, fmt, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while (false)
|
||||
#endif
|
||||
#define HSAKMT_DEBUG_LEVEL_ERR -1
|
||||
#define HSAKMT_DEBUG_LEVEL_DEFAULT 3
|
||||
#define HSAKMT_DEBUG_LEVEL_WARNING 4
|
||||
#define HSAKMT_DEBUG_LEVEL_INFO 6
|
||||
#define HSAKMT_DEBUG_LEVEL_DEBUG 7
|
||||
#define pr_err(fmt, ...) \
|
||||
hsakmt_print(HSAKMT_DEBUG_LEVEL_ERR, fmt, ##__VA_ARGS__)
|
||||
hsakmt_print_common(stderr, fmt, ##__VA_ARGS__)
|
||||
#define pr_warn(fmt, ...) \
|
||||
hsakmt_print(HSAKMT_DEBUG_LEVEL_WARNING, fmt, ##__VA_ARGS__)
|
||||
#define pr_info(fmt, ...) \
|
||||
|
||||
+1
-4
@@ -108,10 +108,7 @@ static HSAKMT_STATUS init_vars_from_env(void) {
|
||||
|
||||
envvar = getenv("HSAKMT_DEBUG_LEVEL");
|
||||
if (envvar) {
|
||||
debug_level = atoi(envvar);
|
||||
if (debug_level >= HSAKMT_DEBUG_LEVEL_ERR &&
|
||||
debug_level <= HSAKMT_DEBUG_LEVEL_DEBUG)
|
||||
hsakmt_debug_level = debug_level;
|
||||
hsakmt_debug_level = atoi(envvar);
|
||||
}
|
||||
|
||||
/* Check whether to support Zero frame buffer */
|
||||
|
||||
Reference in New Issue
Block a user