summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukasz Kostyra <l.kostyra@samsung.com>2021-02-16 08:23:30 +0100
committerLukasz Kostyra <l.kostyra@samsung.com>2022-01-03 12:27:59 +0100
commit4f7f86e36fe19bb1e7da2818dfe576743eb5ebca (patch)
tree6d0fbc4203eca539c212d161fa3cd0e786dae602
parent38fdedfce6472804c3700a5a4dbeab1feecd07ec (diff)
downloademulator-yagl-4f7f86e36fe19bb1e7da2818dfe576743eb5ebca.tar.gz
emulator-yagl-4f7f86e36fe19bb1e7da2818dfe576743eb5ebca.tar.bz2
emulator-yagl-4f7f86e36fe19bb1e7da2818dfe576743eb5ebca.zip
Logger: Enable dlog logging and log messages in one linesubmit/tizen/20220107.012650accepted/tizen/unified/20220107.120835
Change-Id: I596372e265a1d679b294306fb692ec94bb00cbc7
-rw-r--r--CMakeLists.txt5
-rw-r--r--EGL/CMakeLists.txt1
-rw-r--r--EGL/yagl_log.c200
-rw-r--r--packaging/emulator-yagl.spec1
4 files changed, 149 insertions, 58 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bead281..9eadea2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,6 +74,11 @@ find_package(PkgConfig)
find_package(FLEX)
find_package(BISON)
+pkg_check_modules(LIBDLOG REQUIRED dlog)
+add_definitions(${LIBDLOG_CFLAGS})
+include_directories(${LIBDLOG_INCLUDE_DIRS})
+link_directories(${LIBDLOG_LIBRARY_DIRS})
+
pkg_check_modules(LIBDRM REQUIRED libdrm)
add_definitions(${LIBDRM_CFLAGS})
include_directories(${LIBDRM_INCLUDE_DIRS})
diff --git a/EGL/CMakeLists.txt b/EGL/CMakeLists.txt
index 1cebf8f..a71a4b9 100644
--- a/EGL/CMakeLists.txt
+++ b/EGL/CMakeLists.txt
@@ -46,6 +46,7 @@ set(LIBRARIES
${LIBTBM_LIBRARIES}
${LIBTBM_VIGS_LIBRARIES}
${HAL_BACKEND_TBM_VIGS_LIBRARIES}
+ ${LIBDLOG_LIBRARIES}
dl
)
diff --git a/EGL/yagl_log.c b/EGL/yagl_log.c
index 7b907c2..6e57ae2 100644
--- a/EGL/yagl_log.c
+++ b/EGL/yagl_log.c
@@ -34,6 +34,7 @@
#include "yagl_log.h"
#include "yagl_utils.h"
#include "yagl_malloc.h"
+#include <dlog/dlog.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
@@ -87,7 +88,7 @@ static struct
{ "EGLNativeDisplayType", "%p" },
{ "yagl_host_handle", "%u" },
{ "int", "%d" },
- { "GLenum", "%u" },
+ { "GLenum", "%x" },
{ "GLuint", "%u" },
{ "GLbitfield", "%u" },
{ "GLclampf", "%f" },
@@ -110,6 +111,8 @@ static char** g_log_facilities_match = NULL;
static char** g_log_facilities_no_match = NULL;
static int g_log_func_trace = 0;
static pthread_mutex_t g_log_mutex;
+static log_id_t DLOG_ID = LOG_ID_SYSTEM;
+static const char* DLOG_TAG = "YAGL";
static const char* yagl_log_datatype_to_format(const char* type)
{
@@ -131,9 +134,8 @@ static const char* yagl_log_datatype_to_format(const char* type)
return NULL;
}
-static void yagl_log_print_current_time(void)
+static void yagl_log_get_current_time(char buff[], size_t buff_size)
{
- char buff[128];
struct tm tm;
struct timeval tv = { 0, 0 };
time_t ti;
@@ -143,9 +145,7 @@ static void yagl_log_print_current_time(void)
ti = tv.tv_sec;
localtime_r(&ti, &tm);
- strftime(buff, sizeof(buff),
- "%H:%M:%S", &tm);
- fprintf(stderr, "%s", buff);
+ strftime(buff, buff_size, "%H:%M:%S", &tm);
}
/*
@@ -358,6 +358,19 @@ void yagl_log_init(void)
pthread_once(&g_log_init, yagl_log_init_once);
}
+log_priority yagl_log_get_dlog_prio(yagl_log_level log_level)
+{
+ switch (log_level)
+ {
+ case yagl_log_level_error: return DLOG_ERROR;
+ case yagl_log_level_warn: return DLOG_WARN;
+ case yagl_log_level_info: return DLOG_INFO;
+ case yagl_log_level_debug: return DLOG_DEBUG;
+ case yagl_log_level_trace: return DLOG_VERBOSE;
+ default: return DLOG_UNKNOWN;
+ };
+}
+
void yagl_log_event(yagl_log_level log_level,
pid_t process_id,
pid_t thread_id,
@@ -366,27 +379,44 @@ void yagl_log_event(yagl_log_level log_level,
const char* format, ...)
{
va_list args;
+ char time[128] = { '\0' }, intro[200] = { '\0' }, msg[200] = { '\0' };
+ int has_format = 0;
yagl_log_init();
+ log_priority dlog_prio = yagl_log_get_dlog_prio(log_level);
+
pthread_mutex_lock(&g_log_mutex);
- 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);
+ yagl_log_get_current_time(time, sizeof(time));
+
+ snprintf(intro, 200,
+ " %-5s [%u/%u] %s:%d",
+ g_log_level_to_str[log_level],
+ process_id,
+ thread_id,
+ facility,
+ line);
+
if (format)
{
+ has_format = 1;
+
va_start(args, format);
- fprintf(stderr, " - ");
- vfprintf(stderr, format, args);
+ vsnprintf(msg, 200, format, args);
va_end(args);
}
- fprintf(stderr, "\n");
+
+ // newline log only to stderr, dlog assumes newline at the end
+ if (has_format) {
+ fprintf(stderr, "%s %s - %s\n", time, intro, msg);
+ __dlog_print(DLOG_ID, dlog_prio, DLOG_TAG, "%s %s - %s", time, intro, msg);
+ } else {
+ fprintf(stderr, "%s %s\n", time, intro);
+ __dlog_print(DLOG_ID, dlog_prio, DLOG_TAG, "%s %s", time, intro);
+ }
+
+ fflush(stderr);
pthread_mutex_unlock(&g_log_mutex);
}
@@ -398,25 +428,40 @@ void yagl_log_func_enter(pid_t process_id,
const char* format, ...)
{
va_list args;
+ char time[128] = { '\0' }, intro[200] = { '\0' }, msg[200] = { '\0' };
+ int has_format = 0;
yagl_log_init();
pthread_mutex_lock(&g_log_mutex);
- 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);
+ yagl_log_get_current_time(time, sizeof(time));
+
+ snprintf(intro, 200,
+ " %-5s [%u/%u] {{{ %s(",
+ g_log_level_to_str[yagl_log_level_trace],
+ process_id,
+ thread_id,
+ func);
+
if (format)
{
+ has_format = 1;
+
va_start(args, format);
- vfprintf(stderr, format, args);
+ vsnprintf(msg, 200, format, args);
va_end(args);
}
- fprintf(stderr, "):%d\n", line);
+
+ if (has_format) {
+ fprintf(stderr, "%s %s%s):%d\n", time, intro, msg, line);
+ __dlog_print(DLOG_ID, DLOG_VERBOSE, DLOG_TAG, "%s %s%s):%d", time, intro, msg, line);
+ } else {
+ fprintf(stderr, "%s %s):%d\n", time, intro, line);
+ __dlog_print(DLOG_ID, DLOG_VERBOSE, DLOG_TAG, "%s %s):%d", time, intro, line);
+ }
+
+ fflush(stderr);
pthread_mutex_unlock(&g_log_mutex);
}
@@ -428,27 +473,41 @@ void yagl_log_func_exit(pid_t process_id,
const char* format, ...)
{
va_list args;
+ char time[128] = { '\0' }, intro[200] = { '\0' }, msg[200] = { '\0' };
+ int has_format = 0;
yagl_log_init();
pthread_mutex_lock(&g_log_mutex);
- 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);
+ yagl_log_get_current_time(time, sizeof(time));
+
+ snprintf(intro, 200,
+ " %-5s [%u/%u] }}} %s:%d",
+ g_log_level_to_str[yagl_log_level_trace],
+ process_id,
+ thread_id,
+ func,
+ line);
+
if (format)
{
+ has_format = 1;
+
va_start(args, format);
- fprintf(stderr, " = ");
- vfprintf(stderr, format, args);
+ vsnprintf(msg, 200, format, args);
va_end(args);
}
- fprintf(stderr, "\n");
+
+ if (has_format) {
+ fprintf(stderr, "%s %s = %s\n", time, intro, msg);
+ __dlog_print(DLOG_ID, DLOG_VERBOSE, DLOG_TAG, "%s %s = %s", time, intro, msg);
+ } else {
+ fprintf(stderr, "%s %s\n", time, intro);
+ __dlog_print(DLOG_ID, DLOG_VERBOSE, DLOG_TAG, "%s %s", time, intro);
+ }
+
+ fflush(stderr);
pthread_mutex_unlock(&g_log_mutex);
}
@@ -462,23 +521,28 @@ void yagl_log_func_enter_split(pid_t process_id,
char format[1025] = { '\0' };
size_t format_avail = 1024;
va_list args;
+ char time[128] = { '\0' }, intro[200] = { '\0' }, msg[200] = { '\0' };
+ int has_args = 0;
yagl_log_init();
pthread_mutex_lock(&g_log_mutex);
- 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);
+ yagl_log_get_current_time(time, sizeof(time));
+
+ snprintf(intro, 200,
+ " %-5s [%u/%u] {{{ %s(",
+ g_log_level_to_str[yagl_log_level_trace],
+ process_id,
+ thread_id,
+ func);
if (num_args > 0)
{
int i, skip = 0;
+ has_args = 1;
+
va_start(args, num_args);
for (i = 0; i < num_args;)
@@ -525,17 +589,25 @@ void yagl_log_func_enter_split(pid_t process_id,
if (skip)
{
- fprintf(stderr, "...");
+ snprintf(msg, 200, "...");
}
else
{
- vfprintf(stderr, format, args);
+ vsnprintf(msg, 200, format, args);
}
va_end(args);
}
- fprintf(stderr, "):%d\n", line);
+ if (has_args) {
+ fprintf(stderr, "%s %s%s):%d\n", time, intro, msg, line);
+ __dlog_print(DLOG_ID, DLOG_VERBOSE, DLOG_TAG, "%s %s%s):%d", time, intro, msg, line);
+ } else {
+ fprintf(stderr, "%s %s):%d\n", time, intro, line);
+ __dlog_print(DLOG_ID, DLOG_VERBOSE, DLOG_TAG, "%s %s):%d", time, intro, line);
+ }
+
+ fflush(stderr);
pthread_mutex_unlock(&g_log_mutex);
}
@@ -547,33 +619,45 @@ void yagl_log_func_exit_split(pid_t process_id,
const char* datatype, ...)
{
va_list args;
+ char time[128] = { '\0' }, intro[200] = { '\0' }, msg[200] = { '\0' };
+ int has_format = 0;
yagl_log_init();
pthread_mutex_lock(&g_log_mutex);
- 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);
+ yagl_log_get_current_time(time, sizeof(time));
+
+ snprintf(intro, 200,
+ " %-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, " = ");
+ has_format = 1;
+
va_start(args, datatype);
- vfprintf(stderr, format, args);
+ vsnprintf(msg, 200, format, args);
va_end(args);
}
}
- fprintf(stderr, "\n");
+ if (has_format) {
+ fprintf(stderr, "%s %s = %s\n", time, intro, msg);
+ __dlog_print(DLOG_ID, DLOG_VERBOSE, DLOG_TAG, "%s %s = %s", time, intro, msg);
+ } else {
+ fprintf(stderr, "%s %s\n", time, intro);
+ __dlog_print(DLOG_ID, DLOG_VERBOSE, DLOG_TAG, "%s %s", time, intro);
+ }
+
+ fflush(stderr);
pthread_mutex_unlock(&g_log_mutex);
}
diff --git a/packaging/emulator-yagl.spec b/packaging/emulator-yagl.spec
index 5951f91..f356d0e 100644
--- a/packaging/emulator-yagl.spec
+++ b/packaging/emulator-yagl.spec
@@ -14,6 +14,7 @@ Source1001: emulator-yagl.manifest
BuildRequires: cmake
BuildRequires: flex
BuildRequires: bison
+BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(libdrm)
%if "%{ENABLE_TIZEN_BACKEND}" == "1"
BuildRequires: pkgconfig(libtbm)