Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/include/log_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,33 @@ extern int g_log_level;
/* Call once during early initialization to cache LIBCUDA_LOG_LEVEL. */
void log_utils_init(void);

/*
* Level accessor used by the macros below. Resolves LIBCUDA_LOG_LEVEL on first
* use, so messages emitted before log_utils_init() runs honour it as well.
*/
int log_level(void);

#ifdef FILEDEBUG
#define LOG_DEBUG(msg, ...) { \
if (g_log_level >= 4) {\
if (log_level() >= 4) {\
if (fp1==NULL) fp1 = fopen ("/tmp/vgpulog", "a"); \
fprintf(fp1, "[HAMI-core Debug(%d:%ld:%s:%d)]: "msg"\n",getpid(),pthread_self(),basename(__FILE__),__LINE__,##__VA_ARGS__); \
}\
}
#define LOG_INFO(msg, ...) { \
if (g_log_level >= 3) {\
if (log_level() >= 3) {\
if (fp1==NULL) fp1 = fopen ("/tmp/vgpulog", "a"); \
fprintf(fp1, "[HAMI-core Info(%d:%ld:%s:%d)]: "msg"\n", getpid(),pthread_self(),basename(__FILE__),__LINE__,##__VA_ARGS__); \
}\
}
#define LOG_WARN(msg, ...) { \
if (g_log_level >= 2) {\
if (log_level() >= 2) {\
if (fp1==NULL) fp1 = fopen ("/tmp/vgpulog", "a"); \
fprintf(fp1, "[HAMI-core Warn(%d:%ld:%s:%d)]: "msg"\n", getpid(),pthread_self(),basename(__FILE__),__LINE__,##__VA_ARGS__); \
}\
}
#define LOG_MSG(msg, ...) { \
if (g_log_level >= 2) {\
if (log_level() >= 2) {\
if (fp1==NULL) fp1 = fopen ("/tmp/vgpulog", "a"); \
fprintf(fp1, "[HAMI-core Msg(%d:%ld:%s:%d)]: "msg"\n", getpid(),pthread_self(),basename(__FILE__),__LINE__,##__VA_ARGS__); \
}\
Expand All @@ -53,22 +59,22 @@ void log_utils_init(void);
}
#else
#define LOG_DEBUG(msg, ...) { \
if (g_log_level >= 4) {\
if (log_level() >= 4) {\
fprintf(stderr, "[HAMI-core Debug(%d:%ld:%s:%d)]: "msg"\n",getpid(),pthread_self(),basename(__FILE__),__LINE__,##__VA_ARGS__); \
}\
}
#define LOG_INFO(msg, ...) { \
if (g_log_level >= 3) {\
if (log_level() >= 3) {\
fprintf(stderr, "[HAMI-core Info(%d:%ld:%s:%d)]: "msg"\n", getpid(),pthread_self(),basename(__FILE__),__LINE__,##__VA_ARGS__); \
}\
}
#define LOG_WARN(msg, ...) { \
if (g_log_level >= 2) {\
if (log_level() >= 2) {\
fprintf(stderr, "[HAMI-core Warn(%d:%ld:%s:%d)]: "msg"\n", getpid(),pthread_self(),basename(__FILE__),__LINE__,##__VA_ARGS__); \
}\
}
#define LOG_MSG(msg, ...) { \
if (g_log_level >= 2) {\
if (log_level() >= 2) {\
fprintf(stderr, "[HAMI-core Msg(%d:%ld:%s:%d)]: "msg"\n", getpid(),pthread_self(),basename(__FILE__),__LINE__,##__VA_ARGS__); \
}\
}
Expand Down
13 changes: 13 additions & 0 deletions src/log_utils.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

/*
* Cached log level, read once from LIBCUDA_LOG_LEVEL by log_utils_init().
Expand All @@ -9,10 +10,22 @@ int g_log_level = 2;

FILE *fp1 = NULL;

static pthread_once_t log_level_once = PTHREAD_ONCE_INIT;

void log_utils_init(void) {
const char *env = getenv("LIBCUDA_LOG_LEVEL");
if (env != NULL) {
g_log_level = atoi(env);
}
/* else: keep default of 2 (warn level) */
}

/*
* The dlsym hook and preInit() log before preInit() reaches log_utils_init(),
* so reading the cached value directly ignores LIBCUDA_LOG_LEVEL for exactly
* those messages. Resolve on first use instead.
*/
int log_level(void) {
pthread_once(&log_level_once, log_utils_init);
return g_log_level;
}
Loading