e_info: enhance dump buffers functionality
authorJunkyeong Kim <jk0430.kim@samsung.com>
Wed, 29 Jun 2016 04:28:19 +0000 (13:28 +0900)
committerGwanglim Lee <gl77.lee@samsung.com>
Wed, 29 Jun 2016 13:24:43 +0000 (22:24 +0900)
can change dump buffer count by '-c' option
can change dump files saving location by '-p' option

Change-Id: I078359a676e55a614235f1396826b5631bcc379d
Signed-off-by: Junkyeong Kim <jk0430.kim@samsung.com>
src/bin/e_info_client.c
src/bin/e_info_server.c

index 1ffb11d673c9f4df9407677045220082b861a29b..a6ac94275dcd135d717abd3196fa4c81001904bc 100644 (file)
@@ -1221,30 +1221,187 @@ _e_info_client_proc_transform_set(int argc, char **argv)
      }
 }
 
+#define DUMP_BUFFERS_USAGE \
+  "  enlightenment_info -dump_buffers [ARG]...\n" \
+  "  enlightenment_info -dump_buffers 1                : start dump buffer (default - buffer_count:100, path:/tmp/dump_xxxx/\n" \
+  "  enlightenment_info -dump_buffers 1 -c 50          : start dump buffer with 50 buffers\n" \
+  "  enlightenment_info -dump_buffers 1 -p /tmp/test   : start dump buffer - the dump path is '/tmp/test/dump_xxxx'\n" \
+  "  enlightenment_info -dump_buffers 1 -c 60 -p /test : start dump buffer with 60 buffers to '/test/dump_xxxx' folder\n" \
+  "  enlightenment_info -dump_buffers 0                : stop dump buffer (store dump files to dump path)\n" \
+
+static char *
+_buffer_shot_directory_check(char *path)
+{
+   char dir[PATH_MAX], curdir[PATH_MAX];
+   char *fullpath;
+   DIR *dp;
+
+   fullpath = (char*)calloc(1, PATH_MAX * sizeof(char));
+   if (!fullpath)
+     {
+        printf("fail to alloc pathname memory\n");
+        return NULL;
+     }
+
+   if (path && path[0] == '/')
+     snprintf(dir, PATH_MAX, "%s", path);
+   else
+     {
+        char *temp = getcwd(curdir, PATH_MAX);
+        if (!temp)
+          {
+             free(fullpath);
+             return NULL;
+          }
+        if (path)
+          {
+             if (strlen(curdir) == 1 && curdir[0] == '/')
+               snprintf(dir, PATH_MAX, "/%s", path);
+             else
+               snprintf(dir, PATH_MAX, "%s/%s", curdir, path);
+          }
+        else
+          snprintf(dir, PATH_MAX, "%s", curdir);
+     }
+
+   if (!(dp = opendir(dir)))
+     {
+        free(fullpath);
+        printf("not exist: %s\n", dir);
+        return NULL;
+     }
+   else
+      closedir (dp);
+
+   snprintf(fullpath, PATH_MAX, "%s", dir);
+
+   return fullpath;
+}
+
 static void
 _e_info_client_proc_buffer_shot(int argc, char **argv)
 {
+   int dumprun = 0;
+   int count = 100;
+   char path[PATH_MAX];
+
+   strncpy(path, "/tmp", PATH_MAX);
    if (argc == 3)
      {
-        int dumprun = atoi(argv[2]);
+        dumprun = atoi(argv[2]);
 
-        if (dumprun < 0 || dumprun > 1)
-          {
-             printf("Error Check Args : enlightenment_info -dump_buffers [1: start, 0: stop]\n");
-             return;
-          }
+        if (dumprun < 0 || dumprun > 1) goto err;
 
-        if (!_e_info_client_eldbus_message_with_args("dump_buffers", NULL, "i", dumprun))
+        if (!_e_info_client_eldbus_message_with_args("dump_buffers", NULL, "iis", dumprun, count, path))
           {
              printf("_e_info_client_proc_buffer_shot fail (%d)\n", dumprun);
              return;
           }
         printf("_e_info_client_proc_buffer_shot %s\n", (dumprun == 1 ? "start" : "stop"));
      }
-   else
+   else if (argc == 5)
+     {
+        dumprun = atoi(argv[2]);
+
+        if (dumprun < 0 || dumprun > 1) goto err;
+
+        if (eina_streq(argv[3], "-c"))
+          {
+             count = atoi(argv[4]);
+             if (count < 0) goto err;
+
+             if (!_e_info_client_eldbus_message_with_args("dump_buffers", NULL, "iis", dumprun, count, path))
+               {
+                  printf("_e_info_client_proc_buffer_shot fail (%d)\n", dumprun);
+                  return;
+               }
+             printf("_e_info_client_proc_buffer_shot %s\n", (dumprun == 1 ? "start" : "stop"));
+          }
+        else if (eina_streq(argv[3], "-p"))
+          {
+             char *tmp_path = _buffer_shot_directory_check(argv[4]);
+             if (tmp_path == NULL)
+               {
+                  printf("cannot find directory: %s\n", argv[4]);
+                  goto err;
+               }
+
+             if (!_e_info_client_eldbus_message_with_args("dump_buffers", NULL, "iis", dumprun, count, tmp_path))
+               {
+                  printf("_e_info_client_proc_buffer_shot fail (%d)\n", dumprun);
+                  free(tmp_path);
+                  return;
+               }
+             free(tmp_path);
+          }
+        else
+          goto err;
+     }
+   else if (argc == 7)
      {
-        printf("Error Check Args : enlightenment_info -dump_buffers [1: start, 0: stop]\n");
+        dumprun = atoi(argv[2]);
+
+        if (dumprun < 0 || dumprun > 1) goto err;
+
+        if (eina_streq(argv[3], "-c"))
+          {
+             char *tmp_path = NULL;
+
+             if (!eina_streq(argv[5], "-p")) goto err;
+
+             count = atoi(argv[4]);
+             if (count < 0) goto err;
+
+             tmp_path = _buffer_shot_directory_check(argv[6]);
+             if (tmp_path == NULL)
+               {
+                  printf("cannot find directory: %s\n", argv[6]);
+                  goto err;
+               }
+
+             if (!_e_info_client_eldbus_message_with_args("dump_buffers", NULL, "iis", dumprun, count, tmp_path))
+               {
+                  printf("_e_info_client_proc_buffer_shot fail (%d)\n", dumprun);
+                  return;
+               }
+             printf("_e_info_client_proc_buffer_shot %s\n", (dumprun == 1 ? "start" : "stop"));
+          }
+        else if (eina_streq(argv[3], "-p"))
+          {
+             char *tmp_path = NULL;
+
+             if (!eina_streq(argv[5], "-c")) goto err;
+
+             count = atoi(argv[6]);
+             if (count < 0) goto err;
+
+             tmp_path = _buffer_shot_directory_check(argv[4]);
+             if (tmp_path == NULL)
+               {
+                  printf("cannot find directory: %s\n", argv[4]);
+                  goto err;
+               }
+
+             if (!_e_info_client_eldbus_message_with_args("dump_buffers", NULL, "iis", dumprun, count, tmp_path))
+               {
+                  printf("_e_info_client_proc_buffer_shot fail (%d)\n", dumprun);
+                  free(tmp_path);
+                  return;
+               }
+             free(tmp_path);
+          }
+        else
+          goto err;
      }
+   else
+     goto err;
+
+   return;
+
+err:
+   printf("Error Check Args\n%s\n", DUMP_BUFFERS_USAGE);
+return;
+
 }
 
 #ifdef HAVE_HWC
@@ -1411,8 +1568,8 @@ static struct
       _e_info_client_proc_transform_set
    },
    {
-      "dump_buffers", "[start:1,stop:0]",
-      "Dump attach buffers (start:1,stop:0, path:/tmp/dump_xxx/)",
+      "dump_buffers", DUMP_BUFFERS_USAGE,
+      "Dump attach buffers [on:1,off:0] (default path:/tmp/dump_xxx/)",
       _e_info_client_proc_buffer_shot
    },
 #ifdef HAVE_HWC
index b7902055c4d35c415f3fbfacaef085080435f399..86c1ef42b14a9df13a273bd028945e1a54fa9b38 100644 (file)
@@ -1359,7 +1359,7 @@ _e_info_server_cb_buffer_change(void *data, int type, void *event)
 }
 
 static char *
-_e_info_server_dump_directory_make(void)
+_e_info_server_dump_directory_make(const char *path)
 {
    char *fullpath;
    time_t timer;
@@ -1385,7 +1385,7 @@ _e_info_server_dump_directory_make(void)
         return NULL;
      }
 
-   snprintf(fullpath, PATH_MAX, "/tmp/dump_%04d%02d%02d.%02d%02d%02d",
+   snprintf(fullpath, PATH_MAX, "%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);
 
    free(buf);
@@ -1405,8 +1405,10 @@ _e_info_server_cb_buffer_dump(const Eldbus_Service_Interface *iface EINA_UNUSED,
 {
    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
    int start = 0;
+   int count = 0;
+   const char *path = NULL;
 
-   if (!eldbus_message_arguments_get(msg, "i", &start))
+   if (!eldbus_message_arguments_get(msg, "iis", &start, &count, &path))
      {
         ERR("Error getting arguments.");
         return reply;
@@ -1418,7 +1420,7 @@ _e_info_server_cb_buffer_dump(const Eldbus_Service_Interface *iface EINA_UNUSED,
           return reply;
         e_info_dump_running = 1;
         e_info_dump_count = 1;
-        e_info_dump_path = _e_info_server_dump_directory_make();
+        e_info_dump_path = _e_info_server_dump_directory_make(path);
         if (e_info_dump_path == NULL)
           {
              e_info_dump_running = 0;
@@ -1428,7 +1430,7 @@ _e_info_server_cb_buffer_dump(const Eldbus_Service_Interface *iface EINA_UNUSED,
         else
           {
              /* start dump */
-             tbm_surface_internal_dump_start(e_info_dump_path, e_comp->w, e_comp->h, 100);
+             tbm_surface_internal_dump_start(e_info_dump_path, e_comp->w, e_comp->h, count);
              tdm_helper_dump_start(e_info_dump_path, &e_info_dump_count);
              E_LIST_HANDLER_APPEND(e_info_dump_hdlrs, E_EVENT_CLIENT_BUFFER_CHANGE,
                                _e_info_server_cb_buffer_change, NULL);
@@ -1561,7 +1563,7 @@ static const Eldbus_Method methods[] = {
    { "protocol_rule", ELDBUS_ARGS({"sss", "protocol_rule"}), ELDBUS_ARGS({"s", "rule request"}), _e_info_server_cb_protocol_rule, 0},
    { "get_fps_info", NULL, ELDBUS_ARGS({"s", "fps request"}), _e_info_server_cb_fps_info_get, 0},
    { "transform_message", ELDBUS_ARGS({"siiiiiiii", "transform_message"}), NULL, e_info_server_cb_transform_message, 0},
-   { "dump_buffers", ELDBUS_ARGS({"i", "start"}), NULL, _e_info_server_cb_buffer_dump, 0 },
+   { "dump_buffers", ELDBUS_ARGS({"iis", "start"}), NULL, _e_info_server_cb_buffer_dump, 0 },
 #ifdef HAVE_HWC
    { "hwc_trace_message", ELDBUS_ARGS({"i", "hwc_trace_message"}), NULL, e_info_server_cb_hwc_trace_message, 0},
 #endif