impl for using dump path 10/82810/1
authorBoram Park <boram1288.park@samsung.com>
Fri, 5 Aug 2016 09:33:08 +0000 (18:33 +0900)
committerBoram Park <boram1288.park@samsung.com>
Mon, 8 Aug 2016 01:22:00 +0000 (10:22 +0900)
Change-Id: I8b0f5a5812b79330fe7c6f0a6f861f5c95dc333f

src/tdm.c
src/tdm_capture.c
src/tdm_display.c
src/tdm_helper.c
src/tdm_monitor_server.c
src/tdm_pp.c
src/tdm_private.h

index 647230b..2f83a78 100644 (file)
--- a/src/tdm.c
+++ b/src/tdm.c
@@ -840,25 +840,25 @@ tdm_display_init(tdm_error *error)
                return g_private_display;
        }
 
+       private_display = calloc(1, sizeof(tdm_private_display));
+       if (!private_display) {
+               ret = TDM_ERROR_OUT_OF_MEMORY;
+               TDM_ERR("'private_display != NULL' failed");
+               goto failed_alloc;
+       }
+
        debug = getenv("TDM_DEBUG_MODULE");
        if (debug)
                tdm_display_enable_debug_module(debug);
 
        debug = getenv("TDM_DEBUG_DUMP");
        if (debug)
-               tdm_display_enable_dump(debug);
+               tdm_display_enable_dump(private_display, debug, NULL, NULL);
 
        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;
-               TDM_ERR("'private_display != NULL' failed");
-               goto failed_alloc;
-       }
-
        if (pthread_mutex_init(&private_display->lock, NULL)) {
                ret = TDM_ERROR_OPERATION_FAILED;
                TDM_ERR("mutex init failed: %m");
@@ -1023,39 +1023,87 @@ tdm_display_enable_debug_module(const char*modules)
 }
 
 INTERN tdm_error
-tdm_display_enable_dump(const char *dump_str)
+tdm_display_enable_dump(tdm_private_display *private_display, const char *dump_str, char *reply, int *len)
 {
-       char temp[1024];
+       char temp[TDM_PATH_LEN] = {0,}, temp2[TDM_PATH_LEN] = {0,};
+       char *path, *path2;
        char *arg;
        char *end;
 
+       snprintf(temp2, TDM_PATH_LEN, "%s", dump_str);
+       path2 = strtostr(temp, TDM_PATH_LEN, temp2, "@");
+       if (!path2 || path2[0] == '\0')
+               path2 = TDM_DUMP_DIR;
+       else
+               path2++;
+
+       path = tdm_helper_dump_make_directory(path2, reply, len);
+       TDM_GOTO_IF_FAIL(path != NULL, done);
+
        tdm_debug_dump = 0;
 
        snprintf(temp, sizeof(temp), "%s", dump_str);
        arg = strtok_r(temp, ",", &end);
-       while (arg) {
-               if (!strncmp(arg, "none", 4)) {
-                       tdm_debug_dump = 0;
-                       return TDM_ERROR_NONE;
+
+       if (!strncmp(arg, "none", 4)) {
+               tdm_debug_dump = 0;
+               if (tdm_debug_dump_dir) {
+                       free(tdm_debug_dump_dir);
+                       tdm_debug_dump_dir = NULL;
                }
+               TDM_SNPRINTF(reply, len, "path: %s\n", path);
+               goto done;
+       }
+
+       if (!strncmp(arg, "current", 7)) {
+               tdm_private_output *o = NULL;
+               if (!private_display) {
+                       TDM_WRN("no private_display");
+                       goto done;
+               }
+
+               LIST_FOR_EACH_ENTRY(o, &private_display->output_list, link) {
+                       tdm_private_layer *l = NULL;
+                       LIST_FOR_EACH_ENTRY(l, &o->layer_list, link) {
+                               char str[TDM_PATH_LEN];
+                               if (l->usable)
+                                       continue;
+                               snprintf(str, TDM_PATH_LEN, "layer_%d_%d", o->index, l->index);
+                               tdm_helper_dump_buffer_str(l->showing_buffer, path, str);
+                       }
+               }
+
+               TDM_SNPRINTF(reply, len, "path: %s\n", path);
+               goto done;
+       }
+
+       TDM_SNPRINTF(reply, len, "dump: %s\n", arg);
+
+       while (arg) {
                if (!strncmp(arg, "all", 3)) {
                        tdm_debug_dump = 0xFFFFFFFF;
-                       return TDM_ERROR_NONE;
-               }
-               if (!strncmp(arg, "layer", 5))
+                       goto done;
+               } else if (!strncmp(arg, "layer", 5)) {
                        tdm_debug_dump |= TDM_DUMP_FLAG_LAYER;
-               else if (!strncmp(arg, "pp", 2))
+               } else if (!strncmp(arg, "pp", 2)) {
                        tdm_debug_dump |= TDM_DUMP_FLAG_PP;
-               else if (!strncmp(arg, "capture", 7))
+               } else if (!strncmp(arg, "capture", 7)) {
                        tdm_debug_dump |= TDM_DUMP_FLAG_CAPTURE;
-               else
-                       return TDM_ERROR_BAD_REQUEST;
+               else
+                       goto done;
 
                arg = strtok_r(NULL, ",", &end);
        }
 
+       if (tdm_debug_dump_dir)
+               free(tdm_debug_dump_dir);
+
+       tdm_debug_dump_dir = strndup(path, TDM_PATH_LEN);
+
        TDM_INFO("dump... '%s'", dump_str);
 
+done:
+       free(path);
        return TDM_ERROR_NONE;
 }
 
index 2069487..abf3f6d 100644 (file)
@@ -109,7 +109,7 @@ tdm_capture_cb_done(tdm_capture *capture_backend, tbm_surface_h buffer,
                char str[TDM_PATH_LEN];
                static int i;
                snprintf(str, TDM_PATH_LEN, "capture_%03d", i++);
-               tdm_helper_dump_buffer_str(buffer, str);
+               tdm_helper_dump_buffer_str(buffer, tdm_debug_dump_dir, str);
        }
 
        if (tdm_debug_module & TDM_DEBUG_BUFFER)
index d84e329..20dc77c 100644 (file)
@@ -1477,8 +1477,8 @@ tdm_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer)
                char str[TDM_PATH_LEN];
                static int i;
                snprintf(str, TDM_PATH_LEN, "layer_%d_%d_%03d",
-                                private_output->pipe, private_layer->caps.zpos, i++);
-               tdm_helper_dump_buffer_str(buffer, str);
+                                private_output->index, private_layer->index, i++);
+               tdm_helper_dump_buffer_str(buffer, tdm_debug_dump_dir, str);
        }
 
        func_layer = &private_display->func_layer;
index 9547582..6ea3e54 100644 (file)
@@ -54,6 +54,7 @@
 static const char *file_exts[2] = {"png", "yuv"};
 
 int tdm_dump_enable;
+char *tdm_debug_dump_dir;
 
 INTERN unsigned long
 tdm_helper_get_time_in_millis(void)
@@ -168,11 +169,48 @@ _tdm_helper_dump_png(const char *file, const void *data, int width,
        fclose(fp);
 }
 
+INTERN char *
+tdm_helper_dump_make_directory(const char *path, char *reply, int *len)
+{
+       char *fullpath = NULL;
+       time_t timer;
+       struct tm *t, *buf = NULL;
+
+       timer = time(NULL);
+
+       buf = calloc(1, sizeof (struct tm));
+       TDM_GOTO_IF_FAIL(buf != NULL, failed_make);
+
+       fullpath = calloc(1, TDM_PATH_LEN * sizeof(char));
+       TDM_GOTO_IF_FAIL(fullpath != NULL, failed_make);
+
+       t = localtime_r(&timer, buf);
+       TDM_GOTO_IF_FAIL(t != NULL, failed_make);
+
+       snprintf(fullpath, TDM_PATH_LEN, "%s/dump_%04d%02d%02d.%02d%02d%02d", path,
+                        t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
+
+       if ((mkdir(fullpath, 0755)) < 0) {
+               TDM_ERR("mkdir '%s' fail\n", fullpath);
+               TDM_SNPRINTF(reply, len, "mkdir '%s' fail\n", fullpath);
+               goto failed_make;
+       }
+
+       free(buf);
+
+       return fullpath;
+failed_make:
+       if (fullpath)
+               free(fullpath);
+       if (buf)
+               free(buf);
+       return NULL;
+}
+
 INTERN void
-tdm_helper_dump_buffer_str(tbm_surface_h buffer, const char *str)
+tdm_helper_dump_buffer_str(tbm_surface_h buffer, char *dir, char *str)
 {
        tbm_surface_info_s info;
-       const char *dir = "/tmp/dump-tdm";
        const char *ext;
        char file[TDM_PATH_LEN];
        int ret, bw;
@@ -180,6 +218,11 @@ tdm_helper_dump_buffer_str(tbm_surface_h buffer, const char *str)
        TDM_RETURN_IF_FAIL(buffer != NULL);
        TDM_RETURN_IF_FAIL(str != NULL);
 
+       if (!dir) {
+               dir = tdm_helper_dump_make_directory(TDM_DUMP_DIR, NULL, NULL);
+               TDM_RETURN_IF_FAIL(dir != NULL);
+       }
+
        ret = tbm_surface_get_info(buffer, &info);
        TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
 
index a3683fd..c5bda95 100644 (file)
@@ -252,9 +252,7 @@ _tdm_monitor_server_dump(unsigned int pid, char *cwd, int argc, char *argv[], ch
                return;
        }
 
-       tdm_display_enable_dump((const char*)argv[2]);
-
-       TDM_SNPRINTF(reply, len, "%s done\n", argv[2]);
+       tdm_display_enable_dump(dpy, (const char*)argv[2], reply, len);
 }
 
 static struct {
@@ -274,7 +272,7 @@ static struct {
        },
        {
                "debug", _tdm_monitor_server_debug,
-               "set the debug level and modules(none,mutex,buffer,thread,vblank)",
+               "set the debug level and modules(module: none, mutex, buffer, thread, vblank)",
                "<level>[@<module1>[,<module2>]]",
                NULL
        },
@@ -292,8 +290,11 @@ static struct {
        },
        {
                "dump", _tdm_monitor_server_dump,
-               "dump buffers (type: layer, pp, capture, none)",
-               "<object_type1>[,<object_type2>[,...]]",
+               "dump buffers (type: none, layer, pp, capture, current)\n"
+               "\t\t  layer, pp, capture - start to dump buffers of layer, pp, capture\n"
+               "\t\t  none               - stop to dump buffers\n"
+               "\t\t  current            - dump the current buffer of all layers",
+               "<object_type1>[,<object_type2>[,...]]@[<directory_path>]",
                NULL
        },
 };
index a1ba203..cffaba0 100644 (file)
@@ -134,7 +134,7 @@ tdm_pp_cb_done(tdm_pp *pp_backend, tbm_surface_h src, tbm_surface_h dst,
                char str[TDM_PATH_LEN];
                static int i;
                snprintf(str, TDM_PATH_LEN, "pp_dst_%03d", i++);
-               tdm_helper_dump_buffer_str(dst, str);
+               tdm_helper_dump_buffer_str(dst, tdm_debug_dump_dir, str);
        }
 
        if (tdm_debug_module & TDM_DEBUG_BUFFER)
@@ -396,7 +396,7 @@ tdm_pp_attach(tdm_pp *pp, tbm_surface_h src, tbm_surface_h dst)
                char str[TDM_PATH_LEN];
                static int i;
                snprintf(str, TDM_PATH_LEN, "pp_src_%03d", i++);
-               tdm_helper_dump_buffer_str(src, str);
+               tdm_helper_dump_buffer_str(src, tdm_debug_dump_dir, str);
        }
 
        pp_buffer = calloc(1, sizeof *pp_buffer);
index 21649b6..186ac14 100644 (file)
@@ -105,6 +105,8 @@ enum {
        TDM_DUMP_FLAG_CAPTURE = (1 << 2),
 };
 
+#define TDM_DUMP_DIR    "/tmp"
+
 typedef struct _tdm_private_display tdm_private_display;
 typedef struct _tdm_private_output tdm_private_output;
 typedef struct _tdm_private_layer tdm_private_layer;
@@ -481,8 +483,10 @@ tdm_server_init(tdm_private_loop *private_loop);
 void
 tdm_server_deinit(tdm_private_loop *private_loop);
 
+char *
+tdm_helper_dump_make_directory(const char *path, char *reply, int *len);
 void
-tdm_helper_dump_buffer_str(tbm_surface_h buffer, const char *str);
+tdm_helper_dump_buffer_str(tbm_surface_h buffer, char *dir, char *str);
 unsigned long
 tdm_helper_get_time_in_millis(void);
 unsigned long
@@ -491,6 +495,7 @@ tdm_helper_get_time_in_micros(void);
 extern pthread_mutex_t tdm_mutex_check_lock;
 extern int tdm_mutex_locked;
 extern int tdm_dump_enable;
+extern char *tdm_debug_dump_dir;
 
 #define _pthread_mutex_unlock(l) \
        do { \
@@ -553,7 +558,7 @@ tdm_display_update_output(tdm_private_display *private_display,
 tdm_error
 tdm_display_enable_debug_module(const char*modules);
 tdm_error
-tdm_display_enable_dump(const char *dump_str);
+tdm_display_enable_dump(tdm_private_display *private_display, const char *dump_str, char *reply, int *len);
 tdm_error
 tdm_display_enable_path(const char *path);