[FIX] cherry-pick d89d303d37d714ced2d1a9945ae2ea054c5824c0 (#8:3,4,5) + changes
[platform/core/system/swap-probe.git] / include / dahelper.h
1 /*
2  *  DA probe
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: 
7  *
8  * Jaewon Lim <jaewon81.lim@samsung.com>
9  * Woojin Jung <woojin2.jung@samsung.com>
10  * Juyoung Kim <j0.kim@samsung.com>
11  * 
12  * This library is free software; you can redistribute it and/or modify it under
13  * the terms of the GNU Lesser General Public License as published by the
14  * Free Software Foundation; either version 2.1 of the License, or (at your option)
15  * any later version.
16  * 
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
18  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20  * License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this library; if not, write to the Free Software Foundation, Inc., 51
24  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  *
26  * Contributors:
27  * - S-Core Co., Ltd
28  * 
29  */
30
31 #ifndef _DAHELPER_H_
32 #define _DAHELPER_H_
33
34 #include <stdbool.h>
35 #include <pthread.h>                    // for pthread_mutex_t
36
37 #include <Evas.h>
38
39 #include "daprobe.h"
40
41 #ifdef __cplusplus
42 extern "C"{
43 #endif
44
45 #define MAX_PATH_LENGTH         256
46 #define MAX_STACK_DEPTH         128
47 #define TRIM_STACK_DEPTH        2
48
49 /*
50 #define WIN_RENDER_POST 0
51 #define CONTROLBAR_RENDER_POST 1
52 #define NAVIFRAME_RENDER_POST 2
53 #define PAGER_RENDER_POST 3
54 #define RENDER_POST_COUNT 4
55
56 #define SNAPSHOT_WAIT_TIME_MAX 10000
57 */
58
59 #define TS_NONE                                         0x00000000
60 #define TS_PROBE                                        0x00000001
61 #define TS_INIT                                         0x00000002
62 #define TS_FINIT                                        0x00000004
63 #define TS_ENTER_PROBE_BLOCK            0x00000008
64 #define TS_SET_PROBE_POINT                      0x00000010
65 #define TS_PRINT_LOG                            0x00000020
66 #define TS_PRINT_SAMPLE_LOG                     0x00000040
67 #define TS_APPEND_TYPE_LOG                      0x00000080
68 #define TS_BACKTRACE                            0x00000100
69 #define TS_HASHFUNC                                     0x00000200
70 #define TS_PROFIL_THREAD                        0x00000400
71 #define TS_PROFIL_COUNT                         0x00000800
72 #define TS_DETECT_TOUCH                         0x00001000
73 #define TS_REGIST_SCREEN_CHANGE         0x00002000
74 #define TS_POSSIBLE_CAPTURE                     0x00004000
75 #define TS_RECV_THREAD                          0x00008000
76 #define TS_CUSTOM_CHART_THREAD          0x00010000
77 #define TRACE_STATE_SET(value)          ((gSTrace) |= (value))
78 #define TRACE_STATE_UNSET(value)        ((gSTrace) &= (~value))
79
80 #define ENABLE_INTERNAL_MALLOC          0x0001
81 #define ENABLE_SNAPSHOT                         0x0002
82
83 #define LOG(FORMAT, ...)                                        \
84         do {                                                                    \
85                 char buf[128];                                          \
86                 sprintf(buf, FORMAT, __VA_ARGS__);      \
87                 PRINTMSG(buf);                                          \
88         } while(0)                                                              \
89
90 #define SCREENSHOT_LOCK()                                                                               \
91         do {                                                                                                            \
92                 int old;                                                                                                \
93                 LOG("screenshot_lock : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
94                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
95                 old = gTraceInfo.screenshot.state;                                              \
96                 gTraceInfo.screenshot.state = -1;                                               \
97                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
98                 if(old > 0) {                                                                                   \
99                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
100                                 captureScreen();                                                                \
101                 }                                                                                                               \
102         } while(0)
103
104 #define SCREENSHOT_UNLOCK()                                                                             \
105         do {                                                                                                            \
106                 LOG("screenshot_unlock : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
107                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
108                 gTraceInfo.screenshot.state = 1;                                                \
109                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
110         } while(0)
111
112 #define SCREENSHOT_SET()                                                                                \
113         do {                                                                                                            \
114                 int old;                                                                                                \
115                 LOG("screenshot_set : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
116                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
117                 old = gTraceInfo.screenshot.state;                                              \
118                 if(gTraceInfo.screenshot.state >= 0)                                    \
119                         gTraceInfo.screenshot.state = 1;                                        \
120                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
121                 if(old == 2) {                                                                                  \
122                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
123                                 captureScreen();                                                                \
124                 }                                                                                                               \
125         } while(0)
126
127 #define SCREENSHOT_UNSET()                                                                              \
128         do {                                                                                                            \
129                 LOG("screenshot_unset : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
130                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
131                 if(gTraceInfo.screenshot.state >= 0)                                    \
132                         gTraceInfo.screenshot.state = 0;                                        \
133                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
134         } while(0)
135
136 #define SCREENSHOT_DONE()                                                                               \
137         do {                                                                                                            \
138                 int old;                                                                                                \
139                 LOG("screenshot_done : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
140                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
141                 old = gTraceInfo.screenshot.state;                                              \
142                 if(gTraceInfo.screenshot.state == 1)                                    \
143                         gTraceInfo.screenshot.state = 2;                                        \
144                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
145                 if(old == 1) {                                                                                  \
146                         activateCaptureTimer();                                                         \
147                 }                                                                                                               \
148         } while(0)
149
150 #define SCREENSHOT_TIMEOUT()                                                                    \
151         do {                                                                                                            \
152                 int old;                                                                                                \
153                 LOG("screenshot_timeout : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
154                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
155                 old = gTraceInfo.screenshot.state;                                              \
156                 if(gTraceInfo.screenshot.state == 2)                                    \
157                         gTraceInfo.screenshot.state = 0;                                        \
158                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
159                 if(old == 2) {                                                                                  \
160                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
161                                 captureScreen();                                                                \
162                 }                                                                                                               \
163         } while(0)
164
165 #define NUM_ORIGINAL_LIBRARY    9
166
167 typedef enum
168 {
169         LIBC = 0,
170         LIBPTHREAD = 1,
171         LIBELEMENTARY = 2,
172         LIBOSP_UIFW = 3,
173         LIBOSP_APPFW = 4,
174         LIBOSP_WEB = 5,
175         LIBECORE_INPUT_EVAS = 6,
176         LIBDAEMON = 7,
177         LIBCAPI_APPFW_APPLICATION = 8
178 } ORIGINAL_LIBRARY;
179
180 extern char *lib_string[NUM_ORIGINAL_LIBRARY];
181 extern void *lib_handle[NUM_ORIGINAL_LIBRARY];
182
183 // type definition for global variable
184 typedef struct
185 {
186         int eventIndex;
187         pthread_mutex_t eventMutex;
188 } __indexInfo;
189
190 typedef struct
191 {
192         int daemonSock;
193         pthread_mutex_t sockMutex;
194 } __socketInfo;
195
196 typedef struct
197 {
198         char appName[128];
199         unsigned int startTime;
200 } __appInfo;
201
202 typedef struct
203 {
204         int state;
205         pthread_mutex_t ssMutex;
206 } __screenshotInfo;
207
208 typedef struct
209 {
210         void* map_start;
211         void* map_end;
212 } __mapInfo;
213
214 typedef struct
215 {
216         __indexInfo                     index;
217         __socketInfo            socket;
218         __appInfo                       app;
219         __screenshotInfo        screenshot;
220         __mapInfo                       exec_map;
221         int                                     stateTouch;
222         int                                     init_complete;
223         int                                     custom_chart_callback_count;
224         unsigned long           optionflag;
225 } __traceInfo;
226
227 extern __thread unsigned long   gSTrace;
228 extern __traceInfo gTraceInfo;
229
230 int get_map_address(void* symbol, void** map_start, void** map_end);
231 char** da_backtrace_symbols (void* const* array, int size);
232 char** cached_backtrace_symbols (void* const* array, int size);
233
234 // profil turned on
235 int __profil(int mode);
236
237 //wchar_t* -> char*
238 void WcharToChar(char* pstrDest, const wchar_t* pwstrSrc);
239
240 // screen capture functions
241 int initialize_screencapture();
242 int finalize_screencapture();
243 int captureScreen();
244 int activateCaptureTimer();
245 void _cb_render_post(void* data, Evas* e, void* eventinfo);
246
247 // event related functions
248 int initialize_event();
249 int finalize_event();
250 int getOrientation();
251 void orientationEnabled();
252 void on_orientation_changed(int angle, bool capi);
253
254 int remove_indir(const char* dirname);
255
256 // query functions
257 #define isOptionEnabled(OPT)    ((gTraceInfo.optionflag & OPT) != 0)
258
259 #ifdef __cplusplus
260 }
261 #endif
262
263 #endif  // _DAHELPER_H_