support TDM_DEBUG_PATH 41/79741/2
authorBoram Park <boram1288.park@samsung.com>
Tue, 12 Jul 2016 07:22:40 +0000 (16:22 +0900)
committerBoram Park <boram1288.park@samsung.com>
Mon, 18 Jul 2016 01:19:47 +0000 (10:19 +0900)
Change-Id: Ibc25d75ad797d1815987a2acceccb9b15d7723f3

common/tdm_log.c
include/tdm_log.h
src/tdm.c
src/tdm_dbg_server.c
src/tdm_private.h

index c843c9b..5e1ab2c 100644 (file)
@@ -61,6 +61,7 @@
 #define LOG_TAG "TDM"
 
 static unsigned int dlog_enable;
+static unsigned int color_enable = 1;
 static unsigned int debug_level = TDM_LOG_LEVEL_INFO;
 
 static unsigned int need_check_env = 1;
@@ -85,6 +86,12 @@ _tdm_log_check_env(void)
 }
 
 EXTERN void
+tdm_log_enable_color(unsigned int enable)
+{
+       color_enable = enable;
+}
+
+EXTERN void
 tdm_log_enable_dlog(unsigned int enable)
 {
        dlog_enable = enable;
@@ -146,9 +153,12 @@ tdm_log_print(int level, const char *fmt, ...)
 
                clock_gettime(CLOCK_MONOTONIC, &ts);
 
-               printf("%s", color[level]);
+               if (color_enable)
+                       printf("%s", color[level]);
                printf("[%s]", lvl_str[level]);
-               printf(COLOR_RESET"[%d.%06d]", (int)ts.tv_sec, (int)ts.tv_nsec / 1000);
+               if (color_enable)
+                       printf(COLOR_RESET);
+               printf("[%d.%06d]", (int)ts.tv_sec, (int)ts.tv_nsec / 1000);
                va_start(arg, fmt);
                vprintf(fmt, arg);
                va_end(arg);
index 19abde5..e43a4af 100644 (file)
@@ -63,6 +63,7 @@ enum {
        TDM_LOG_LEVEL_DBG,
 };
 
+void tdm_log_enable_color(unsigned int enable);
 void tdm_log_enable_dlog(unsigned int enable);
 void tdm_log_enable_debug(unsigned int enable);
 void tdm_log_set_debug_level(int level);
index d388f19..5597bca 100644 (file)
--- a/src/tdm.c
+++ b/src/tdm.c
@@ -907,6 +907,10 @@ tdm_display_init(tdm_error *error)
        if (debug)
                tdm_display_enable_dump(debug);
 
+       debug = getenv("TDM_DEBUG_PATH");
+       if (debug)
+               tdm_display_enable_path(debug);
+
        private_display = calloc(1, sizeof(tdm_private_display));
        if (!private_display) {
                ret = TDM_ERROR_OUT_OF_MEMORY;
@@ -1064,6 +1068,8 @@ tdm_display_enable_debug_module(const char*modules)
                        tdm_debug_module |= TDM_DEBUG_THREAD;
                else if (!strncmp(arg, "mutex", 5))
                        tdm_debug_module |= TDM_DEBUG_MUTEX;
+               else if (!strncmp(arg, "vblank", 6))
+                       tdm_debug_module |= TDM_DEBUG_VBLANK;
                else
                        return TDM_ERROR_BAD_REQUEST;
 
@@ -1111,3 +1117,36 @@ tdm_display_enable_dump(const char *dump_str)
 
        return TDM_ERROR_NONE;
 }
+
+INTERN tdm_error
+tdm_display_enable_path(const char *path)
+{
+       static int old_stdout = -1;
+       char fd_name[TDM_PATH_LEN];
+       int  log_fd = -1;
+       FILE *log_fl;
+
+       if (old_stdout == -1)
+               old_stdout = dup(STDOUT_FILENO);
+
+       tdm_log_enable_dlog(0);
+
+       snprintf(fd_name, TDM_PATH_LEN, "%s", path);
+
+       log_fl = fopen(fd_name, "a");
+       if (!log_fl) {
+               TDM_ERR("failed: open file(%s)\n", fd_name);
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       fflush(stderr);
+       close(STDOUT_FILENO);
+
+       setvbuf(log_fl, NULL, _IOLBF, 512);
+       log_fd = fileno(log_fl);
+
+       dup2(log_fd, STDOUT_FILENO);
+       fclose(log_fl);
+
+       return TDM_ERROR_NONE;
+}
index c5db70a..83ea135 100644 (file)
@@ -118,8 +118,6 @@ _tdm_dbg_server_log_path(unsigned int pid, char *cwd, int argc, char *argv[], ch
 {
        static int old_stdout = -1;
        char fd_name[TDM_PATH_LEN];
-       int  log_fd = -1;
-       FILE *log_fl;
        char *path;
 
        if (argc < 3) {
@@ -149,22 +147,14 @@ _tdm_dbg_server_log_path(unsigned int pid, char *cwd, int argc, char *argv[], ch
                        else
                                snprintf(fd_name, TDM_PATH_LEN, "%s", path);
                }
+               tdm_log_enable_color(0);
        }
 
-       log_fl = fopen(fd_name, "a");
-       if (!log_fl) {
-               TDM_SNPRINTF(reply, len, "failed: open file(%s)\n", fd_name);
+       if (tdm_display_enable_path((const char*)fd_name) != TDM_ERROR_NONE) {
+               TDM_SNPRINTF(reply, len, "failed: '%s'\n", path);
                return;
        }
 
-       fflush(stderr);
-       close(STDOUT_FILENO);
-
-       setvbuf(log_fl, NULL, _IOLBF, 512);
-       log_fd = fileno(log_fl);
-
-       dup2(log_fd, STDOUT_FILENO);
-       fclose(log_fl);
 done:
        TDM_SNPRINTF(reply, len, "log path: '%s'\n", path);
 }
index 0e792c8..5b3a68d 100644 (file)
@@ -533,6 +533,8 @@ tdm_error
 tdm_display_enable_debug_module(const char*modules);
 tdm_error
 tdm_display_enable_dump(const char *dump_str);
+tdm_error
+tdm_display_enable_path(const char *path);
 
 /**
  * @brief The tdm vblank object