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, char *path)
180 tbm_bufmgr_debug_dump_set_scale(scale);
181 tbm_bufmgr_debug_dump_all(path);
186 _waylend_tbm_util_dump_queue(WL_TBM_MONITOR_PROC_STATE cmd, tbm_bufmgr bufmgr, double scale)
188 static char *path = NULL;
190 if (!bDump && cmd == WL_TBM_MONITOR_PROC_STATE_ON) {
191 path = _wayland_tbm_dump_directory_make();
193 tbm_bufmgr_debug_dump_set_scale(scale);
194 tbm_bufmgr_debug_queue_dump(path, 20, 1);
197 } else if (bDump && cmd == WL_TBM_MONITOR_PROC_STATE_OFF) {
198 tbm_bufmgr_debug_queue_dump(NULL, 0, 0);
209 _wayland_tbm_util_get_appname_brief(char *brief)
213 char temp[255] = {0,};
214 char *saveptr = NULL;
216 token = strtok_r(brief, delim, &saveptr);
218 while (token != NULL) {
219 memset(temp, 0x00, 255 * sizeof(char));
220 strncpy(temp, token, 254 * sizeof(char));
221 token = strtok_r(NULL, delim, &saveptr);
224 snprintf(brief, sizeof(temp), "%s", temp);
228 _wayland_tbm_util_get_appname_from_pid(long pid, char *str)
233 char fn_cmdline[255] = {0,};
234 char cmdline[255] = {0,};
236 snprintf(fn_cmdline, sizeof(fn_cmdline), "/proc/%ld/cmdline", app_pid);
238 fp = fopen(fn_cmdline, "r");
240 fprintf(stderr, "cannot file open /proc/%ld/cmdline", app_pid);
244 if (!fgets(cmdline, 255, fp)) {
245 fprintf(stderr, "fail to get appname for pid(%ld)\n", app_pid);
251 len = strlen(cmdline);
253 memset(cmdline, 0x00, 255);
257 snprintf(str, sizeof(cmdline), "%s", cmdline);
261 _wayland_tbm_check_dlog_enable(void)
266 env = getenv("WL_TBM_DLOG");
269 WL_TBM_LOG("WL_TBM_DLOG=%s", env);
278 _wayland_tbm_dump_directory_make(void)
283 char appname[255] = {'\0'};
287 buf = calloc(1, sizeof(struct tm));
291 t = localtime_r(&timer, buf);
297 fullpath = (char *) calloc(1, PATH_MAX * sizeof(char));
303 _wayland_tbm_util_get_appname_from_pid(getpid(), appname);
305 _wayland_tbm_util_get_appname_brief(appname);
308 snprintf(fullpath, PATH_MAX, "/tmp/tbm_dump_%s_%04d%02d%02d.%02d%02d%02d", appname, t->tm_year + 1900,
309 t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
313 if ((mkdir(fullpath, 0755)) < 0) {