monitor: implement trace 64/76864/2
authorRoman Marchenko <r.marchenko@samsung.com>
Mon, 27 Jun 2016 12:51:47 +0000 (15:51 +0300)
committerRoman Marchenko <r.marchenko@samsung.com>
Wed, 29 Jun 2016 06:32:41 +0000 (09:32 +0300)
Change-Id: I0f04be446dc8b63dd05b60c849ad6e5ae8c88917
Signed-off-by: Roman Marchenko <r.marchenko@samsung.com>
src/wayland-tbm-client.c
src/wayland-tbm-int.h
src/wayland-tbm-server.c
src/wayland-tbm-util.c
tool/wayland-tbm-monitor.c

index 3bf788d..30189e8 100644 (file)
@@ -50,6 +50,8 @@ struct wayland_tbm_client {
 
        tbm_bufmgr bufmgr;
 
+       WL_TBM_MONITOR_TRACE_STATUS trace_state;
+
        struct wl_list queue_info_list;
 };
 
@@ -83,9 +85,11 @@ struct wayland_tbm_surface_queue {
        struct wl_list link;
 };
 
+WL_TBM_MONITOR_TRACE_STATUS trace_status;
+
 //#define DEBUG_TRACE
 #ifdef DEBUG_TRACE
-#define WL_TBM_TRACE(fmt, ...)   fprintf (stderr, "[WL_TBM_C(%d):%s] " fmt, getpid(), __func__, ##__VA_ARGS__)
+#define WL_TBM_TRACE(fmt, ...)   if (trace_status == WL_TBM_MONITOR_TRACE_STATUS_ON) fprintf (stderr, "[WL_TBM_C(%d):%s] " fmt, getpid(), __func__, ##__VA_ARGS__)
 #else
 #define WL_TBM_TRACE(fmt, ...)
 #endif
@@ -100,6 +104,11 @@ handle_tbm_monitor_client_tbm_bo(void *data,
 {
        struct wayland_tbm_client *tbm_client = (struct wayland_tbm_client *)data;
 
+#ifdef DEBUG_TRACE
+       WL_TBM_TRACE("command=%d, trace_command=%d, target=%d, pid=%d.\n",
+                  command, trace_command, target, pid);
+#endif
+
        if (command == WL_TBM_MONITOR_COMMAND_SHOW) {
                if (target == WL_TBM_MONITOR_TARGET_CLIENT) {
                        if (getpid() == pid)
@@ -111,7 +120,22 @@ handle_tbm_monitor_client_tbm_bo(void *data,
                                   target);
                }
        } else if (command == WL_TBM_MONITOR_COMMAND_TRACE) {
-               WL_TBM_LOG("[%s]: TRACE is not implemented.\n", __func__);
+               if (target == WL_TBM_MONITOR_TARGET_CLIENT) {
+                       if (getpid() == pid) {
+                               if (trace_command == WL_TBM_MONITOR_TRACE_COMMAND_STATUS)
+                                       WL_TBM_DEBUG("clinet(%d): trace status: %s\n", getpid(), _tarce_status_to_str(trace_status));
+                               else
+                                       _change_trace_status(&trace_status, trace_command, tbm_client->bufmgr);
+                       }
+               } else if (target == WL_TBM_MONITOR_TARGET_ALL) {
+                       if (trace_command == WL_TBM_MONITOR_TRACE_COMMAND_STATUS)
+                               WL_TBM_DEBUG("clinet(%d): trace status: %s\n", getpid(), _tarce_status_to_str(trace_status));
+                       else
+                               _change_trace_status(&trace_status, trace_command, tbm_client->bufmgr);
+               } else {
+                       WL_TBM_LOG("[%s]: Error target is not available. target = %d\n", __func__,
+                                  target);
+               }
        } else {
                WL_TBM_LOG("[%s]: Error command is not available. command = %d\n", __func__,
                           command);
@@ -163,6 +187,8 @@ wayland_tbm_client_init(struct wl_display *display)
 
        _wayland_tbm_check_dlog_enable();
 
+       trace_status = WL_TBM_MONITOR_TRACE_STATUS_UNREGISTERED;
+
        tbm_client = calloc(1, sizeof(struct wayland_tbm_client));
        WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
 
index cce87f3..fa80c1f 100644 (file)
@@ -34,6 +34,7 @@ DEALINGS IN THE SOFTWARE.
 extern "C" {
 #endif
 
+#include <tbm_bufmgr.h>
 #include "wayland-tbm-client.h"
 
 #define HAVE_DLOG
@@ -117,6 +118,12 @@ typedef enum {
 } WL_TBM_MONITOR_TRACE_COMMAND;
 
 typedef enum {
+       WL_TBM_MONITOR_TRACE_STATUS_UNREGISTERED,
+       WL_TBM_MONITOR_TRACE_STATUS_OFF,
+       WL_TBM_MONITOR_TRACE_STATUS_ON,
+} WL_TBM_MONITOR_TRACE_STATUS;
+
+typedef enum {
        WL_TBM_MONITOR_TARGET_CLIENT,
        WL_TBM_MONITOR_TARGET_SERVER,
        WL_TBM_MONITOR_TARGET_ALL,
@@ -135,6 +142,12 @@ _wayland_tbm_util_get_appname_from_pid(long pid, char *str);
 void
 _wayland_tbm_check_dlog_enable(void);
 
+void
+_change_trace_status(WL_TBM_MONITOR_TRACE_STATUS * curr_status, WL_TBM_MONITOR_TRACE_COMMAND cmd, tbm_bufmgr bufmgr);
+
+char *
+_tarce_status_to_str(WL_TBM_MONITOR_TRACE_STATUS status);
+
 #ifdef  __cplusplus
 }
 #endif
index 4bf9b95..ffcc35b 100644 (file)
@@ -45,10 +45,12 @@ DEALINGS IN THE SOFTWARE.
 \r
 #include "wayland-tbm-int.h"\r
 \r
+WL_TBM_MONITOR_TRACE_STATUS trace_status;\r
+\r
 //#define WL_TBM_SERVER_DEBUG\r
 //#define DEBUG_TRACE\r
 #ifdef DEBUG_TRACE\r
-#define WL_TBM_TRACE(fmt, ...)   fprintf (stderr, "[WL_TBM_S(%d):%s] " fmt, getpid(), __func__, ##__VA_ARGS__)\r
+#define WL_TBM_TRACE(fmt, ...)   if (trace_status == WL_TBM_MONITOR_TRACE_STATUS_ON) fprintf (stderr, "[WL_TBM_S(%d):%s] " fmt, getpid(), __func__, ##__VA_ARGS__)\r
 #else\r
 #define WL_TBM_TRACE(fmt, ...)\r
 #endif\r
@@ -317,7 +319,11 @@ _wayland_tbm_server_impl_request_tbm_monitor(struct wl_client *client,
                if (command == WL_TBM_MONITOR_COMMAND_SHOW) {\r
                        tbm_bufmgr_debug_show(tbm_srv->bufmgr);\r
                } else if (command == WL_TBM_MONITOR_COMMAND_TRACE) {\r
-                       WL_TBM_LOG("[%s]: TRACE NOT IMPLEMENTED.\n", __func__);\r
+                       if (trace_command == WL_TBM_MONITOR_TRACE_COMMAND_STATUS)\r
+                               WL_TBM_DEBUG("server: trace status: %s\n",\r
+                                                       _tarce_status_to_str(trace_status));\r
+                       else\r
+                               _change_trace_status(&trace_status, trace_command, tbm_srv->bufmgr);\r
                } else\r
                        wl_resource_post_error(resource, WL_TBM_ERROR_INVALID_FORMAT,\r
                                               "invalid format");\r
@@ -336,9 +342,22 @@ _wayland_tbm_server_impl_request_tbm_monitor(struct wl_client *client,
                        }\r
                        tbm_bufmgr_debug_show(tbm_srv->bufmgr);\r
                } else if (command == WL_TBM_MONITOR_COMMAND_TRACE) {\r
-                       wl_tbm_send_monitor_client_tbm_bo(resource, command, trace_command, target,\r
-                                                         pid);\r
-                       WL_TBM_LOG("[%s]: TRACE NOT IMPLEMENTED.\n", __func__);\r
+                       /* send the events to all client containing wl_tbm resource except for the wayland-tbm-monitor(requestor). */\r
+                       if (!wl_list_empty(&tbm_srv->cresource_list)) {\r
+                               wl_list_for_each_safe(c_res, tmp_res, &tbm_srv->cresource_list, link) {\r
+                                       /* skip the requestor (wayland-tbm-monitor */\r
+                                       if (c_res->resource == resource)\r
+                                               continue;\r
+\r
+                                       wl_tbm_send_monitor_client_tbm_bo(c_res->resource, command, trace_command,\r
+                                                                         target, pid);\r
+                               }\r
+                       }\r
+                       if (trace_command == WL_TBM_MONITOR_TRACE_COMMAND_STATUS)\r
+                               WL_TBM_DEBUG("server: trace status: %s\n",\r
+                                                       _tarce_status_to_str(trace_status));\r
+                       else\r
+                               _change_trace_status(&trace_status, trace_command, tbm_srv->bufmgr);\r
                } else\r
                        wl_resource_post_error(resource, WL_TBM_ERROR_INVALID_FORMAT,\r
                                               "invalid format");\r
@@ -648,6 +667,8 @@ wayland_tbm_server_init(struct wl_display *display, const char *device_name,
 \r
        _wayland_tbm_check_dlog_enable();\r
 \r
+       trace_status = WL_TBM_MONITOR_TRACE_STATUS_UNREGISTERED;\r
+\r
        tbm_srv = calloc(1, sizeof(struct wayland_tbm_server));\r
        WL_TBM_RETURN_VAL_IF_FAIL(tbm_srv != NULL, NULL);\r
 \r
index fccb5ae..fcb8f62 100644 (file)
@@ -38,6 +38,40 @@ DEALINGS IN THE SOFTWARE.
 int bDlog;
 #endif
 
+char * _tarce_status_to_str(WL_TBM_MONITOR_TRACE_STATUS status)
+{
+       if (status == WL_TBM_MONITOR_TRACE_STATUS_OFF)
+               return "off";
+       else if (status == WL_TBM_MONITOR_TRACE_STATUS_ON)
+               return "on";
+       else if (status == WL_TBM_MONITOR_TRACE_STATUS_UNREGISTERED)
+               return "unregistered";
+       return "unknown";
+}
+
+void _change_trace_status(WL_TBM_MONITOR_TRACE_STATUS * curr_status, WL_TBM_MONITOR_TRACE_COMMAND cmd, tbm_bufmgr bufmgr)
+{
+       if (cmd == WL_TBM_MONITOR_TRACE_COMMAND_ON) {
+               if (*curr_status == WL_TBM_MONITOR_TRACE_STATUS_OFF) {
+                       tbm_bufmgr_debug_trace(bufmgr, 1);
+                       *curr_status = WL_TBM_MONITOR_TRACE_STATUS_ON;
+               }
+       } else if (cmd == WL_TBM_MONITOR_TRACE_COMMAND_OFF) {
+               if (*curr_status == WL_TBM_MONITOR_TRACE_STATUS_ON) {
+                       tbm_bufmgr_debug_trace(bufmgr, 0);
+                       *curr_status = WL_TBM_MONITOR_TRACE_STATUS_OFF;
+               }
+       } else if (cmd == WL_TBM_MONITOR_TRACE_COMMAND_REGISTER) {
+               if (*curr_status == WL_TBM_MONITOR_TRACE_STATUS_UNREGISTERED) {
+                       tbm_bufmgr_debug_trace(bufmgr, 0);
+                       *curr_status = WL_TBM_MONITOR_TRACE_STATUS_OFF;
+               }
+       } else if (cmd == WL_TBM_MONITOR_TRACE_COMMAND_UNREGISTER) {
+               *curr_status = WL_TBM_MONITOR_TRACE_STATUS_UNREGISTERED;
+               tbm_bufmgr_debug_trace(bufmgr, 0);
+       }
+}
+
 void
 _wayland_tbm_util_get_appname_brief(char *brief)
 {
index 3704399..3629f5a 100644 (file)
@@ -195,8 +195,10 @@ _wl_tbm_monitor_process_options(struct wayland_tbm_monitor *tbm_monitor,
 
                if (!strncmp(argv[2], "on", strlen(argv[2]) + 1)) {
                        tbm_monitor->options.trace_command = WL_TBM_MONITOR_TRACE_COMMAND_ON;
+                       tbm_monitor->options.target = WL_TBM_MONITOR_TARGET_ALL;
                } else if (!strncmp(argv[2], "off", strlen(argv[2]) + 1)) {
                        tbm_monitor->options.trace_command = WL_TBM_MONITOR_TRACE_COMMAND_OFF;
+                       tbm_monitor->options.target = WL_TBM_MONITOR_TARGET_ALL;
                } else if (!strncmp(argv[2], "register", strlen(argv[2]) + 1)) {
                        if (argc < 4) {
                                WL_TBM_LOG("error: no pid. please type the target(client [pid]/server/all).\n");
@@ -205,7 +207,7 @@ _wl_tbm_monitor_process_options(struct wayland_tbm_monitor *tbm_monitor,
                        }
 
                        tbm_monitor->options.trace_command = WL_TBM_MONITOR_TRACE_COMMAND_REGISTER;
-                       if (_wl_tbm_select_target_option(tbm_monitor, argc, argv, 3)) {
+                       if (!_wl_tbm_select_target_option(tbm_monitor, argc, argv, 3)) {
                                WL_TBM_LOG("error: no pid. please type the target(client [pid]/server/all).\n");
                                _wl_tbm_trace_usage();
                                return 0;
@@ -218,13 +220,14 @@ _wl_tbm_monitor_process_options(struct wayland_tbm_monitor *tbm_monitor,
                        }
 
                        tbm_monitor->options.trace_command = WL_TBM_MONITOR_TRACE_COMMAND_UNREGISTER;
-                       if (_wl_tbm_select_target_option(tbm_monitor, argc, argv, 3)) {
+                       if (!_wl_tbm_select_target_option(tbm_monitor, argc, argv, 3)) {
                                WL_TBM_LOG("error: no pid. please type the target(client [pid]/server/all).\n");
                                _wl_tbm_trace_usage();
                                return 0;
                        }
                } else if (!strncmp(argv[2], "status", strlen(argv[2]) + 1)) {
                        tbm_monitor->options.trace_command = WL_TBM_MONITOR_TRACE_COMMAND_STATUS;
+                       tbm_monitor->options.target = WL_TBM_MONITOR_TARGET_ALL;
                } else {
                        _wl_tbm_trace_usage();
                        return 0;