1 /**************************************************************************
5 * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8 * JinYoung Jeon <jy0.jeon@samsung.com>,
9 * Taeheon Kim <th908.kim@samsung.com>,
10 * YoungJun Cho <yj44.cho@samsung.com>,
11 * SooChan Lim <sc1.lim@samsung.com>,
12 * Boram Park <sc1.lim@samsung.com>
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sub license, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 **************************************************************************/
42 #include "tdm_private.h"
43 #include "tdm_helper.h"
46 #define TDM_DBG_SERVER_ARGS_MAX 32
48 static void _tdm_monitor_server_usage(char *app_name, char *reply, int *len);
51 _tdm_monitor_server_query(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
53 tdm_helper_get_display_information(dpy, reply, len);
57 _tdm_monitor_server_dpms(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
60 int output_idx, dpms_value;
66 _tdm_monitor_server_usage(argv[0], reply, len);
71 output_idx = strtol(arg, &end, 10);
73 TDM_SNPRINTF(reply, len, "failed: no onoff value\n");
78 dpms_value = strtol(arg, &end, 10);
80 output = tdm_display_get_output(dpy, output_idx, &ret);
81 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE && output != NULL);
83 ret = tdm_output_set_dpms(output, dpms_value);
84 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
86 TDM_SNPRINTF(reply, len, "done: DPMS %s\n", tdm_dpms_str(dpms_value));
90 _tdm_monitor_server_ttrace_vblank(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
92 int enable, output_id = 0;
100 _tdm_monitor_server_usage(argv[0], reply, len);
105 enable = strtol(arg, &end, 10);
109 output_id = strtol(arg, &end, 10);
112 output = tdm_display_get_output(dpy, output_id, NULL);
114 TDM_SNPRINTF(reply, len, "can't find the output_id(%d)\n", output_id);
118 ret = tdm_output_get_output_type(output, &type);
119 if (ret != TDM_ERROR_NONE) {
120 TDM_SNPRINTF(reply, len, "can't find the type of output_id(%d)\n", output_id);
124 tdm_display_enable_ttrace_vblank(dpy, output, enable);
126 TDM_SNPRINTF(reply, len, "%s ttrace vblank for '%s'\n",
127 (enable) ? "enable" : "disable", tdm_conn_str(type));
131 _tdm_monitor_server_debug(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
138 _tdm_monitor_server_usage(argv[0], reply, len);
143 level = strtol(arg, &end, 10);
145 tdm_log_set_debug_level(level);
146 TDM_SNPRINTF(reply, len, "debug level: %d\n", level);
151 tdm_display_enable_debug_module((const char *)arg);
153 TDM_SNPRINTF(reply, len, "debugging... '%s'\n", arg);
158 _tdm_monitor_server_log_path(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
160 static int old_stdout = -1;
161 char fd_name[TDM_PATH_LEN];
165 _tdm_monitor_server_usage(argv[0], reply, len);
169 if (old_stdout == -1)
170 old_stdout = dup(STDOUT_FILENO);
173 TDM_DBG_RETURN_IF_FAIL(path != NULL);
175 tdm_log_enable_dlog(0);
177 if (!strncmp(path, "dlog", 4)) {
178 tdm_log_enable_dlog(1);
180 } else if (!strncmp(path, "console", 7))
181 snprintf(fd_name, TDM_PATH_LEN, "/proc/%d/fd/1", pid);
184 snprintf(fd_name, TDM_PATH_LEN, "%s", path);
187 snprintf(fd_name, TDM_PATH_LEN, "%s/%s", cwd, path);
189 snprintf(fd_name, TDM_PATH_LEN, "%s", path);
191 tdm_log_enable_color(0);
194 if (tdm_display_enable_path((const char*)fd_name) != TDM_ERROR_NONE) {
195 TDM_SNPRINTF(reply, len, "failed: '%s'\n", path);
200 TDM_SNPRINTF(reply, len, "log path: '%s'\n", path);
204 _tdm_monitor_server_commit_per_vblank(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
211 _tdm_monitor_server_usage(argv[0], reply, len);
216 enable = strtol(arg, &end, 10);
218 tdm_display_enable_commit_per_vblank(dpy, enable);
220 TDM_SNPRINTF(reply, len, "%s the commit-per-vblank\n", (enable) ? "enable" : "disable");
224 _tdm_monitor_server_fps(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
231 _tdm_monitor_server_usage(argv[0], reply, len);
236 enable = strtol(arg, &end, 10);
238 tdm_display_enable_fps(dpy, enable);
240 TDM_SNPRINTF(reply, len, "%s to print fps\n", (enable) ? "enable" : "disable");
244 _tdm_monitor_server_vblank_list(unsigned int pid, char *cwd, int argc, char *argv[],
245 char *reply, int *len, tdm_display *dpy)
247 tdm_vblank_get_vblank_list_information(dpy, reply, len);
251 _tdm_monitor_server_vblank_fps(unsigned int pid, char *cwd, int argc, char *argv[],
252 char *reply, int *len, tdm_display *dpy)
254 unsigned int target_pid, fps;
257 char name[TDM_NAME_LEN];
261 _tdm_monitor_server_usage(argv[0], reply, len);
266 target_pid = strtol(arg, &end, 10);
270 end = strtostr(name, TDM_NAME_LEN, arg, TDM_DELIM);
272 strncpy(name, TDM_VBLANK_DEFAULT_NAME, TDM_NAME_LEN - 1);
273 name[TDM_NAME_LEN - 1] = '\0';
277 TDM_SNPRINTF(reply, len, "failed: no fps value\n");
282 fps = strtol(arg, &end, 10);
284 ret = tdm_vblank_set_client_vblank_fps(target_pid, name, fps);
285 if (ret != TDM_ERROR_NONE) {
286 TDM_SNPRINTF(reply, len, "can't set '%u' fps to '%s' client vblank(PID:%u)\n", fps, name, target_pid);
290 TDM_SNPRINTF(reply, len, "success: '%u' fps for '%s' client vblank(PID:%u)\n", fps, name, target_pid);
294 _tdm_monitor_server_prop(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
297 tdm_output *layer = NULL;
298 int output_idx, layer_idx = -1;
299 int cnt, i, done = 0;
301 char temp[TDM_PATH_LEN];
306 const tdm_prop *props;
309 _tdm_monitor_server_usage(argv[0], reply, len);
313 snprintf(temp, TDM_PATH_LEN, "%s", argv[2]);
316 output_idx = strtol(arg, &end, 10);
319 layer_idx = strtol(arg, &end, 10);
323 TDM_SNPRINTF(reply, len, "failed: no prop_name\n");
328 prop_name = strtok_r(arg, ",", &end);
330 TDM_SNPRINTF(reply, len, "failed: get prop_name by strtok_r\n");
335 TDM_SNPRINTF(reply, len, "failed: no value\n");
339 arg = strtok_r(NULL, TDM_DELIM, &end);
341 TDM_SNPRINTF(reply, len, "failed: get arg by strtok_r\n");
344 value.u32 = strtol(arg, &end, 10);
346 output = tdm_display_get_output(dpy, output_idx, &ret);
347 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE && output != NULL);
349 if (layer_idx != -1) {
350 layer = tdm_output_get_layer(output, layer_idx, &ret);
351 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE && layer != NULL);
355 ret = tdm_layer_get_available_properties(layer, &props, &cnt);
356 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
358 for (i = 0; i < cnt; i++) {
359 if (!strncmp(props[i].name, prop_name, TDM_NAME_LEN)) {
360 ret = tdm_layer_set_property(layer, props[i].id, value);
361 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
367 ret = tdm_output_get_available_properties(output, &props, &cnt);
368 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
370 for (i = 0; i < cnt; i++) {
371 if (!strncmp(props[i].name, prop_name, TDM_NAME_LEN)) {
372 ret = tdm_output_set_property(output, props[i].id, value);
373 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
381 TDM_SNPRINTF(reply, len, "done: %s:%d \n", prop_name, value.u32);
383 TDM_SNPRINTF(reply, len, "no '%s' propperty \n", prop_name);
387 _tdm_monitor_server_dump(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
390 _tdm_monitor_server_usage(argv[0], reply, len);
394 tdm_display_enable_dump(dpy, (const char*)argv[2], reply, len);
398 _tdm_monitor_server_punch(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
401 unsigned int output_id, layer_id;
404 tbm_surface_h buffer;
408 output_id = strtol(arg, &end, 10);
409 output = tdm_display_get_output(dpy, output_id, NULL);
411 TDM_SNPRINTF(reply, len, "not found output\n");
415 TDM_SNPRINTF(reply, len, "not found ',<layer_idx>'\n");
420 layer_id = strtol(arg, &end, 10);
421 layer = tdm_output_get_layer(output, layer_id, NULL);
423 TDM_SNPRINTF(reply, len, "not found layer\n");
427 buffer = tdm_layer_get_displaying_buffer(layer, NULL);
429 TDM_SNPRINTF(reply, len, "not found buffer\n");
437 pos.w = strtol(arg, &end, 10);
438 TDM_EXIT_IF_FAIL(*end == 'x');
440 pos.h = strtol(arg, &end, 10);
443 pos.x = strtol(arg, &end, 10);
444 TDM_EXIT_IF_FAIL(*end == '+');
446 pos.y = strtol(arg, &end, 10);
449 tdm_helper_clear_buffer_pos(buffer, &pos);
451 tdm_helper_clear_buffer(buffer);
456 void (*func)(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy);
462 "info", _tdm_monitor_server_query,
463 "show tdm output, layer information", NULL, NULL
466 "dpms", _tdm_monitor_server_dpms,
467 "set output dpms", "<output_idx>:<dpms>", "0:3 or 0:0"
470 "ttrace_vblank", _tdm_monitor_server_ttrace_vblank,
471 "enable/disable the vblank for ttrace [0:disable 1:enable]",
472 "<enable>[@<output_idx>]", "0 or 1"
475 "debug", _tdm_monitor_server_debug,
476 "set the debug level and modules(module: none, mutex, buffer, thread, vblank)",
477 "<level>[@<module1>[,<module2>]]",
481 "log_path", _tdm_monitor_server_log_path,
482 "set the log path (console,dlog,filepath)",
487 "commit_per_vblank", _tdm_monitor_server_commit_per_vblank,
488 "enable/disable the commit per vblank",
493 "fps", _tdm_monitor_server_fps,
494 "enable/disable to print fps",
499 "vblank_list", _tdm_monitor_server_vblank_list,
500 "print the client vblank list",
505 "vblank_fps", _tdm_monitor_server_vblank_fps,
506 "set the client vblank fps for the given process ID and client vblank name",
507 "<pid>[,<vblank_name>]@<fps>",
511 "prop", _tdm_monitor_server_prop,
512 "set the property of a output or a layer",
513 "<output_idx>[,<layer_idx>]:<prop_name>,<value>",
517 "dump", _tdm_monitor_server_dump,
518 "dump buffers (type: none, layer, pp, capture, current)\n"
519 "\t\t layer, pp, capture - start to dump buffers of layer, pp, capture\n"
520 "\t\t none - stop to dump buffers\n"
521 "\t\t current - dump the current buffer of all layers",
522 "<object_type1>[,<object_type2>[,...]][@<directory_path>]",
526 "punch", _tdm_monitor_server_punch,
528 "<output_idx>,<layer_idx>[:<w>x<h>[+<x>+<y>]]",
534 _tdm_monitor_server_usage(char *app_name, char *reply, int *len)
536 int opt_size = sizeof(option_proc) / sizeof(option_proc[0]);
539 TDM_SNPRINTF(reply, len, "usage: %s \n\n", app_name);
541 for (i = 0; i < opt_size; i++) {
542 TDM_SNPRINTF(reply, len, "\t-%s\t%s\n", option_proc[i].opt, option_proc[i].desc);
543 if (option_proc[i].arg)
544 TDM_SNPRINTF(reply, len, "\t\t %s\n", option_proc[i].arg);
545 if (option_proc[i].ex)
546 TDM_SNPRINTF(reply, len, "\t\t ex) %s\n", option_proc[i].ex);
547 TDM_SNPRINTF(reply, len, "\n");
552 _tdm_monitor_server_command(unsigned int pid, char *cwd, tdm_display *dpy, int argc, char *argv[], char *reply, int *len)
554 int opt_size = sizeof(option_proc) / sizeof(option_proc[0]);
558 _tdm_monitor_server_usage(argv[0], reply, len);
562 for (i = 0; i < opt_size; i++) {
563 if (argv[1][0] == '-' && !strncmp(argv[1] + 1, option_proc[i].opt, 32)) {
564 if (option_proc[i].func) {
565 option_proc[i].func(pid, cwd, argc, argv, reply, len, dpy);
568 TDM_SNPRINTF(reply, len, "'%s' not implemented.\n", argv[1]);
574 _tdm_monitor_server_usage(argv[0], reply, len);
580 tdm_monitor_server_command(tdm_display *dpy, const char *options, char *reply, int *len)
585 char *argv[TDM_DBG_SERVER_ARGS_MAX] = {0,};
588 char *end = NULL, *e;
590 snprintf(temp, sizeof(temp), "%s", options);
592 arg = strtok_r(temp, " ", &end);
594 TDM_SNPRINTF(reply, len, "no pid for tdm-monitor");
597 pid = strtol(arg, &e, 10);
599 arg = strtok_r(NULL, " ", &end);
601 TDM_SNPRINTF(reply, len, "no cwd for tdm-monitor");
604 snprintf(cwd, sizeof(cwd), "%s", arg);
606 TDM_DBG("pid(%d) cwd(%s)", pid, cwd);
608 argv[argc] = strtok_r(NULL, " ", &end);
611 if (argc == TDM_DBG_SERVER_ARGS_MAX) {
612 TDM_SNPRINTF(reply, len, "too many arguments for tdm-monitor");
615 argv[argc] = strtok_r(NULL, " ", &end);
618 _tdm_monitor_server_command(pid, cwd, dpy, argc, argv, reply, len);