} WL_TBM_MONITOR_PROC_STATE;
#define WL_TBM_MONITOR_REPLY_MSG_LEN 8192
-#define WL_TBM_MONITOR_ARGS_MAX 12
+#define WL_TBM_MONITOR_ARGS_MAX 12
+#define WL_TBM_MONITOR_PATH_LEN 256
#define WL_TBM_MONITOR_SNPRINTF(p, len, fmt, ARG...) \
do { \
int queue_dump;
};
-struct wayland_tbm_monitor_target
-{
+struct wayland_tbm_monitor_target {
int server;
int all;
int pid;
};
+struct wayland_tbm_monitor_path {
+ int console;
+ int dlog;
+ char file[WL_TBM_MONITOR_PATH_LEN];
+};
+
/* internal functions */
void
_wayland_tbm_util_get_appname_brief(char *brief);
int
_waylend_tbm_util_target_parse(char * target_str, struct wayland_tbm_monitor_target *target);
+int
+_wayland_tbm_util_show_path_parse(char * path_str, char * cwd, struct wayland_tbm_monitor_path *path);
+
WL_TBM_MONITOR_PROC_STATE
_waylend_tbm_util_proc_state_parse(char * str);
struct wl_client *wl_client;
struct wl_resource *wl_resource;
char app_name[256];
+ char cwd[WL_TBM_MONITOR_PATH_LEN];
char options[256]; /* raw options */
char arg_mem[256]; /* memory for argv */
int len;
FILE *console;
+ struct wayland_tbm_monitor_path path;
int wait_count;
};
static void
_wayland_tbm_monitor_request_printf(struct wayland_tbm_monitore_request *r, const char *fmt, ...)
{
+ FILE *f;
va_list arg;
va_start(arg, fmt);
- if (r->console)
+
+ if (r->path.file[0] != '\0') {
+ if ((f = fopen(r->path.file, "a+")) != NULL) {
+ vfprintf(f, fmt, arg);
+ fclose(f);
+ }
+ else
+ _wayland_tbm_monitor_request_printf(r, "server: can't write show to file: '%s'\n",
+ r->path.file);
+ }
+
+ if (r->path.console && r->console)
vfprintf(r->console, fmt, arg);
va_end(arg);
}
wl_resource_for_each(c_res, &r->tbm_srv->tbm_monitor_list) {
if (c_res == r->wl_resource)
continue;
+#ifdef DEBUG_TRACE
+ wl_client_get_credentials(wl_resource_get_client(c_res), &c_pid, NULL, NULL);
+ WL_TBM_TRACE("send request:%d(%d) to client:%d option:'%s'\n", r->id, r->wait_count, c_pid,r->options);
+#endif
wl_tbm_monitor_send_request_to_client(c_res, r->options, request_id);
if (wait_answer)
r->wait_count++;
/* send option string to c_res */
if (c_res) {
+ WL_TBM_TRACE("send request:%d(%d) to client:%d option:'%s'\n", r->id, r->wait_count, c_pid,r->options);
wl_tbm_monitor_send_request_to_client(c_res, r->options, request_id);
if (wait_answer)
r->wait_count++;
_waylend_tbm_monitor_server_show(struct wayland_tbm_monitore_request *r)
{
struct wayland_tbm_monitor_target target = {0};
+ FILE * f = NULL;
+ char show_str[1024*4] = {0,};
+ int len = sizeof(show_str);
if (!_waylend_tbm_util_target_parse(r->argv[1], &target)) {
_wayland_tbm_monitor_request_printf(r, "'%s' - unknown target for -show\n", r->argv[1]);
return;
}
+ if (r->argv[2]) {
+ r->path.console = r->path.dlog = r->path.file[0] = 0;
+ if (!_wayland_tbm_util_show_path_parse(r->argv[2], r->cwd, &r->path)) {
+ r->path.console = 1;
+ _wayland_tbm_monitor_request_printf(r, "'%s' - unknown path for -show\n", r->argv[2]);
+ return;
+ }
+ }
+
if (target.server) {
- tbm_bufmgr_debug_tbm_info_get(r->tbm_srv->bufmgr, r->reply, &r->len);
- tbm_bufmgr_debug_show(r->tbm_srv->bufmgr);
+ tbm_bufmgr_debug_tbm_info_get(r->tbm_srv->bufmgr, show_str, &len);
+
+ if (r->path.console && r->console)
+ fprintf(r->console, "%s", show_str);
+
+ if (r->path.file[0] != '\0') {
+ if ((f = fopen(r->path.file, "a+")) != NULL) {
+ fprintf(f, "%s", show_str);
+ fclose(f);
+ }
+ else
+ _wayland_tbm_monitor_request_printf(r, "server: can't write show to file: '%s'\n",
+ r->path.file);
+ }
+
+ if (r->path.dlog)
+ tbm_bufmgr_debug_show(r->tbm_srv->bufmgr);
}
_send_request_to_client_with_wait(r, &target, 1);
{
"show",
_waylend_tbm_monitor_server_show,
- "shows all tbm_bo information contained by (all | server | client=<pid>)"
+ "print all tbm_bo information for (all | server | client=<pid>) to path (console | dlog | <filepath>)"
,
- " client=<pid> - the client with <pid> (use -list to get pid)\n"
+ "<target> [<path>]\n"
+ "\t\t"" client=<pid> - the client with <pid> (use -list to get pid)\n"
"\t\t"" server - the server\n"
"\t\t"" all - clients and server\n"
,
- "client=<pid>; server; all"
+ "client=<pid> dlog,console; server tmp.txt; all"
},
{
"trace",
struct wl_resource *resource, const char *options)
{
char *end = NULL;
+ char path[256];
int i;
int pid;
static int id_count = 1;
r->len = WL_TBM_MONITOR_REPLY_MSG_LEN;
r->tbm_srv = tbm_srv;
r->id = id_count++;
+ r->path.console = 1;
wl_list_init(&r->link);
/* get pid */
_wayland_tbm_util_get_appname_brief(r->app_name);
/* get access to the console of a wayland-tbm-monitor application */
- char fd_name[32];
- snprintf(fd_name, 32, "/proc/%d/fd/1", pid);
- r->console = fopen(fd_name, "a");
+ snprintf(path, sizeof(path), "/proc/%d/fd/1", pid);
+ r->console = fopen(path, "a");
if (!r->console) {
_wayland_tbm_monitor_request_printf(r, "Can't get access to the console\n");
return r;
}
+ /* get cwd of the client */
+ snprintf(path, sizeof(path), "/proc/%d/cwd", pid);
+ if (readlink(path, r->cwd, sizeof(r->cwd)) < 0) {
+ _wayland_tbm_monitor_request_printf(r, "Can't get cwd\n");
+ return r;
+ }
+
/* parse options */
r->argv[r->argc] = strtok_r(r->arg_mem, " ", &end);
while (r->argv[r->argc]) {
return WL_TBM_MONITOR_PROC_STATE_UNKNOWN;
}
+int
+_wayland_tbm_util_show_path_parse(char * path_str, char * cwd, struct wayland_tbm_monitor_path *path)
+{
+ char *end = path_str;
+ char *p = NULL;
+
+ if (!path_str)
+ return 0;
+
+ /* parse options */
+ while ((p = strtok_r(NULL, ",", &end)) != NULL) {
+ if (!strncmp(p, "dlog", 4))
+ path->dlog = 1;
+ else if (!strncmp(p, "console", 7))
+ path->console = 1;
+ else {
+ if (p[0] == '/')
+ snprintf(path->file, WL_TBM_MONITOR_PATH_LEN, "%s", p);
+ else {
+ if (cwd)
+ snprintf(path->file, WL_TBM_MONITOR_PATH_LEN, "%s/%s", cwd, p);
+ else
+ snprintf(path->file, WL_TBM_MONITOR_PATH_LEN, "%s", p);
+ }
+ }
+ }
+
+ return 1;
+}
+
+
WL_TBM_MONITOR_PROC_STATE
_waylend_tbm_util_trace(WL_TBM_MONITOR_PROC_STATE cmd, tbm_bufmgr bufmgr)
{