support dlog for debugging 31/78331/3
authorBoram Park <boram1288.park@samsung.com>
Tue, 5 Jul 2016 06:05:06 +0000 (15:05 +0900)
committerBoram Park <boram1288.park@samsung.com>
Tue, 5 Jul 2016 07:09:04 +0000 (16:09 +0900)
Change-Id: If8ebfbbe9158ca8313f9f32351762e3e3a4d4b5a

Makefile.am
client/Makefile.am
client/tdm_client.c
common/Makefile.am [new file with mode: 0644]
common/tdm_log.c [new file with mode: 0644]
configure.ac
include/tdm_log.h
src/Makefile.am
src/tdm.c
tools/tdm_test_client.c

index 393ba5c..1908008 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = . include protocol client src tools
+SUBDIRS = . include protocol common src client tools
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libtdm.pc
index b41c0c6..f3b29c8 100644 (file)
@@ -9,7 +9,7 @@ pkgconfig_DATA = libtdm-client.pc
 libtdm_client_la_LTLIBRARIES = libtdm-client.la
 libtdm_client_ladir = $(libdir)
 libtdm_client_la_LDFLAGS = $(LDFLAGS)
-libtdm_client_la_LIBADD = $(TDM_CLIENT_LIBS)
+libtdm_client_la_LIBADD = $(TDM_CLIENT_LIBS) ../common/libtdm-common.la
 libtdm_client_la_CFLAGS = \
        $(CFLAGS) \
        $(WARN_CFLAGS) \
index e3679d2..f03ae63 100644 (file)
@@ -49,8 +49,6 @@
 #include "tdm_list.h"
 #include "tdm-client-protocol.h"
 
-int tdm_debug;
-
 typedef struct _tdm_private_client_vblank tdm_private_client_vblank;
 
 typedef struct _tdm_private_client {
@@ -278,11 +276,6 @@ tdm_client*
 tdm_client_create(tdm_error *error)
 {
        tdm_private_client *private_client;
-       const char *debug;
-
-       debug = getenv("TDM_DEBUG");
-       if (debug && (strstr(debug, "1")))
-               tdm_debug = 1;
 
        private_client = calloc(1, sizeof *private_client);
        if (!private_client) {
diff --git a/common/Makefile.am b/common/Makefile.am
new file mode 100644 (file)
index 0000000..e3f2dbe
--- /dev/null
@@ -0,0 +1,12 @@
+noinst_LTLIBRARIES = libtdm-common.la
+
+libtdm_common_la_SOURCES = tdm_log.c
+libtdm_common_la_LIBADD = ${LDFLAGS} $(TDM_LDFLAGS)
+libtdm_common_la_LDFLAGS = ${LDFLAGS} $(TDM_LDFLAGS)
+libtdm_common_la_CFLAGS = \
+       $(CFLAGS) \
+       $(WARN_CFLAGS) \
+       $(TDM_CFLAGS) \
+       -I$(top_srcdir)/include \
+       -I$(top_srcdir)/protocol \
+       -I$(top_srcdir)/src
diff --git a/common/tdm_log.c b/common/tdm_log.c
new file mode 100644 (file)
index 0000000..2c8b0c6
--- /dev/null
@@ -0,0 +1,147 @@
+/**************************************************************************
+ *
+ * libtdm
+ *
+ * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
+ *          JinYoung Jeon <jy0.jeon@samsung.com>,
+ *          Taeheon Kim <th908.kim@samsung.com>,
+ *          YoungJun Cho <yj44.cho@samsung.com>,
+ *          SooChan Lim <sc1.lim@samsung.com>,
+ *          Boram Park <sc1.lim@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <time.h>
+#include <assert.h>
+#include <sys/syscall.h>
+#include <dlog.h>
+
+#include "tdm.h"
+#include "tdm_log.h"
+#include "tdm_macro.h"
+
+//#define TDM_CONFIG_ASSERT
+
+#define LOG_MAX_LEN    4076
+
+#define COLOR_RED "\x1b[31m"      /* for error */
+#define COLOR_YELLOW "\x1b[33m"   /* for warning */
+#define COLOR_GREEN "\x1b[32m"    /* for info */
+#define COLOR_RESET "\x1b[0m"
+
+#undef LOG_TAG
+#define LOG_TAG "TDM"
+
+static unsigned int dlog_enable;
+static unsigned int debug_enable;
+
+static unsigned int need_check_env = 1;
+
+static void
+_tdm_log_check_env(void)
+{
+       const char *str;
+
+       str = getenv("TDM_DEBUG");
+       if (str && (strstr(str, "1")))
+               debug_enable = 1;
+
+       str = getenv("TDM_DLOG");
+       if (str && (strstr(str, "1")))
+               dlog_enable = 1;
+}
+
+EXTERN void
+tdm_log_enable_dlog(unsigned int enable)
+{
+       dlog_enable = enable;
+}
+
+EXTERN void
+tdm_log_enable_debug(unsigned int enable)
+{
+       debug_enable = enable;
+}
+
+EXTERN void
+tdm_log_print(int level, const char *fmt, ...)
+{
+       va_list arg;
+
+       if (need_check_env) {
+               need_check_env = 0;
+               _tdm_log_check_env();
+       }
+
+       if (level > 3 && !debug_enable)
+               return;
+
+       if (dlog_enable) {
+               log_priority dlog_prio;
+               switch (level) {
+               case TDM_LOG_LEVEL_ERR:
+                       dlog_prio = DLOG_ERROR;
+                       break;
+               case TDM_LOG_LEVEL_WRN:
+                       dlog_prio = DLOG_WARN;
+                       break;
+               case TDM_LOG_LEVEL_INFO:
+                       dlog_prio = DLOG_INFO;
+                       break;
+               case TDM_LOG_LEVEL_DBG:
+                       dlog_prio = DLOG_DEBUG;
+                       break;
+               default:
+                       return;
+               }
+               va_start(arg, fmt);
+               dlog_vprint(dlog_prio, LOG_TAG, fmt, arg);
+               va_end(arg);
+       } else {
+               struct timespec ts;
+               char *lvl_str[] = {"TDM_NON", "TDM_ERR", "TDM_WRN", "TDM_INF", "TDM_DBG"};
+               char *color[] = {COLOR_RESET, COLOR_RED, COLOR_YELLOW, COLOR_GREEN, COLOR_RESET};
+
+               clock_gettime(CLOCK_MONOTONIC, &ts);
+
+               printf("%s", color[level]);
+               printf("[%s]", lvl_str[level]);
+               printf(COLOR_RESET"[%d.%06d]", (int)ts.tv_sec, (int)ts.tv_nsec / 1000);
+               va_start(arg, fmt);
+               vprintf(fmt, arg);
+               va_end(arg);
+       }
+
+#ifdef TDM_CONFIG_ASSERT
+       if (level < 3)
+               assert(0);
+#endif
+}
index 21d8163..c2bb484 100644 (file)
@@ -78,9 +78,10 @@ AC_OUTPUT([
        libtdm.pc
        include/Makefile
        protocol/Makefile
+       common/Makefile
+       src/Makefile
        client/libtdm-client.pc
        client/Makefile
-       src/Makefile
        tools/Makefile])
 
 echo ""
index c55acf6..69c2729 100644 (file)
 #ifndef _TDM_LOG_H_
 #define _TDM_LOG_H_
 
+#include <unistd.h>
+#include <sys/syscall.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include <unistd.h>
-#include <time.h>
-#include <assert.h>
-#include <sys/syscall.h>
-
-
 /**
  * @file tdm_log.h
  * @brief The header file to print logs in frontend and backend modules
  * @details
- * The TDM debug log can be enable by setting "TDM_DEBUG" enviroment
+ * The TDM debug log can be enable by setting "TDM_DEBUG" enviroment. And also,
+ * the TDM dlog can be enable by setting "TDM_DLOG" enviroment.
  * @par Example
  * @code
  *  $ export TDM_DEBUG=1
  * @endcode
  */
-extern int tdm_debug;
-
-//#define TDM_CONFIG_DLOG
-//#define TDM_CONFIG_ASSERT
-
-#undef TDM_ASSERT
-#ifdef TDM_CONFIG_ASSERT
-#define TDM_ASSERT(o) assert(o)
-#else
-#define TDM_ASSERT(o)
-#endif
-
-#ifdef TDM_CONFIG_DLOG
-
-#include <dlog.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "TDM"
 
-#define TDM_DBG(fmt, args...) \
-       do { \
-               if (tdm_debug) { \
-                       struct timespec ts;     \
-                       clock_gettime(CLOCK_MONOTONIC, &ts);    \
-                       LOGD("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args);      \
-                       printf("[TDM_DBG][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
-                               (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
-               } \
-       } while (0)
-
-#define TDM_INFO(fmt, args...) \
-       do { \
-               struct timespec ts;     \
-               clock_gettime(CLOCK_MONOTONIC, &ts);    \
-               LOGI("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args);      \
-               printf("[TDM_INF][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
-                       (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
-       } while (0)
-
-#define TDM_WRN(fmt, args...) \
-       do { \
-               struct timespec ts;     \
-               clock_gettime(CLOCK_MONOTONIC, &ts);    \
-               LOGI("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args);      \
-               printf("[TDM_WRN][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
-                       (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
-       } while (0)
-
-#define TDM_ERR(fmt, args...) \
-       do { \
-               struct timespec ts;     \
-               clock_gettime(CLOCK_MONOTONIC, &ts);    \
-               LOGE("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args);      \
-               printf("[TDM_ERR][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
-                       (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
-       } while (0)
+enum {
+       TDM_LOG_LEVEL_NONE,
+       TDM_LOG_LEVEL_ERR,
+       TDM_LOG_LEVEL_WRN,
+       TDM_LOG_LEVEL_INFO,
+       TDM_LOG_LEVEL_DBG,
+};
 
-#else /* TDM_CONFIG_DLOG */
-
-#include <stdio.h>
-
-#define COLOR_RED "\x1b[31m"      /* for error */
-#define COLOR_YELLOW "\x1b[33m"   /* for warning */
-#define COLOR_GREEN "\x1b[32m"    /* for info */
-#define COLOR_RESET "\x1b[0m"
+void tdm_log_enable_dlog(unsigned int enable);
+void tdm_log_enable_debug(unsigned int enable);
+void tdm_log_print(int level, const char *fmt, ...);
 
 #define TDM_DBG(fmt, args...) \
-       do { \
-               if (tdm_debug) { \
-                       struct timespec ts;     \
-                       clock_gettime(CLOCK_MONOTONIC, &ts);    \
-                       printf("[TDM_DBG][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
-                               (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
-               } \
-       } while (0)
-
+       tdm_log_print(TDM_LOG_LEVEL_DBG, "[%d][%s %d]"fmt"\n", \
+                                 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args)
 #define TDM_INFO(fmt, args...) \
-       do { \
-               struct timespec ts;     \
-               clock_gettime(CLOCK_MONOTONIC, &ts);    \
-               printf(COLOR_GREEN"[TDM_INF]"COLOR_RESET"[%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
-                       (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
-       } while (0)
-
+       tdm_log_print(TDM_LOG_LEVEL_INFO, "[%d][%s %d]"fmt"\n", \
+                                 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args)
 #define TDM_WRN(fmt, args...) \
-       do { \
-               struct timespec ts;     \
-               clock_gettime(CLOCK_MONOTONIC, &ts);    \
-               printf(COLOR_YELLOW"[TDM_WRN]"COLOR_RESET"[%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec,        \
-                       (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
-               TDM_ASSERT(0); \
-       } while (0)
-
+       tdm_log_print(TDM_LOG_LEVEL_WRN, "[%d][%s %d]"fmt"\n", \
+                                 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args)
 #define TDM_ERR(fmt, args...) \
-       do { \
-               struct timespec ts;     \
-               clock_gettime(CLOCK_MONOTONIC, &ts);    \
-               printf(COLOR_RED"[TDM_ERR]"COLOR_RESET"[%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec,   \
-                       (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
-               TDM_ASSERT(0); \
-       } while (0)
-
-#endif /* TDM_CONFIG_DLOG */
+       tdm_log_print(TDM_LOG_LEVEL_ERR, "[%d][%s %d]"fmt"\n", \
+                                 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args)
 
 #ifdef __cplusplus
 }
index 4d62318..900d3e2 100644 (file)
@@ -1,7 +1,7 @@
 libtdm_la_LTLIBRARIES = libtdm.la
 libtdm_ladir = $(libdir)
 libtdm_la_LDFLAGS = -version-number 1:0:0 -no-undefined
-libtdm_la_LIBADD = $(TDM_LIBS) -ldl -lpthread
+libtdm_la_LIBADD = $(TDM_LIBS) -ldl -lpthread ../common/libtdm-common.la
 libtdm_la_CFLAGS = \
        $(CFLAGS) \
        $(WARN_CFLAGS) \
index be9d26b..9653d8f 100644 (file)
--- a/src/tdm.c
+++ b/src/tdm.c
@@ -665,7 +665,6 @@ tdm_display_update(tdm_display *dpy)
 #define SUFFIX_MODULE    ".so"
 #define DEFAULT_MODULE   "libtdm-default"SUFFIX_MODULE
 
-int tdm_debug;
 int tdm_debug_buffer;
 int tdm_debug_thread;
 int tdm_debug_mutex;
@@ -892,10 +891,6 @@ tdm_display_init(tdm_error *error)
                return g_private_display;
        }
 
-       debug = getenv("TDM_DEBUG");
-       if (debug && (strstr(debug, "1")))
-               tdm_debug = 1;
-
        debug = getenv("TDM_DEBUG_BUFFER");
        if (debug && (strstr(debug, "1")))
                tdm_debug_buffer = 1;
@@ -975,7 +970,6 @@ failed_event:
 failed_mutex_init:
        free(private_display);
 failed_alloc:
-       tdm_debug = 0;
        tdm_debug_buffer = 0;
        if (error)
                *error = ret;
@@ -1018,7 +1012,6 @@ tdm_display_deinit(tdm_display *dpy)
        pthread_mutex_destroy(&private_display->lock);
        free(private_display);
        g_private_display = NULL;
-       tdm_debug = 0;
        tdm_debug_buffer = 0;
 
        _pthread_mutex_unlock(&gLock);
index f14b6fe..4a8e583 100644 (file)
 #include <time.h>
 #include <stdint.h>
 
-#include "tdm_macro.h"
-
 #include <tdm_client.h>
-#include <tdm_helper.h>
-
-int tdm_debug;
+#include "tdm_macro.h"
 
 typedef struct _tdm_test_client_arg {
        char output_name[512];
@@ -252,13 +248,6 @@ _client_vblank_handler(tdm_client_vblank *vblank, tdm_error error, unsigned int
        if (cur - vbl > 2000) /* 2ms */
                printf("kernel -> tdm-client: %ld us\n", cur - vbl);
 
-       if (tdm_debug) {
-               static unsigned long p_cur = 0;
-               printf("vblank event interval: %ld %ld\n",
-                          vbl - p_vbl, cur - p_cur);
-               p_cur = cur;
-       }
-
        p_vbl = vbl;
 }
 
@@ -387,11 +376,6 @@ main(int argc, char *argv[])
 {
        tdm_test_client *data = &ttc_data;
        tdm_error error;
-       const char *debug;
-
-       debug = getenv("TDM_DEBUG");
-       if (debug && (strstr(debug, "1")))
-               tdm_debug = 1;
 
        parse_args(data, argc, argv);