From: jinhyung.jo Date: Mon, 27 Jul 2015 10:31:59 +0000 (+0900) Subject: VIGS/YaGL: Modified the logging format X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.2~286^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fdc9dfa96fc5d952d583ef920bc3765c9549f0dc;p=sdk%2Femulator%2Fqemu.git VIGS/YaGL: Modified the logging format Adjust the format of the tizen devices. Change-Id: I19502e3a030be6a60c472f3d48369e8ab35681e2 Signed-off-by: Jinhyung Jo --- diff --git a/hw/vigs/vigs_log.c b/hw/vigs/vigs_log.c index f2e776fc94..8fa6218a9b 100644 --- a/hw/vigs/vigs_log.c +++ b/hw/vigs/vigs_log.c @@ -28,48 +28,40 @@ */ #include "vigs_log.h" -#include -#include -#include -#include +#include "qemu-common.h" +#include -static const char *g_log_level_to_str[vigs_log_level_max + 1] = -{ - "OFF", - "ERROR", - "WARN", - "INFO", - "DEBUG", - "TRACE" +/* "OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE" */ +static const char g_log_level_acronym[vigs_log_level_max + 1] = { + '-', 'E', 'W', 'I', 'D', 'T' }; static vigs_log_level g_log_level = vigs_log_level_off; -static void vigs_log_print_current_time(void) +static size_t vigs_log_print_current_time(char *buf, size_t buf_size) { - char buff[128]; #ifdef _WIN32 - struct tm *ptm; + struct tm *ptm = NULL; #else struct tm tm; #endif qemu_timeval tv = { 0, 0 }; time_t ti; + size_t ret_size; qemu_gettimeofday(&tv); - ti = tv.tv_sec; #ifdef _WIN32 ptm = localtime(&ti); - strftime(buff, sizeof(buff), - "%H:%M:%S", ptm); + ret_size = strftime(buf, buf_size, "%H:%M:%S", ptm); #else localtime_r(&ti, &tm); - strftime(buff, sizeof(buff), - "%H:%M:%S", &tm); + ret_size = strftime(buf, buf_size, "%H:%M:%S", &tm); #endif - fprintf(stderr, "%s", buff); + ret_size += g_snprintf(buf + ret_size, buf_size - ret_size, + ".%03ld", (long)tv.tv_usec/1000); + return ret_size; } void vigs_log_init(void) @@ -92,25 +84,33 @@ void vigs_log_cleanup(void) } void vigs_log_event(vigs_log_level log_level, - const char* func, + const char *func, int line, - const char* format, ...) + const char *format, ...) { va_list args; + size_t ret_size; + char log_buf[2048]; - vigs_log_print_current_time(); - fprintf(stderr, - " %-5s %s:%d", - g_log_level_to_str[log_level], - func, - line); + ret_size = vigs_log_print_current_time(log_buf, sizeof(log_buf)); + ret_size += g_snprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, + "|%5d|%1c|%10s|%4d|%s:%d", + qemu_get_thread_id(), + g_log_level_acronym[log_level], + "vigs", + line, + func, + line); if (format) { va_start(args, format); - fprintf(stderr, " - "); - vfprintf(stderr, format, args); + ret_size += g_snprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, " - "); + ret_size += g_vsnprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, format, args); va_end(args); } - fprintf(stderr, "\n"); + g_fprintf(stderr, "%s\n", log_buf); } bool vigs_log_is_enabled_for_level(vigs_log_level log_level) diff --git a/hw/yagl/yagl_log.c b/hw/yagl/yagl_log.c index ceb08956c5..470c709b95 100644 --- a/hw/yagl/yagl_log.c +++ b/hw/yagl/yagl_log.c @@ -28,28 +28,18 @@ */ #include "yagl_log.h" -#include -#include -#include -#include -#include +#include "qemu-common.h" +#include -static const char* g_log_level_to_str[yagl_log_level_max + 1] = -{ - "OFF", - "ERROR", - "WARN", - "INFO", - "DEBUG", - "TRACE" +/* "OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE" */ +static const char g_log_level_acronym[yagl_log_level_max + 1] = { + '-', 'E', 'W', 'I', 'D', 'T' }; -static struct -{ - const char* datatype; - const char* format; -} g_datatype_to_format[] = -{ +static struct { + const char *datatype; + const char *format; +} g_datatype_to_format[] = { { "EGLboolean", "%u" }, { "EGLenum", "0x%x" }, { "EGLint", "%d" }, @@ -80,23 +70,22 @@ static struct }; static yagl_log_level g_log_level = yagl_log_level_off; -static char** g_log_facilities_match = NULL; -static char** g_log_facilities_no_match = NULL; -static bool g_log_func_trace = false; +static char **g_log_facilities_match; +static char **g_log_facilities_no_match; +static bool g_log_func_trace; -static const char* yagl_log_datatype_to_format(const char* type) +static const char *yagl_log_datatype_to_format(const char *type) { unsigned int i; - if (strchr(type, '*')) - { + if (strchr(type, '*')) { return "%p"; } - for (i = 0; i < sizeof(g_datatype_to_format)/sizeof(g_datatype_to_format[0]); ++i) - { - if (strcmp(g_datatype_to_format[i].datatype, type) == 0) - { + for (i = 0; + i < sizeof(g_datatype_to_format)/sizeof(g_datatype_to_format[0]); + ++i) { + if (strcmp(g_datatype_to_format[i].datatype, type) == 0) { return g_datatype_to_format[i].format; } } @@ -104,54 +93,49 @@ static const char* yagl_log_datatype_to_format(const char* type) return NULL; } -static void yagl_log_print_current_time(void) +static size_t yagl_log_print_current_time(char *buf, size_t buf_size) { - char buff[128]; #ifdef _WIN32 - struct tm *ptm; + struct tm *ptm = NULL; #else struct tm tm; #endif qemu_timeval tv = { 0, 0 }; time_t ti; + size_t ret_size; qemu_gettimeofday(&tv); - ti = tv.tv_sec; #ifdef _WIN32 ptm = localtime(&ti); - strftime(buff, sizeof(buff), - "%H:%M:%S", ptm); + ret_size = strftime(buf, buf_size, "%H:%M:%S", ptm); #else localtime_r(&ti, &tm); - strftime(buff, sizeof(buff), - "%H:%M:%S", &tm); + ret_size = strftime(buf, buf_size, "%H:%M:%S", &tm); #endif - fprintf(stderr, "%s", buff); + ret_size += g_snprintf(buf + ret_size, buf_size - ret_size, + ".%03ld", (long)tv.tv_usec/1000); + return ret_size; } /* * Simple asterisk pattern matcher. */ -static bool yagl_log_match(const char* str, const char* expr) +static bool yagl_log_match(const char *str, const char *expr) { - while (*str && *expr) - { + while (*str && *expr) { /* * Swallow '**'. */ while ((*expr == '*') && - (*(expr + 1) == '*')) - { + (*(expr + 1) == '*')) { ++expr; } - if (*expr == '*') - { - if (!*(expr + 1)) - { + if (*expr == '*') { + if (!*(expr + 1)) { /* * Last '*' always matches. */ @@ -163,13 +147,11 @@ static bool yagl_log_match(const char* str, const char* expr) * Search for symbol after the asterisk. */ - while (*str && (*str != *(expr + 1))) - { + while (*str && (*str != *(expr + 1))) { ++str; } - if (!*str) - { + if (!*str) { /* * Reached the end, didn't find symbol following asterisk, * no match. @@ -184,15 +166,12 @@ static bool yagl_log_match(const char* str, const char* expr) ++str; expr += 2; - } - else - { + } else { /* * No asterisk, exact match. */ - if (*str != *expr) - { + if (*str != *expr) { return false; } @@ -205,8 +184,7 @@ static bool yagl_log_match(const char* str, const char* expr) * Remaining '*' always match. */ - while (*expr == '*') - { + while (*expr == '*') { ++expr; } @@ -215,80 +193,67 @@ static bool yagl_log_match(const char* str, const char* expr) void yagl_log_init(void) { - char* level_str = getenv("YAGL_DEBUG"); + char *level_str = getenv("YAGL_DEBUG"); int level = level_str ? atoi(level_str) : yagl_log_level_info; - char* facilities; - char* func_trace; + char *facilities; + char *func_trace; - if (level < 0) - { + if (level < 0) { g_log_level = yagl_log_level_off; - } - else if (level > yagl_log_level_max) - { + } else if (level > yagl_log_level_max) { g_log_level = (yagl_log_level)yagl_log_level_max; - } - else - { + } else { g_log_level = (yagl_log_level)level; } facilities = getenv("YAGL_DEBUG_FACILITIES"); - if (facilities) - { - char* tmp_facilities = facilities; + if (facilities) { + char *tmp_facilities = facilities; int i = 0, num_match = 0, num_no_match = 0; - while (1) - { - char* tmp = strchr(tmp_facilities, ','); + while (1) { + char *tmp = strchr(tmp_facilities, ','); - if (!tmp) - { + if (!tmp) { break; } - if (tmp - tmp_facilities > 0) - { + if (tmp - tmp_facilities > 0) { ++i; } tmp_facilities = tmp + 1; } - if (strlen(tmp_facilities) > 0) - { + if (strlen(tmp_facilities) > 0) { ++i; } - g_log_facilities_match = g_malloc0((i + 1) * sizeof(char*)); - g_log_facilities_no_match = g_malloc0((i + 1) * sizeof(char*)); + g_log_facilities_match = g_malloc0((i + 1) * sizeof(char *)); + g_log_facilities_no_match = g_malloc0((i + 1) * sizeof(char *)); tmp_facilities = facilities; - while (1) - { - char* tmp = strchr(tmp_facilities, ','); + while (1) { + char *tmp = strchr(tmp_facilities, ','); - if (!tmp) - { + if (!tmp) { break; } - if (tmp - tmp_facilities > 0) - { - if (*tmp_facilities == '^') - { - if ((tmp - tmp_facilities - 1) > 0) - { - g_log_facilities_no_match[num_no_match] = g_strndup(tmp_facilities + 1, tmp - tmp_facilities - 1); + if (tmp - tmp_facilities > 0) { + if (*tmp_facilities == '^') { + if ((tmp - tmp_facilities - 1) > 0) { + g_log_facilities_no_match[num_no_match] = + g_strndup(tmp_facilities + 1, + tmp - tmp_facilities - 1); ++num_no_match; } - } - else - { - g_log_facilities_match[num_match] = g_strndup(tmp_facilities, tmp - tmp_facilities); + } else { + g_log_facilities_match[num_match] = + g_strndup(tmp_facilities, + tmp - tmp_facilities); ++num_match; } } @@ -296,18 +261,14 @@ void yagl_log_init(void) tmp_facilities = tmp + 1; } - if (strlen(tmp_facilities) > 0) - { - if (*tmp_facilities == '^') - { - if ((strlen(tmp_facilities) - 1) > 0) - { - g_log_facilities_no_match[num_no_match] = g_strdup(tmp_facilities + 1); + if (strlen(tmp_facilities) > 0) { + if (*tmp_facilities == '^') { + if ((strlen(tmp_facilities) - 1) > 0) { + g_log_facilities_no_match[num_no_match] = + g_strdup(tmp_facilities + 1); ++num_no_match; } - } - else - { + } else { g_log_facilities_match[num_match] = g_strdup(tmp_facilities); ++num_match; } @@ -316,14 +277,12 @@ void yagl_log_init(void) g_log_facilities_no_match[num_no_match] = NULL; g_log_facilities_match[num_match] = NULL; - if (!num_no_match) - { + if (!num_no_match) { g_free(g_log_facilities_no_match); g_log_facilities_no_match = NULL; } - if (!num_match) - { + if (!num_match) { g_free(g_log_facilities_match); g_log_facilities_match = NULL; } @@ -338,20 +297,16 @@ void yagl_log_cleanup(void) { int i; g_log_level = yagl_log_level_off; - if (g_log_facilities_no_match) - { - for (i = 0; g_log_facilities_no_match[i]; ++i) - { + if (g_log_facilities_no_match) { + for (i = 0; g_log_facilities_no_match[i]; ++i) { g_free(g_log_facilities_no_match[i]); g_log_facilities_no_match[i] = NULL; } g_free(g_log_facilities_no_match); g_log_facilities_no_match = NULL; } - if (g_log_facilities_match) - { - for (i = 0; g_log_facilities_match[i]; ++i) - { + if (g_log_facilities_match) { + for (i = 0; g_log_facilities_match[i]; ++i) { g_free(g_log_facilities_match[i]); g_log_facilities_match[i] = NULL; } @@ -364,116 +319,141 @@ void yagl_log_cleanup(void) void yagl_log_event(yagl_log_level log_level, yagl_pid process_id, yagl_tid thread_id, - const char* facility, + const char *facility, int line, - const char* format, ...) + const char *format, ...) { va_list args; - - yagl_log_print_current_time(); - fprintf(stderr, - " %-5s [%u/%u] %s:%d", - g_log_level_to_str[log_level], - process_id, - thread_id, - facility, - line); - if (format) - { + size_t ret_size; + char log_buf[2048]; + + ret_size = yagl_log_print_current_time(log_buf, sizeof(log_buf)); + ret_size += g_snprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, + "|%5d|%1c|%10s|%4d|[%u/%u] %s:%d", + qemu_get_thread_id(), + g_log_level_acronym[log_level], + "yagl", + line, + process_id, + thread_id, + facility, + line); + if (format) { va_start(args, format); - fprintf(stderr, " - "); - vfprintf(stderr, format, args); + ret_size += g_snprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, " - "); + ret_size += g_vsnprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, format, args); va_end(args); } - fprintf(stderr, "\n"); + g_fprintf(stderr, "%s\n", log_buf); } void yagl_log_func_enter(yagl_pid process_id, yagl_tid thread_id, - const char* func, + const char *func, int line, - const char* format, ...) + const char *format, ...) { va_list args; - - yagl_log_print_current_time(); - fprintf(stderr, - " %-5s [%u/%u] {{{ %s(", - g_log_level_to_str[yagl_log_level_trace], - process_id, - thread_id, - func); - if (format) - { + size_t ret_size; + char log_buf[2048]; + + ret_size = yagl_log_print_current_time(log_buf, sizeof(log_buf)); + ret_size += g_snprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, + "|%5d|%1c|%10s|%4d|[%u/%u] {{{ %s(", + qemu_get_thread_id(), + g_log_level_acronym[yagl_log_level_trace], + "yagl", + line, + process_id, + thread_id, + func); + if (format) { va_start(args, format); - vfprintf(stderr, format, args); + ret_size += g_vsnprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, format, args); va_end(args); } - fprintf(stderr, "):%d\n", line); + g_fprintf(stderr, "%s):%d\n", log_buf, line); } void yagl_log_func_exit(yagl_pid process_id, yagl_tid thread_id, - const char* func, + const char *func, int line, - const char* format, ...) + const char *format, ...) { va_list args; - - yagl_log_print_current_time(); - fprintf(stderr, - " %-5s [%u/%u] }}} %s:%d", - g_log_level_to_str[yagl_log_level_trace], - process_id, - thread_id, - func, - line); - if (format) - { + size_t ret_size; + char log_buf[2048]; + + ret_size = yagl_log_print_current_time(log_buf, sizeof(log_buf)); + ret_size += g_snprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, + "|%5d|%1c|%10s|%4d|[%u/%u] }}} %s:%d", + qemu_get_thread_id(), + g_log_level_acronym[yagl_log_level_trace], + "yagl", + line, + process_id, + thread_id, + func, + line); + if (format) { va_start(args, format); - fprintf(stderr, " = "); - vfprintf(stderr, format, args); + ret_size += g_snprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, " = "); + ret_size += g_vsnprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, format, args); va_end(args); } - fprintf(stderr, "\n"); + g_fprintf(stderr, "%s\n", log_buf); } void yagl_log_func_enter_split(yagl_pid process_id, yagl_tid thread_id, - const char* func, + const char *func, int line, int num_args, ...) { char format[1025] = { '\0' }; va_list args; - - yagl_log_print_current_time(); - fprintf(stderr, - " %-5s [%u/%u] {{{ %s(", - g_log_level_to_str[yagl_log_level_trace], - process_id, - thread_id, - func); - - if (num_args > 0) - { + size_t ret_size; + char log_buf[2048]; + + ret_size = yagl_log_print_current_time(log_buf, sizeof(log_buf)); + ret_size += g_snprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, + "|%5d|%1c|%10s|%4d|[%u/%u] {{{ %s(", + qemu_get_thread_id(), + g_log_level_acronym[yagl_log_level_trace], + "yagl", + line, + process_id, + thread_id, + func); + + if (num_args > 0) { int i; bool skip = false; va_start(args, num_args); - for (i = 0; i < num_args;) - { - const char* arg_format = yagl_log_datatype_to_format(va_arg(args, const char*)); - const char* arg_name; + for (i = 0; i < num_args;) { + const char *arg_format = + yagl_log_datatype_to_format(va_arg(args, + const char *)); + const char *arg_name; - if (!arg_format) - { + if (!arg_format) { skip = true; break; } - arg_name = va_arg(args, const char*); + arg_name = va_arg(args, const char *); strcat(format, arg_name); strcat(format, " = "); @@ -481,57 +461,63 @@ void yagl_log_func_enter_split(yagl_pid process_id, ++i; - if (i < num_args) - { + if (i < num_args) { strcat(format, ", "); } } - if (skip) - { - fprintf(stderr, "..."); - } - else - { - vfprintf(stderr, format, args); + if (skip) { + ret_size += g_snprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, "..."); + + } else { + ret_size += g_vsnprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, format, args); } va_end(args); } - fprintf(stderr, "):%d\n", line); + g_fprintf(stderr, "%s):%d\n", log_buf, line); } void yagl_log_func_exit_split(yagl_pid process_id, yagl_tid thread_id, - const char* func, + const char *func, int line, - const char* datatype, ...) + const char *datatype, ...) { va_list args; + size_t ret_size; + char log_buf[2048]; + + ret_size = yagl_log_print_current_time(log_buf, sizeof(log_buf)); + ret_size += g_snprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, + "|%5d|%1c|%10s|%4d|[%u/%u] }}} %s:%d", + qemu_get_thread_id(), + g_log_level_acronym[yagl_log_level_trace], + "yagl", + line, + process_id, + thread_id, + func, + line); + + if (datatype) { + const char *format = yagl_log_datatype_to_format(datatype); + if (format) { + ret_size += g_snprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, " = "); - yagl_log_print_current_time(); - fprintf(stderr, - " %-5s [%u/%u] }}} %s:%d", - g_log_level_to_str[yagl_log_level_trace], - process_id, - thread_id, - func, - line); - - if (datatype) - { - const char* format = yagl_log_datatype_to_format(datatype); - if (format) - { - fprintf(stderr, " = "); va_start(args, datatype); - vfprintf(stderr, format, args); + ret_size += g_vsnprintf(log_buf + ret_size, + sizeof(log_buf) - ret_size, format, args); va_end(args); } } - fprintf(stderr, "\n"); + g_fprintf(stderr, "%s\n", log_buf); } bool yagl_log_is_enabled_for_level(yagl_log_level log_level) @@ -539,33 +525,25 @@ bool yagl_log_is_enabled_for_level(yagl_log_level log_level) return log_level <= g_log_level; } -bool yagl_log_is_enabled_for_facility(const char* facility) +bool yagl_log_is_enabled_for_facility(const char *facility) { int i; bool res = false; - if (g_log_facilities_match) - { - for (i = 0; g_log_facilities_match[i]; ++i) - { - if (yagl_log_match(facility, g_log_facilities_match[i])) - { + if (g_log_facilities_match) { + for (i = 0; g_log_facilities_match[i]; ++i) { + if (yagl_log_match(facility, g_log_facilities_match[i])) { res = true; break; } } - } - else - { + } else { res = true; } - if (res && g_log_facilities_no_match) - { - for (i = 0; g_log_facilities_no_match[i]; ++i) - { - if (yagl_log_match(facility, g_log_facilities_no_match[i])) - { + if (res && g_log_facilities_no_match) { + for (i = 0; g_log_facilities_no_match[i]; ++i) { + if (yagl_log_match(facility, g_log_facilities_no_match[i])) { res = false; break; }