show the dump path on the console.
[platform/core/uifw/wayland-tbm.git] / src / wayland-tbm-int.h
1 /*
2 Copyright (C) 2015 Samsung Electronics co., Ltd. All Rights Reserved.
3
4 Contact:
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>
9
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:
16
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
19 Software.
20
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.
28 */
29
30 #ifndef WAYLAND_TBM_INT_H
31 #define WAYLAND_TBM_INT_H
32
33 #ifdef  __cplusplus
34 extern "C" {
35 #endif
36
37 #include <tbm_bufmgr.h>
38 #include <wayland-util.h>
39
40 #define HAVE_DLOG
41 #ifdef HAVE_DLOG
42 #include <dlog.h>
43
44 extern int bDlog;
45 extern int bTrace;
46
47 #ifdef LOG_TAG
48 #undef LOG_TAG
49 #endif
50
51 #define LOG_TAG "WL_TBM"
52
53 #define WL_TBM_C_LOG(fmt, ...) {\
54         if (bDlog) {\
55                 LOGE(fmt, ##__VA_ARGS__);\
56         } \
57         else {\
58                 fprintf(stderr, "[WL_TBM_C(%d):%s] " fmt"\n", getpid(), __func__, ##__VA_ARGS__);\
59         } \
60 }
61 #define WL_TBM_S_LOG(fmt, ...) {\
62         if (bDlog) {\
63                 LOGI(fmt, ##__VA_ARGS__);\
64         } \
65         else{\
66                 fprintf(stderr, "[WL_TBM_S(%d):%s] " fmt"\n", getpid(), __func__, ##__VA_ARGS__);\
67         } \
68 }
69 #define WL_TBM_LOG(fmt, ...) {\
70         if (bDlog) {\
71                 LOGI(fmt, ##__VA_ARGS__);\
72         } \
73         else {\
74                 fprintf(stderr, "[WL_TBM(%d)] " fmt"\n", getpid(), ##__VA_ARGS__);\
75         } \
76 }
77
78 /* temp log */
79 #define WL_TBM_LOG_E(fmt, ...) {\
80         if (bDlog) {\
81                 LOGE(fmt, ##__VA_ARGS__);\
82         } \
83         else {\
84                 fprintf(stderr, "[WL_TBM(%d)] " fmt"\n", getpid(), ##__VA_ARGS__);\
85         } \
86 }
87
88 #else
89 #define WL_TBM_C_LOG(fmt, ...)   fprintf(stderr, "[WL_TBM_C(%d):%s] " fmt"\n", getpid(), __func__, ##__VA_ARGS__)
90 #define WL_TBM_S_LOG(fmt, ...)   fprintf(stderr, "[WL_TBM_S(%d):%s] " fmt"\n", getpid(), __func__, ##__VA_ARGS__)
91 #define WL_TBM_LOG(fmt, ...)     fprintf(stderr, "[WL_TBM(%d)] " fmt"\n", getpid(), ##__VA_ARGS__)
92 #define WL_TBM_LOG_E(fmt, ...)   fprintf(stderr, "[WL_TBM_E(%d)] " fmt"\n", getpid(), ##__VA_ARGS__)
93 #endif /* ENABLE_DLOG */
94
95
96 /* check condition */
97 #define WL_TBM_RETURN_IF_FAIL(cond) {\
98         if (!(cond)) {\
99                 WL_TBM_LOG("'%s' failed.", #cond);\
100                 return;\
101         } \
102 }
103 #define WL_TBM_RETURN_VAL_IF_FAIL(cond, val) {\
104         if (!(cond)) {\
105                 WL_TBM_LOG("'%s' failed.", #cond);\
106                 return val;\
107         } \
108 }
109 #define WL_TBM_GOTO_IF_FAIL(cond, dst) {\
110         if (!(cond)) {\
111                 WL_TBM_LOG("'%s' failed.", #cond);\
112                 goto dst;\
113         } \
114 }
115
116 #define WL_TBM_ARRAY_NTH_DATA(array, type, n) (((type*)((array)->data)) + n)
117
118 typedef enum {
119         WL_TBM_MONITOR_PROC_STATE_OFF,
120         WL_TBM_MONITOR_PROC_STATE_ON,
121         WL_TBM_MONITOR_PROC_STATE_STATUS,
122         WL_TBM_MONITOR_PROC_STATE_UNKNOWN,
123 } WL_TBM_MONITOR_PROC_STATE;
124
125 #define WL_TBM_MONITOR_REPLY_MSG_LEN    8192
126 #define WL_TBM_MONITOR_ARGS_MAX                 12
127 #define WL_TBM_MONITOR_PATH_LEN                 256
128
129 #define WL_TBM_MONITOR_SNPRINTF(p, len, fmt, ARG...)  \
130         do { \
131                 if (p && (len) > 0) { \
132                         int s = snprintf(p, (len), fmt, ##ARG); \
133                         if (s > len) \
134                                 s = len; \
135                         if (s < 0) \
136                                 s = 0; \
137                         p += s; \
138                         (len) -= s; \
139                 } \
140         } while (0)
141
142 struct wayland_tbm_server {
143         struct wl_display *display;
144         struct wl_global *wl_tbm_global;
145         struct wl_global *wl_tbm_monitor_global;
146
147         tbm_bufmgr bufmgr;
148
149         struct wl_list cqueue_list; /* for scanout buffer */
150         struct wl_list tbm_monitor_list; /* for tbm monitor */
151         struct wl_list tbm_monitor_request_list; /* for tbm monitor */
152
153         char *path;
154         int queue_dump;
155 };
156
157 struct wayland_tbm_monitor_target {
158         int server;
159         int all;
160         int pid[256];
161 };
162
163 struct wayland_tbm_monitor_path {
164         int console;
165         int dlog;
166         char file[WL_TBM_MONITOR_PATH_LEN];
167 };
168
169 /* internal functions */
170 void
171 _wayland_tbm_util_get_appname_brief(char *brief);
172
173 void
174 _wayland_tbm_util_get_appname_from_pid(long pid, char *str);
175
176 void
177 _wayland_tbm_check_dlog_enable(void);
178
179 int
180 _waylend_tbm_util_target_parse(char * target_str, struct wayland_tbm_monitor_target *target);
181
182 int
183 _waylend_tbm_util_scale_parse(char * scale_str, double *scale);
184
185 int
186 _wayland_tbm_util_show_path_parse(char * path_str, char * cwd, struct wayland_tbm_monitor_path *path);
187
188 WL_TBM_MONITOR_PROC_STATE
189 _waylend_tbm_util_proc_state_parse(char * str);
190
191 int
192 _waylend_tbm_util_dump_queue(WL_TBM_MONITOR_PROC_STATE cmd, tbm_bufmgr bufmgr, double scale);
193
194 void
195 _waylend_tbm_util_dump_snapshot(tbm_bufmgr bufmgr, double scale, char *path);
196
197 int
198 _waylend_tbm_util_trace(WL_TBM_MONITOR_PROC_STATE cmd, tbm_bufmgr bufmgr);
199
200 char *
201 _wayland_tbm_dump_directory_make(void);
202
203 int wayland_tbm_monitor_server_init(struct wayland_tbm_server *tbm_srv);
204
205 #ifdef  __cplusplus
206 }
207 #endif
208
209 #endif