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(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
116 _tdm_monitor_server_usage(argv[0], reply, len);
121 output_id = strtol(argv[3], &end, 10);
123 ret = tdm_display_enable_ttrace(dpy, argv[2], output_id, reply, len);
124 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
128 _tdm_monitor_server_debug(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
135 _tdm_monitor_server_usage(argv[0], reply, len);
140 level = strtol(arg, &end, 10);
142 tdm_log_set_debug_level(level);
143 TDM_SNPRINTF(reply, len, "debug level: %d\n", level);
148 tdm_display_enable_debug_module((const char *)arg);
150 TDM_SNPRINTF(reply, len, "debugging... '%s'\n", arg);
155 _tdm_monitor_server_log_path(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
157 static int old_stdout = -1;
158 char fd_name[TDM_PATH_LEN];
162 _tdm_monitor_server_usage(argv[0], reply, len);
166 if (old_stdout == -1)
167 old_stdout = dup(STDOUT_FILENO);
170 TDM_DBG_RETURN_IF_FAIL(path != NULL);
172 tdm_log_enable_dlog(0);
174 if (!strncmp(path, "dlog", 4)) {
175 tdm_log_enable_dlog(1);
177 } else if (!strncmp(path, "console", 7))
178 snprintf(fd_name, TDM_PATH_LEN, "/proc/%d/fd/1", pid);
181 snprintf(fd_name, TDM_PATH_LEN, "%s", path);
184 snprintf(fd_name, TDM_PATH_LEN, "%s/%s", cwd, path);
186 snprintf(fd_name, TDM_PATH_LEN, "%s", path);
188 tdm_log_enable_color(0);
191 if (tdm_display_enable_path((const char*)fd_name) != TDM_ERROR_NONE) {
192 TDM_SNPRINTF(reply, len, "failed: '%s'\n", path);
197 TDM_SNPRINTF(reply, len, "log path: '%s'\n", path);
201 _tdm_monitor_server_commit_per_vblank(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
208 _tdm_monitor_server_usage(argv[0], reply, len);
213 enable = strtol(arg, &end, 10);
215 tdm_display_enable_commit_per_vblank(dpy, enable);
217 TDM_SNPRINTF(reply, len, "%s the commit-per-vblank\n", (enable) ? "enable" : "disable");
221 _tdm_monitor_server_fps(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
228 _tdm_monitor_server_usage(argv[0], reply, len);
233 enable = strtol(arg, &end, 10);
235 tdm_display_enable_fps(dpy, enable);
237 TDM_SNPRINTF(reply, len, "%s to print fps\n", (enable) ? "enable" : "disable");
241 _tdm_monitor_server_vblank_list(unsigned int pid, char *cwd, int argc, char *argv[],
242 char *reply, int *len, tdm_display *dpy)
244 tdm_vblank_get_vblank_list_information(dpy, reply, len);
248 _tdm_monitor_server_vblank_fps(unsigned int pid, char *cwd, int argc, char *argv[],
249 char *reply, int *len, tdm_display *dpy)
251 unsigned int target_pid, fps;
254 char name[TDM_NAME_LEN];
258 _tdm_monitor_server_usage(argv[0], reply, len);
263 target_pid = strtol(arg, &end, 10);
267 end = strtostr(name, TDM_NAME_LEN, arg, TDM_DELIM);
269 strncpy(name, TDM_VBLANK_DEFAULT_NAME, TDM_NAME_LEN - 1);
270 name[TDM_NAME_LEN - 1] = '\0';
274 TDM_SNPRINTF(reply, len, "failed: no fps value\n");
279 fps = strtol(arg, &end, 10);
281 ret = tdm_vblank_set_client_vblank_fps(target_pid, name, fps);
282 if (ret != TDM_ERROR_NONE) {
283 TDM_SNPRINTF(reply, len, "can't set '%u' fps to '%s' client vblank(PID:%u)\n", fps, name, target_pid);
287 TDM_SNPRINTF(reply, len, "success: '%u' fps for '%s' client vblank(PID:%u)\n", fps, name, target_pid);
291 _tdm_monitor_server_global_fps(unsigned int pid, char *cwd, int argc, char *argv[],
292 char *reply, int *len, tdm_display *dpy)
300 _tdm_monitor_server_usage(argv[0], reply, len);
305 fps = strtol(arg, &end, 10);
308 ret = tdm_vblank_enable_global_fps(1, fps);
310 ret = tdm_vblank_enable_global_fps(0, 0);
312 if (ret != TDM_ERROR_NONE) {
313 TDM_SNPRINTF(reply, len, "can't set '%u' fps to global fps\n", fps);
317 TDM_SNPRINTF(reply, len, "success: '%u' global fps\n", fps);
321 _tdm_monitor_server_prop(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
324 tdm_output *layer = NULL;
325 int output_idx, layer_idx = -1;
326 int cnt, i, done = 0;
328 char temp[TDM_PATH_LEN];
333 const tdm_prop *props;
336 _tdm_monitor_server_usage(argv[0], reply, len);
340 snprintf(temp, TDM_PATH_LEN, "%s", argv[2]);
343 output_idx = strtol(arg, &end, 10);
346 layer_idx = strtol(arg, &end, 10);
350 TDM_SNPRINTF(reply, len, "failed: no prop_name\n");
355 prop_name = strtok_r(arg, ",", &end);
357 TDM_SNPRINTF(reply, len, "failed: get prop_name by strtok_r\n");
362 TDM_SNPRINTF(reply, len, "failed: no value\n");
366 arg = strtok_r(NULL, TDM_DELIM, &end);
368 TDM_SNPRINTF(reply, len, "failed: get arg by strtok_r\n");
371 value.u32 = strtol(arg, &end, 10);
373 output = tdm_display_get_output(dpy, output_idx, &ret);
374 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE && output != NULL);
376 if (layer_idx != -1) {
377 layer = tdm_output_get_layer(output, layer_idx, &ret);
378 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE && layer != NULL);
382 ret = tdm_layer_get_available_properties(layer, &props, &cnt);
383 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
385 for (i = 0; i < cnt; i++) {
386 if (!strncmp(props[i].name, prop_name, TDM_NAME_LEN)) {
387 ret = tdm_layer_set_property(layer, props[i].id, value);
388 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
394 ret = tdm_output_get_available_properties(output, &props, &cnt);
395 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
397 for (i = 0; i < cnt; i++) {
398 if (!strncmp(props[i].name, prop_name, TDM_NAME_LEN)) {
399 ret = tdm_output_set_property(output, props[i].id, value);
400 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
408 TDM_SNPRINTF(reply, len, "done: %s:%d \n", prop_name, value.u32);
410 TDM_SNPRINTF(reply, len, "no '%s' propperty \n", prop_name);
414 _tdm_monitor_server_dump(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
417 _tdm_monitor_server_usage(argv[0], reply, len);
421 tdm_display_enable_dump(dpy, (const char*)argv[2], reply, len);
425 _tdm_monitor_server_punch(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
428 unsigned int output_id, layer_id;
431 tbm_surface_h buffer;
435 output_id = strtol(arg, &end, 10);
436 output = tdm_display_get_output(dpy, output_id, NULL);
438 TDM_SNPRINTF(reply, len, "not found output\n");
442 TDM_SNPRINTF(reply, len, "not found ',<layer_idx>'\n");
447 layer_id = strtol(arg, &end, 10);
448 layer = tdm_output_get_layer(output, layer_id, NULL);
450 TDM_SNPRINTF(reply, len, "not found layer\n");
454 buffer = tdm_layer_get_displaying_buffer(layer, NULL);
456 TDM_SNPRINTF(reply, len, "not found buffer\n");
464 pos.w = strtol(arg, &end, 10);
465 TDM_EXIT_IF_FAIL(*end == 'x');
467 pos.h = strtol(arg, &end, 10);
470 pos.x = strtol(arg, &end, 10);
471 TDM_EXIT_IF_FAIL(*end == '+');
473 pos.y = strtol(arg, &end, 10);
476 tdm_helper_clear_buffer_pos(buffer, &pos);
478 tdm_helper_clear_buffer(buffer);
483 void (*func)(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy);
489 "info", _tdm_monitor_server_query,
490 "show tdm output, layer information", NULL, NULL
493 "trace", _tdm_monitor_server_protocol_trace,
494 "enable/disable the wl protocol",
499 "dpms", _tdm_monitor_server_dpms,
500 "set output dpms", "<output_idx>:<dpms>", "0:3 or 0:0"
503 "ttrace", _tdm_monitor_server_ttrace,
504 "enable/disable ttrace (module: none, vblank, client, layer, pp, capture, all",
505 "<module>[@<output_idx>]",
509 "debug", _tdm_monitor_server_debug,
510 "set the debug level and modules(module: none, mutex, buffer, thread, vblank)",
511 "<level>[@<module1>[,<module2>]]",
515 "log_path", _tdm_monitor_server_log_path,
516 "set the log path (console,dlog,filepath)",
521 "commit_per_vblank", _tdm_monitor_server_commit_per_vblank,
522 "enable/disable the commit per vblank",
527 "fps", _tdm_monitor_server_fps,
528 "enable/disable to print fps",
533 "vblank_list", _tdm_monitor_server_vblank_list,
534 "print the client vblank list",
539 "vblank_fps", _tdm_monitor_server_vblank_fps,
540 "set the client vblank fps for the given process ID and client vblank name",
541 "<pid>[,<vblank_name>]@<fps>",
545 "global_fps", _tdm_monitor_server_global_fps,
546 "set the global vblank fps for the entire system",
551 "prop", _tdm_monitor_server_prop,
552 "set the property of a output or a layer",
553 "<output_idx>[,<layer_idx>]:<prop_name>,<value>",
557 "dump", _tdm_monitor_server_dump,
558 "dump buffers (type: none, layer, pp, capture, current)\n"
559 "\t\t layer, pp, capture - start to dump buffers of layer, pp, capture\n"
560 "\t\t none - stop to dump buffers\n"
561 "\t\t current - dump the current buffer of all layers",
562 "<object_type1>[,<object_type2>[,...]][@<directory_path>]",
566 "punch", _tdm_monitor_server_punch,
568 "<output_idx>,<layer_idx>[:<w>x<h>[+<x>+<y>]]",
574 _tdm_monitor_server_usage(char *app_name, char *reply, int *len)
576 int opt_size = sizeof(option_proc) / sizeof(option_proc[0]);
579 TDM_SNPRINTF(reply, len, "usage: %s \n\n", app_name);
581 for (i = 0; i < opt_size; i++) {
582 TDM_SNPRINTF(reply, len, "\t-%s\t%s\n", option_proc[i].opt, option_proc[i].desc);
583 if (option_proc[i].arg)
584 TDM_SNPRINTF(reply, len, "\t\t %s\n", option_proc[i].arg);
585 if (option_proc[i].ex)
586 TDM_SNPRINTF(reply, len, "\t\t ex) %s\n", option_proc[i].ex);
587 TDM_SNPRINTF(reply, len, "\n");
592 _tdm_monitor_server_command(unsigned int pid, char *cwd, tdm_display *dpy, int argc, char *argv[], char *reply, int *len)
594 int opt_size = sizeof(option_proc) / sizeof(option_proc[0]);
598 _tdm_monitor_server_usage(argv[0], reply, len);
602 for (i = 0; i < opt_size; i++) {
603 if (argv[1][0] == '-' && !strncmp(argv[1] + 1, option_proc[i].opt, 32)) {
604 if (option_proc[i].func) {
605 option_proc[i].func(pid, cwd, argc, argv, reply, len, dpy);
608 TDM_SNPRINTF(reply, len, "'%s' not implemented.\n", argv[1]);
614 _tdm_monitor_server_usage(argv[0], reply, len);
620 tdm_monitor_server_command(tdm_display *dpy, const char *options, char *reply, int *len)
625 char *argv[TDM_DBG_SERVER_ARGS_MAX] = {0,};
628 char *end = NULL, *e;
630 snprintf(temp, sizeof(temp), "%s", options);
632 arg = strtok_r(temp, " ", &end);
634 TDM_SNPRINTF(reply, len, "no pid for tdm-monitor");
637 pid = strtol(arg, &e, 10);
639 arg = strtok_r(NULL, " ", &end);
641 TDM_SNPRINTF(reply, len, "no cwd for tdm-monitor");
644 snprintf(cwd, sizeof(cwd), "%s", arg);
646 TDM_DBG("pid(%d) cwd(%s)", pid, cwd);
648 argv[argc] = strtok_r(NULL, " ", &end);
651 if (argc == TDM_DBG_SERVER_ARGS_MAX) {
652 TDM_SNPRINTF(reply, len, "too many arguments for tdm-monitor");
655 argv[argc] = strtok_r(NULL, " ", &end);
658 _tdm_monitor_server_command(pid, cwd, dpy, argc, argv, reply, len);