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_display_lock(dpy);
54 tdm_helper_get_display_information(dpy, reply, len);
55 tdm_display_unlock(dpy);
59 _tdm_monitor_server_protocol_trace(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
64 _tdm_monitor_server_usage(argv[0], reply, len);
68 enable = atoi(argv[2]);
70 tdm_event_loop_trace_enable(dpy, enable);
72 TDM_SNPRINTF(reply, len, "protocol trace: '%s'\n", (enable) ? "enabled" : "disabled");
76 _tdm_monitor_server_dpms(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
79 int output_idx, dpms_value;
85 _tdm_monitor_server_usage(argv[0], reply, len);
90 output_idx = strtol(arg, &end, 10);
92 TDM_SNPRINTF(reply, len, "failed: no onoff value\n");
97 dpms_value = strtol(arg, &end, 10);
99 output = tdm_display_get_output(dpy, output_idx, &ret);
100 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE && output != NULL);
102 ret = tdm_output_set_dpms(output, dpms_value);
103 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
105 TDM_SNPRINTF(reply, len, "done: DPMS %s\n", tdm_dpms_str(dpms_value));
109 _tdm_monitor_server_ttrace_vblank(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
111 int ttrace_vblank, output_id = 0;
116 _tdm_monitor_server_usage(argv[0], reply, len);
121 ttrace_vblank = strtol(arg, &end, 10);
123 if (ttrace_vblank > 0) {
126 tdm_output_type type;
131 output_id = strtol(arg, &end, 10);
134 output = tdm_display_get_output(dpy, output_id, NULL);
136 TDM_SNPRINTF(reply, len, "can't find the output_id(%d)\n", output_id);
140 ret = tdm_output_get_output_type(output, &type);
141 if (ret != TDM_ERROR_NONE) {
142 TDM_SNPRINTF(reply, len, "can't find the type of output_id(%d)\n", output_id);
147 tdm_display_enable_ttrace_vblank(dpy, output, 1);
149 if (ttrace_vblank > 1) {
151 tdm_server_enable_ttrace_vblank(dpy, output, 1);
154 TDM_SNPRINTF(reply, len, "enable ttrace vblank for '%s': %s \n", tdm_conn_str(type), temp);
156 tdm_display_enable_ttrace_vblank(dpy, NULL, 0);
157 tdm_server_enable_ttrace_vblank(dpy, NULL, 0);
158 TDM_SNPRINTF(reply, len, "disable ttrace vblank\n");
163 _tdm_monitor_server_debug(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
170 _tdm_monitor_server_usage(argv[0], reply, len);
175 level = strtol(arg, &end, 10);
177 tdm_log_set_debug_level(level);
178 TDM_SNPRINTF(reply, len, "debug level: %d\n", level);
183 tdm_display_enable_debug_module((const char *)arg);
185 TDM_SNPRINTF(reply, len, "debugging... '%s'\n", arg);
190 _tdm_monitor_server_log_path(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
192 static int old_stdout = -1;
193 char fd_name[TDM_PATH_LEN];
197 _tdm_monitor_server_usage(argv[0], reply, len);
201 if (old_stdout == -1)
202 old_stdout = dup(STDOUT_FILENO);
205 TDM_DBG_RETURN_IF_FAIL(path != NULL);
207 tdm_log_enable_dlog(0);
209 if (!strncmp(path, "dlog", 4)) {
210 tdm_log_enable_dlog(1);
212 } else if (!strncmp(path, "console", 7))
213 snprintf(fd_name, TDM_PATH_LEN, "/proc/%d/fd/1", pid);
216 snprintf(fd_name, TDM_PATH_LEN, "%s", path);
219 snprintf(fd_name, TDM_PATH_LEN, "%s/%s", cwd, path);
221 snprintf(fd_name, TDM_PATH_LEN, "%s", path);
223 tdm_log_enable_color(0);
226 if (tdm_display_enable_path((const char*)fd_name) != TDM_ERROR_NONE) {
227 TDM_SNPRINTF(reply, len, "failed: '%s'\n", path);
232 TDM_SNPRINTF(reply, len, "log path: '%s'\n", path);
236 _tdm_monitor_server_choose_commit_per_vblank_mode(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
244 /* TODO: do we have to provide an ability to choose commit_per_vblank mode outside? */
247 _tdm_monitor_server_usage(argv[0], reply, len);
252 output_idx = strtol(arg, &end, 10);
255 mode = strtol(arg, &end, 10);
257 err = tdm_output_choose_commit_per_vblank_mode(tdm_display_get_output(dpy, output_idx, NULL), mode);
258 if (err != TDM_ERROR_NONE) {
259 TDM_SNPRINTF(reply, len, "an error: output_idx or mode is wrong\n");
263 TDM_SNPRINTF(reply, len, "the mode's been set\n");
267 _tdm_monitor_server_fps(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
274 _tdm_monitor_server_usage(argv[0], reply, len);
279 enable = strtol(arg, &end, 10);
281 tdm_display_enable_fps(dpy, enable);
283 TDM_SNPRINTF(reply, len, "%s to print fps\n", (enable) ? "enable" : "disable");
287 _tdm_monitor_server_vblank_list(unsigned int pid, char *cwd, int argc, char *argv[],
288 char *reply, int *len, tdm_display *dpy)
290 tdm_vblank_get_vblank_list_information(dpy, reply, len);
294 _tdm_monitor_server_vblank_fps(unsigned int pid, char *cwd, int argc, char *argv[],
295 char *reply, int *len, tdm_display *dpy)
297 unsigned int target_pid, fps;
300 char name[TDM_NAME_LEN];
304 _tdm_monitor_server_usage(argv[0], reply, len);
309 target_pid = strtol(arg, &end, 10);
313 end = strtostr(name, TDM_NAME_LEN, arg, TDM_DELIM);
315 strncpy(name, TDM_VBLANK_DEFAULT_NAME, TDM_NAME_LEN - 1);
316 name[TDM_NAME_LEN - 1] = '\0';
320 TDM_SNPRINTF(reply, len, "failed: no fps value\n");
325 fps = strtol(arg, &end, 10);
327 ret = tdm_vblank_set_client_vblank_fps(target_pid, name, fps);
328 if (ret != TDM_ERROR_NONE) {
329 TDM_SNPRINTF(reply, len, "can't set '%u' fps to '%s' client vblank(PID:%u)\n", fps, name, target_pid);
333 TDM_SNPRINTF(reply, len, "success: '%u' fps for '%s' client vblank(PID:%u)\n", fps, name, target_pid);
337 _tdm_monitor_server_global_fps(unsigned int pid, char *cwd, int argc, char *argv[],
338 char *reply, int *len, tdm_display *dpy)
346 _tdm_monitor_server_usage(argv[0], reply, len);
351 fps = strtol(arg, &end, 10);
354 ret = tdm_vblank_enable_global_fps(1, fps);
356 ret = tdm_vblank_enable_global_fps(0, 0);
358 if (ret != TDM_ERROR_NONE) {
359 TDM_SNPRINTF(reply, len, "can't set '%u' fps to global fps\n", fps);
363 TDM_SNPRINTF(reply, len, "success: '%u' global fps\n", fps);
367 _tdm_monitor_server_prop(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
370 tdm_output *layer = NULL;
371 int output_idx, layer_idx = -1;
372 int cnt, i, done = 0;
374 char temp[TDM_PATH_LEN];
379 const tdm_prop *props;
382 _tdm_monitor_server_usage(argv[0], reply, len);
386 snprintf(temp, TDM_PATH_LEN, "%s", argv[2]);
389 output_idx = strtol(arg, &end, 10);
392 layer_idx = strtol(arg, &end, 10);
396 TDM_SNPRINTF(reply, len, "failed: no prop_name\n");
401 prop_name = strtok_r(arg, ",", &end);
403 TDM_SNPRINTF(reply, len, "failed: get prop_name by strtok_r\n");
408 TDM_SNPRINTF(reply, len, "failed: no value\n");
412 arg = strtok_r(NULL, TDM_DELIM, &end);
414 TDM_SNPRINTF(reply, len, "failed: get arg by strtok_r\n");
417 value.u32 = strtol(arg, &end, 10);
419 output = tdm_display_get_output(dpy, output_idx, &ret);
420 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE && output != NULL);
422 if (layer_idx != -1) {
423 layer = tdm_output_get_layer(output, layer_idx, &ret);
424 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE && layer != NULL);
428 ret = tdm_layer_get_available_properties(layer, &props, &cnt);
429 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
431 for (i = 0; i < cnt; i++) {
432 if (!strncmp(props[i].name, prop_name, TDM_NAME_LEN)) {
433 ret = tdm_layer_set_property(layer, props[i].id, value);
434 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
440 ret = tdm_output_get_available_properties(output, &props, &cnt);
441 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
443 for (i = 0; i < cnt; i++) {
444 if (!strncmp(props[i].name, prop_name, TDM_NAME_LEN)) {
445 ret = tdm_output_set_property(output, props[i].id, value);
446 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
454 TDM_SNPRINTF(reply, len, "done: %s:%d \n", prop_name, value.u32);
456 TDM_SNPRINTF(reply, len, "no '%s' propperty \n", prop_name);
460 _tdm_monitor_server_dump(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
463 _tdm_monitor_server_usage(argv[0], reply, len);
467 tdm_display_enable_dump(dpy, (const char*)argv[2], reply, len);
471 _tdm_monitor_server_punch(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
474 unsigned int output_id, layer_id;
477 tbm_surface_h buffer;
481 output_id = strtol(arg, &end, 10);
482 output = tdm_display_get_output(dpy, output_id, NULL);
484 TDM_SNPRINTF(reply, len, "not found output\n");
488 TDM_SNPRINTF(reply, len, "not found ',<layer_idx>'\n");
493 layer_id = strtol(arg, &end, 10);
494 layer = tdm_output_get_layer(output, layer_id, NULL);
496 TDM_SNPRINTF(reply, len, "not found layer\n");
500 buffer = tdm_layer_get_displaying_buffer(layer, NULL);
502 TDM_SNPRINTF(reply, len, "not found buffer\n");
510 pos.w = strtol(arg, &end, 10);
511 TDM_EXIT_IF_FAIL(*end == 'x');
513 pos.h = strtol(arg, &end, 10);
516 pos.x = strtol(arg, &end, 10);
517 TDM_EXIT_IF_FAIL(*end == '+');
519 pos.y = strtol(arg, &end, 10);
522 tdm_helper_clear_buffer_pos(buffer, &pos);
524 tdm_helper_clear_buffer(buffer);
529 void (*func)(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy);
535 "info", _tdm_monitor_server_query,
536 "show tdm output, layer information", NULL, NULL
539 "trace", _tdm_monitor_server_protocol_trace,
540 "enable/disable the wl protocol",
545 "dpms", _tdm_monitor_server_dpms,
546 "set output dpms", "<output_idx>:<dpms>", "0:3 or 0:0"
549 "ttrace_vblank", _tdm_monitor_server_ttrace_vblank,
550 "enable/disable the vblank for ttrace [0:disable, 1:server, 2:clients]",
551 "<enable>[@<output_idx>]", "0 or 1 or 2 or 1@0 or 2@0 or 1@1 or 2@1"
554 "debug", _tdm_monitor_server_debug,
555 "set the debug level and modules(module: none, mutex, buffer, thread, vblank)",
556 "<level>[@<module1>[,<module2>]]",
560 "log_path", _tdm_monitor_server_log_path,
561 "set the log path (console,dlog,filepath)",
566 "choose_commit_per_vblank_mode", _tdm_monitor_server_choose_commit_per_vblank_mode,
567 "choose a commit_per_vblank mode for the output",
568 "<output_idx> <mode>",
572 "fps", _tdm_monitor_server_fps,
573 "enable/disable to print fps",
578 "vblank_list", _tdm_monitor_server_vblank_list,
579 "print the client vblank list",
584 "vblank_fps", _tdm_monitor_server_vblank_fps,
585 "set the client vblank fps for the given process ID and client vblank name",
586 "<pid>[,<vblank_name>]@<fps>",
590 "global_fps", _tdm_monitor_server_global_fps,
591 "set the global vblank fps for the entire system",
596 "prop", _tdm_monitor_server_prop,
597 "set the property of a output or a layer",
598 "<output_idx>[,<layer_idx>]:<prop_name>,<value>",
602 "dump", _tdm_monitor_server_dump,
603 "dump buffers (type: none, layer, pp, capture, current)\n"
604 "\t\t layer, pp, capture - start to dump buffers of layer, pp, capture\n"
605 "\t\t none - stop to dump buffers\n"
606 "\t\t current - dump the current buffer of all layers",
607 "<object_type1>[,<object_type2>[,...]][@<directory_path>]",
611 "punch", _tdm_monitor_server_punch,
613 "<output_idx>,<layer_idx>[:<w>x<h>[+<x>+<y>]]",
619 _tdm_monitor_server_usage(char *app_name, char *reply, int *len)
621 int opt_size = sizeof(option_proc) / sizeof(option_proc[0]);
624 TDM_SNPRINTF(reply, len, "usage: %s \n\n", app_name);
626 for (i = 0; i < opt_size; i++) {
627 TDM_SNPRINTF(reply, len, "\t-%s\t%s\n", option_proc[i].opt, option_proc[i].desc);
628 if (option_proc[i].arg)
629 TDM_SNPRINTF(reply, len, "\t\t %s\n", option_proc[i].arg);
630 if (option_proc[i].ex)
631 TDM_SNPRINTF(reply, len, "\t\t ex) %s\n", option_proc[i].ex);
632 TDM_SNPRINTF(reply, len, "\n");
637 _tdm_monitor_server_command(unsigned int pid, char *cwd, tdm_display *dpy, int argc, char *argv[], char *reply, int *len)
639 int opt_size = sizeof(option_proc) / sizeof(option_proc[0]);
643 _tdm_monitor_server_usage(argv[0], reply, len);
647 for (i = 0; i < opt_size; i++) {
648 if (argv[1][0] == '-' && !strncmp(argv[1] + 1, option_proc[i].opt, 32)) {
649 if (option_proc[i].func) {
650 option_proc[i].func(pid, cwd, argc, argv, reply, len, dpy);
653 TDM_SNPRINTF(reply, len, "'%s' not implemented.\n", argv[1]);
659 _tdm_monitor_server_usage(argv[0], reply, len);
665 tdm_monitor_server_command(tdm_display *dpy, const char *options, char *reply, int *len)
670 char *argv[TDM_DBG_SERVER_ARGS_MAX] = {0,};
673 char *end = NULL, *e;
675 snprintf(temp, sizeof(temp), "%s", options);
677 arg = strtok_r(temp, " ", &end);
679 TDM_SNPRINTF(reply, len, "no pid for tdm-monitor");
682 pid = strtol(arg, &e, 10);
684 arg = strtok_r(NULL, " ", &end);
686 TDM_SNPRINTF(reply, len, "no cwd for tdm-monitor");
689 snprintf(cwd, sizeof(cwd), "%s", arg);
691 TDM_DBG("pid(%d) cwd(%s)", pid, cwd);
693 argv[argc] = strtok_r(NULL, " ", &end);
696 if (argc == TDM_DBG_SERVER_ARGS_MAX) {
697 TDM_SNPRINTF(reply, len, "too many arguments for tdm-monitor");
700 argv[argc] = strtok_r(NULL, " ", &end);
703 _tdm_monitor_server_command(pid, cwd, dpy, argc, argv, reply, len);