wayland_tbm_monitor: add path opion for dump_snapshot 74/232974/1
authorChangyeon Lee <cyeon.lee@samsung.com>
Fri, 8 May 2020 06:12:45 +0000 (15:12 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Mon, 11 May 2020 04:28:51 +0000 (13:28 +0900)
Change-Id: Ife00fe7e63d69af6b1c95d8d9d7c17bfacddde77

src/wayland-tbm-int.h
src/wayland-tbm-monitor-client.c
src/wayland-tbm-monitor-server.c
src/wayland-tbm-util.c

index f80e287..ea57219 100644 (file)
@@ -167,6 +167,9 @@ _wayland_tbm_util_debug_level_parse(char * str, int *debug_level);
 int
 _wayland_tbm_util_show_path_parse(char * path_str, char * cwd, struct wayland_tbm_monitor_path *path);
 
+char *
+_wayland_tbm_util_dump_path_parse(char * path_str);
+
 WL_TBM_MONITOR_PROC_STATE
 _wayland_tbm_util_proc_state_parse(char * str);
 
@@ -183,7 +186,7 @@ int
 _wayland_tbm_util_trace(WL_TBM_MONITOR_PROC_STATE cmd, WL_TBM_MONITOR_RES res, tbm_bufmgr bufmgr);
 
 char *
-_wayland_tbm_dump_directory_make(void);
+_wayland_tbm_dump_directory_make(const char *path);
 
 void
 _wayland_tbm_util_set_log_level(int debug_level);
index 44a7614..1f68cfe 100644 (file)
@@ -85,15 +85,22 @@ void _wayland_tbm_monitor_client_dump_snapshot(int argc, char *argv[],
        double scale = 0;
        int i;
        char *path = NULL;
+       char *input_path = NULL;
 
        for (i = 1; i < argc; i++) {
+               if ((!input_path) && (input_path =_wayland_tbm_util_dump_path_parse(argv[i])))
+                       continue;
                if (_wayland_tbm_util_scale_parse(argv[i], &scale))
-                       break;
+                       continue;
        }
 
-       path = _wayland_tbm_dump_directory_make();
+       path = _wayland_tbm_dump_directory_make(input_path);
        _wayland_tbm_util_dump_snapshot((tbm_bufmgr)wayland_tbm_client_get_bufmgr(tbm_client), scale, path);
        WL_TBM_MONITOR_SNPRINTF(reply, *len, "client(%d): snapshot dump is done. path=%s\n", getpid(), path);
+
+       if (input_path)
+               free(input_path);
+
        free(path);
 }
 
index 4b3b2af..d480019 100644 (file)
@@ -375,8 +375,11 @@ _wayland_tbm_monitor_server_dump_snapshot(struct wayland_tbm_monitore_request *r
        double scale = 0;
        int i;
        char *path = NULL;
+       char *input_path = NULL;
 
        for (i = 1; i < r->argc; i++) {
+               if ((!input_path) && (input_path =_wayland_tbm_util_dump_path_parse(r->argv[i])))
+                       continue;
                if (_wayland_tbm_util_target_parse(r->argv[i], &target))
                        continue;
                if (_wayland_tbm_util_scale_parse(r->argv[i], &scale))
@@ -384,15 +387,23 @@ _wayland_tbm_monitor_server_dump_snapshot(struct wayland_tbm_monitore_request *r
 
                _wayland_tbm_monitor_request_printf(r, "'%s' - unknown target or scale for -dump_snapshot\n", r->argv[2]);
                _wayland_tbm_monitor_server_usage(r);
+
+               if (input_path)
+                       free(input_path);
+
                return;
        }
 
        if (target.server) {
-               path = _wayland_tbm_dump_directory_make();
+               path = _wayland_tbm_dump_directory_make(input_path);
                _wayland_tbm_util_dump_snapshot(r->tbm_srv->bufmgr, scale, path);
                _wayland_tbm_monitor_request_printf(r, "server: snapshot dump is done. path=%s\n", path);
                free(path);
        }
+
+       if (input_path)
+               free(input_path);
+
        _send_request_to_client_with_wait(r, &target, 1);
 }
 
@@ -513,9 +524,9 @@ static struct {
        {
                "dump_snapshot",
                _wayland_tbm_monitor_server_dump_snapshot,
-               "make dumps of all tbm_surfaces for (all | server,<pid>,... ) with scale"
+               "make dumps of all tbm_surfaces for (all | server,<pid>,... ) with scale and path"
                ,
-               "[<target>] [<scale>]\n"
+               "[<target>] [<scale>] [path]\n"
                "\t""  <target>\n"
                "\t""    all                 - clients and server\n"
                "\t""    server,<pid>,...    - list of targets"
@@ -523,6 +534,7 @@ static struct {
                "\n"
                "\t""wayland-tbm-monitor -dump_snapshot all scale=0.5\n"
                "\t""wayland-tbm-monitor -dump_snapshot server,1,2 scale=0.5"
+               "\t""wayland-tbm-monitor -dump_snapshot server,1,2 scale=0.5 /tmp"
        },
        {
                "dump_queue",
index 42fd0d1..19ad317 100644 (file)
@@ -199,6 +199,25 @@ _wayland_tbm_util_show_path_parse(char * path_str, char * cwd, struct wayland_tb
        return 1;
 }
 
+char *
+_wayland_tbm_util_dump_path_parse(char * path_str)
+{
+       char *path = NULL;
+
+       if (!path_str)
+               return NULL;
+
+       if (path_str[0] == '/') {
+               path = (char *) calloc(1, PATH_MAX * sizeof(char));
+               if (!path)
+                       return NULL;
+
+               snprintf(path, WL_TBM_MONITOR_PATH_LEN, "%s", path_str);
+               return path;
+       }
+
+       return NULL;
+}
 
 int
 _wayland_tbm_util_trace(WL_TBM_MONITOR_PROC_STATE cmd, WL_TBM_MONITOR_RES res, tbm_bufmgr bufmgr)
@@ -262,7 +281,7 @@ _wayland_tbm_util_dump_queue(WL_TBM_MONITOR_PROC_STATE cmd, tbm_bufmgr bufmgr, d
        static char *path = NULL;
 
        if (!bDump && cmd == WL_TBM_MONITOR_PROC_STATE_ON) {
-               path = _wayland_tbm_dump_directory_make();
+               path = _wayland_tbm_dump_directory_make(NULL);
                if (path != NULL) {
                        tbm_bufmgr_debug_dump_set_scale(scale);
                        tbm_bufmgr_debug_queue_dump(path, 20, 1);
@@ -332,7 +351,7 @@ _wayland_tbm_util_get_appname_from_pid(long pid, char *str)
 }
 
 char *
-_wayland_tbm_dump_directory_make(void)
+_wayland_tbm_dump_directory_make(const char *path)
 {
        char *fullpath;
        time_t timer;
@@ -361,9 +380,13 @@ _wayland_tbm_dump_directory_make(void)
 
        _wayland_tbm_util_get_appname_brief(appname);
 
-
-       snprintf(fullpath, PATH_MAX, "/tmp/tbm_dump_%s_%04d%02d%02d.%02d%02d%02d", appname, t->tm_year + 1900,
-                       t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
+       if (path) {
+               snprintf(fullpath, PATH_MAX, "%s/tbm_dump_%s_%04d%02d%02d.%02d%02d%02d", path, appname, t->tm_year + 1900,
+                               t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
+       } else {
+               snprintf(fullpath, PATH_MAX, "/tmp/tbm_dump_%s_%04d%02d%02d.%02d%02d%02d", appname, t->tm_year + 1900,
+                               t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
+       }
 
        free(buf);