1947845b1c4f7fdb3cbb124d4478878ab5814bb4
[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 extern int app_efl_main_flg;
46
47 #define MAX_PATH_LENGTH         256
48 #define MAX_STACK_DEPTH         128
49 #define TRIM_STACK_DEPTH        2
50
51 /*
52 #define WIN_RENDER_POST 0
53 #define CONTROLBAR_RENDER_POST 1
54 #define NAVIFRAME_RENDER_POST 2
55 #define PAGER_RENDER_POST 3
56 #define RENDER_POST_COUNT 4
57
58 #define SNAPSHOT_WAIT_TIME_MAX 10000
59 */
60
61 #define ENABLE_INTERNAL_MALLOC          0x0001
62 #define ENABLE_SNAPSHOT                         0x0002
63
64 #define LOG(FORMAT, ...)                                        \
65         do {                                                                    \
66                 char buf[128];                                          \
67                 sprintf(buf, FORMAT, __VA_ARGS__);      \
68                 PRINTMSG(buf);                                          \
69         } while(0)                                                              \
70
71 #define SCREENSHOT_LOCK()                                                                               \
72         do {                                                                                                            \
73                 int old;                                                                                                \
74                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
75                 old = gTraceInfo.screenshot.state;                                              \
76                 gTraceInfo.screenshot.state = -1;                                               \
77                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
78                 if(old > 0) {                                                                                   \
79                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
80                                 captureScreen();                                                                \
81                 }                                                                                                               \
82         } while(0)
83
84 #define SCREENSHOT_UNLOCK()                                                                             \
85         do {                                                                                                            \
86                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
87                 if(gTraceInfo.screenshot.state < 0)                                             \
88                         gTraceInfo.screenshot.state = 1;                                        \
89                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
90         } while(0)
91
92 #define SCREENSHOT_SET()                                                                                \
93         do {                                                                                                            \
94                 int old;                                                                                                \
95                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
96                 old = gTraceInfo.screenshot.state;                                              \
97                 if(gTraceInfo.screenshot.state >= 0)                                    \
98                         gTraceInfo.screenshot.state = 1;                                        \
99                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
100                 if(old == 2) {                                                                                  \
101                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
102                                 captureScreen();                                                                \
103                 }                                                                                                               \
104         } while(0)
105
106 #define SCREENSHOT_UNSET()                                                                              \
107         do {                                                                                                            \
108                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
109                 if(gTraceInfo.screenshot.state >= 0)                                    \
110                         gTraceInfo.screenshot.state = 0;                                        \
111                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
112         } while(0)
113
114 #define SCREENSHOT_DONE()                                                                               \
115         do {                                                                                                            \
116                 int old;                                                                                                \
117                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
118                 old = gTraceInfo.screenshot.state;                                              \
119                 if(gTraceInfo.screenshot.state == 1)                                    \
120                         gTraceInfo.screenshot.state = 2;                                        \
121                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
122                 if(old == 1) {                                                                                  \
123                         activateCaptureTimer();                                                         \
124                 }                                                                                                               \
125         } while(0)
126
127 #define SCREENSHOT_TIMEOUT()                                                                    \
128         do {                                                                                                            \
129                 int old;                                                                                                \
130                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
131                 old = gTraceInfo.screenshot.state;                                              \
132                 if(gTraceInfo.screenshot.state == 2)                                    \
133                         gTraceInfo.screenshot.state = 0;                                        \
134                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
135                 if(old == 2) {                                                                                  \
136                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
137                                 captureScreen();                                                                \
138                 }                                                                                                               \
139         } while(0)
140
141 #define NUM_ORIGINAL_LIBRARY    13
142
143 typedef enum
144 {
145         LIBC = 0,
146         LIBPTHREAD = 1,
147         LIBELEMENTARY = 2,
148         LIBOSP_UIFW = 3,
149         LIBOSP_APPFW = 4,
150         LIBOSP_WEB = 5,
151         LIBECORE_INPUT_EVAS = 6,
152         LIBDAEMON = 7,
153         LIBCAPI_APPFW_APPLICATION = 8,
154         LIBGLES20 = 9,
155         LIBEGL = 10,
156         LIBOSP_NET = 11,
157         LIBSELF = 12
158 } ORIGINAL_LIBRARY;
159
160 extern const char *lib_string[NUM_ORIGINAL_LIBRARY];
161 extern void *lib_handle[NUM_ORIGINAL_LIBRARY];
162
163 // type definition for global variable
164 typedef struct
165 {
166         int eventIndex;
167         pthread_mutex_t eventMutex;
168 } __indexInfo;
169
170 typedef struct
171 {
172         int daemonSock;
173         pthread_mutex_t sockMutex;
174 } __socketInfo;
175
176 typedef struct
177 {
178         char appName[128];
179         uint64_t startTime;
180 } __appInfo;
181
182 typedef struct
183 {
184         int state;
185         pthread_mutex_t ssMutex;
186 } __screenshotInfo;
187
188 typedef struct
189 {
190         void* map_start;
191         void* map_end;
192 } __mapInfo;
193
194 typedef struct
195 {
196         __indexInfo                     index;
197         __socketInfo            socket;
198         __appInfo                       app;
199         __screenshotInfo        screenshot;
200         __mapInfo                       exec_map;
201         int                                     stateTouch;
202         int                                     init_complete;
203         int                                     custom_chart_callback_count;
204         uint64_t                optionflag;
205 } __traceInfo;
206
207 extern __traceInfo gTraceInfo;
208
209 int get_map_address(void* symbol, void** map_start, void** map_end);
210 char** da_backtrace_symbols (void* const* array, int size);
211 char** cached_backtrace_symbols (void* const* array, int size);
212
213 // profil turned on
214 int __profil(int mode);
215
216 //wchar_t* -> char*
217 void WcharToChar(char* pstrDest, const wchar_t* pwstrSrc);
218 char *absolutize_filepath(char buf[PATH_MAX], const char *fname);
219 void application_exit();
220
221 // screen capture functions
222 int initialize_screencapture();
223 int finalize_screencapture();
224 int captureScreen();
225 int activateCaptureTimer();
226 void _cb_render_post(void* data, Evas* e, void* eventinfo);
227
228 // event related functions
229 int initialize_event();
230 int finalize_event();
231 int getOrientation();
232 void on_orientation_changed(int angle, bool capi);
233
234 int remove_indir(const char* dirname);
235
236 // query functions
237 #define isOptionEnabled(OPT)    ((gTraceInfo.optionflag & OPT) != 0)
238
239 #ifdef __cplusplus
240 }
241 #endif
242
243 #endif  // _DAHELPER_H_