wayland-tbm-monitor: fix issue with a big message from clients 15/144715/4
authorRoman Marchenko <r.marchenko@samsung.com>
Thu, 17 Aug 2017 13:22:29 +0000 (16:22 +0300)
committerSooChan Lim <sc1.lim@samsung.com>
Fri, 18 Aug 2017 02:38:11 +0000 (02:38 +0000)
Change-Id: Ia7708ada13af545e3ffbd4effb83d0cc43926aaa
Signed-off-by: Roman Marchenko <r.marchenko@samsung.com>
src/wayland-tbm-client.c
src/wayland-tbm-monitor-server.c

index 9c8320f..a175a44 100644 (file)
@@ -220,18 +220,37 @@ static const struct wl_tbm_listener wl_tbm_client_listener = {
        handle_tbm_buffer_import_with_fd
 };
 
+void _waylend_tbm_monitor_client_print_show_to_file(char* show_str)
+{
+       FILE * f = NULL;
+       static int c = 0;
+       char tmp_file[256];
+
+       snprintf(tmp_file, sizeof(tmp_file), "/tmp/tbm_debug_show_%d%d", getpid(), c++);
+       if ((f = fopen(tmp_file, "a+")) != NULL) {
+               fprintf(f, "%s", show_str);
+               fclose(f);
+       }
+}
+
 void _waylend_tbm_monitor_client_show(int argc, char *argv[],
                                      char *reply, int *len, struct wayland_tbm_client *tbm_client)
 {
        struct wayland_tbm_monitor_path path = {0};
+       char show_str[1024*4] = {0,};
+       int show_len = sizeof(show_str);
 
        _wayland_tbm_util_show_path_parse(argv[2], 0, &path);
 
        if (path.dlog)
                tbm_bufmgr_debug_show(tbm_client->bufmgr);
 
-       /* always answer to the server */
-       tbm_bufmgr_debug_tbm_info_get(tbm_client->bufmgr, reply, len);
+       /* we have to save result to some file as reply can be very long */
+       tbm_bufmgr_debug_tbm_info_get(tbm_client->bufmgr, show_str, &show_len);
+       _waylend_tbm_monitor_client_print_show_to_file(show_str);
+
+       /* send empty string to close the session */
+       WL_TBM_MONITOR_SNPRINTF(reply, *len, "\n");
 }
 
 void _waylend_tbm_monitor_client_dump_snapshot(int argc, char *argv[],
index 3a7e645..45640f6 100644 (file)
@@ -30,6 +30,7 @@ DEALINGS IN THE SOFTWARE.
 
 #include "config.h"
 
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -38,6 +39,9 @@ DEALINGS IN THE SOFTWARE.
 #include <unistd.h>
 #include <fcntl.h>
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include <tbm_surface.h>
 #include <tbm_surface_internal.h>
 #include <wayland-server.h>
@@ -84,6 +88,72 @@ struct wayland_tbm_monitore_request {
 
 static void _wayland_tbm_monitor_server_usage(struct wayland_tbm_monitore_request *r);
 
+static int
+_wayland_tbm_monitor_server_collect_files(FILE* f_to_collect, int need_remove)
+{
+       char buf[1024*8];
+       int buf_len = 0;
+
+       DIR *dir_stream;
+       struct dirent *entry;
+       char * dir_name = "/tmp/";
+
+       int fd;
+
+       char *file_name = NULL;
+
+       dir_stream = opendir(dir_name);
+       if (!dir_stream) {
+               WL_TBM_LOG("got an error trying to call 'opendir'.\n");
+               return -1;
+       }
+
+       while ((entry = readdir(dir_stream))) {
+               if (strncmp(entry->d_name, "tbm_debug_show_", strlen("tbm_debug_show_")))
+                       continue;
+
+               int tmp = asprintf(&file_name, "%s/%s", dir_name, entry->d_name);
+               if (tmp < 0)
+                       continue;
+
+               fd = open(file_name, O_RDONLY);
+               if (fd < 0) {
+                       WL_TBM_LOG(" got an error trying to open file");
+                       free(file_name);
+                       continue;
+               }
+
+               while ((buf_len = read(fd, buf, sizeof(buf))) > 0)
+                       fwrite(buf, buf_len, 1, f_to_collect);
+
+               close(fd);
+
+               if (need_remove)
+                       unlink(file_name);
+
+               free(file_name);
+       }
+
+       closedir(dir_stream);
+
+       return 0;
+}
+
+void
+_wayland_tbm_monitor_add_info_printf(struct wayland_tbm_monitore_request *r)
+{
+       FILE *f;
+       if (r->path.file[0] != '\0') {
+               if ((f = fopen(r->path.file, "a+")) != NULL) {
+                       _wayland_tbm_monitor_server_collect_files(f, r->path.console && r->console ? 0 : 1);
+                       fclose(f);
+               }
+       }
+
+       if (r->path.console && r->console)
+               _wayland_tbm_monitor_server_collect_files(r->console, 1);
+}
+
 static void
 _wayland_tbm_monitor_request_printf(struct wayland_tbm_monitore_request *r, const char *fmt, ...)
 {
@@ -123,6 +193,8 @@ _wayland_tbm_monitor_request_unref(struct wayland_tbm_monitore_request *r)
        r->wait_count--;
        WL_TBM_TRACE("request_id:%d wait_count:%d\n", r->id, r->wait_count);
        if (r->wait_count <= 0) {
+               /* print additional info from clients */
+               _wayland_tbm_monitor_add_info_printf(r);
                wl_tbm_monitor_send_done(r->wl_resource, r->msg);
                _wayland_tbm_monitor_request_delete(r);
        }