2 Copyright (C) 2015 Samsung Electronics co., Ltd. All Rights Reserved.
5 SooChan Lim <sc1.lim@samsung.com>,
6 Sangjin Lee <lsj119@samsung.com>,
7 Boram Park <boram1288.park@samsung.com>,
8 Changyeon Lee <cyeon.lee@samsung.com>
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the "Software"),
12 to deal in the Software without restriction, including without limitation
13 the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 and/or sell copies of the Software, and to permit persons to whom the
15 Software is furnished to do so, subject to the following conditions:
17 The above copyright notice and this permission notice (including the next
18 paragraph) shall be included in all copies or substantial portions of the
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
38 #include <sys/types.h>
40 #include <tbm_surface.h>
41 #include <tbm_surface_internal.h>
42 #include "wayland-tbm-int.h"
52 _str_to_pid(char * pid_str)
73 _waylend_tbm_util_target_parse(char * target_str, struct wayland_tbm_monitor_target *target)
76 char *end = target_str;
85 if (target_str == NULL || !strncmp(target_str, "all", 3)) {
89 while ((t = strtok_r(NULL, ",", &end)) != NULL) {
90 if (!strncmp(t, "server", 6))
92 else if ((pid = _str_to_pid(t)) >= 0)
93 target->pid[i++] = pid;
99 target->server = server;
107 _waylend_tbm_util_scale_parse(char * scale_str, double *scale)
112 if (sscanf(scale_str, "scale=%lf", scale) == 1)
113 if (*scale >= 0 && *scale <= 1)
119 WL_TBM_MONITOR_PROC_STATE
120 _waylend_tbm_util_proc_state_parse(char *str)
123 return WL_TBM_MONITOR_PROC_STATE_UNKNOWN;
124 if (!strncmp(str, "on", 2))
125 return WL_TBM_MONITOR_PROC_STATE_ON;
126 if (!strncmp(str, "off", 3))
127 return WL_TBM_MONITOR_PROC_STATE_OFF;
128 if (!strncmp(str, "status", 6))
129 return WL_TBM_MONITOR_PROC_STATE_STATUS;
130 return WL_TBM_MONITOR_PROC_STATE_UNKNOWN;
134 _wayland_tbm_util_show_path_parse(char * path_str, char * cwd, struct wayland_tbm_monitor_path *path)
136 char *end = path_str;
143 while ((p = strtok_r(NULL, ",", &end)) != NULL) {
144 if (!strncmp(p, "dlog", 4))
146 else if (!strncmp(p, "console", 7))
150 snprintf(path->file, WL_TBM_MONITOR_PATH_LEN, "%s", p);
153 snprintf(path->file, WL_TBM_MONITOR_PATH_LEN, "%s/%s", cwd, p);
155 snprintf(path->file, WL_TBM_MONITOR_PATH_LEN, "%s", p);
165 _waylend_tbm_util_trace(WL_TBM_MONITOR_PROC_STATE cmd, tbm_bufmgr bufmgr)
167 if (!bTrace && cmd == WL_TBM_MONITOR_PROC_STATE_ON) {
168 tbm_bufmgr_debug_trace(bufmgr, 1);
170 } else if (bTrace && cmd == WL_TBM_MONITOR_PROC_STATE_OFF) {
171 tbm_bufmgr_debug_trace(bufmgr, 0);
177 _waylend_tbm_util_dump_snapshot(tbm_bufmgr bufmgr, double scale)
179 char *path = _wayland_tbm_dump_directory_make();
181 tbm_bufmgr_debug_dump_set_scale(scale);
182 tbm_bufmgr_debug_dump_all(path);
189 _waylend_tbm_util_dump_queue(WL_TBM_MONITOR_PROC_STATE cmd, tbm_bufmgr bufmgr, double scale)
191 static char *path = NULL;
193 if (!bDump && cmd == WL_TBM_MONITOR_PROC_STATE_ON) {
194 path = _wayland_tbm_dump_directory_make();
196 tbm_bufmgr_debug_dump_set_scale(scale);
197 tbm_bufmgr_debug_queue_dump(path, 20, 1);
200 } else if (bDump && cmd == WL_TBM_MONITOR_PROC_STATE_OFF) {
201 tbm_bufmgr_debug_queue_dump(NULL, 0, 0);
212 _wayland_tbm_util_get_appname_brief(char *brief)
216 char temp[255] = {0,};
217 char *saveptr = NULL;
219 token = strtok_r(brief, delim, &saveptr);
221 while (token != NULL) {
222 memset(temp, 0x00, 255 * sizeof(char));
223 strncpy(temp, token, 254 * sizeof(char));
224 token = strtok_r(NULL, delim, &saveptr);
227 snprintf(brief, sizeof(temp), "%s", temp);
231 _wayland_tbm_util_get_appname_from_pid(long pid, char *str)
236 char fn_cmdline[255] = {0,};
237 char cmdline[255] = {0,};
239 snprintf(fn_cmdline, sizeof(fn_cmdline), "/proc/%ld/cmdline", app_pid);
241 fp = fopen(fn_cmdline, "r");
243 fprintf(stderr, "cannot file open /proc/%ld/cmdline", app_pid);
247 if (!fgets(cmdline, 255, fp)) {
248 fprintf(stderr, "fail to get appname for pid(%ld)\n", app_pid);
254 len = strlen(cmdline);
256 memset(cmdline, 0x00, 255);
260 snprintf(str, sizeof(cmdline), "%s", cmdline);
264 _wayland_tbm_check_dlog_enable(void)
269 env = getenv("WL_TBM_DLOG");
272 WL_TBM_LOG("WL_TBM_DLOG=%s", env);
281 _wayland_tbm_dump_directory_make(void)
286 char appname[255] = {'\0'};
290 buf = calloc(1, sizeof(struct tm));
294 t = localtime_r(&timer, buf);
300 fullpath = (char *) calloc(1, PATH_MAX * sizeof(char));
306 _wayland_tbm_util_get_appname_from_pid(getpid(), appname);
308 _wayland_tbm_util_get_appname_brief(appname);
311 snprintf(fullpath, PATH_MAX, "/tmp/tbm_dump_%s_%04d%02d%02d.%02d%02d%02d", appname, t->tm_year + 1900,
312 t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
316 if ((mkdir(fullpath, 0755)) < 0) {