[FIX] wrong app start time
[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 ENABLE_INTERNAL_MALLOC          0x0001
60 #define ENABLE_SNAPSHOT                         0x0002
61
62 #define LOG(FORMAT, ...)                                        \
63         do {                                                                    \
64                 char buf[128];                                          \
65                 sprintf(buf, FORMAT, __VA_ARGS__);      \
66                 PRINTMSG(buf);                                          \
67         } while(0)                                                              \
68
69 #define SCREENSHOT_LOCK()                                                                               \
70         do {                                                                                                            \
71                 int old;                                                                                                \
72                 LOG("screenshot_lock : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
73                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
74                 old = gTraceInfo.screenshot.state;                                              \
75                 gTraceInfo.screenshot.state = -1;                                               \
76                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
77                 if(old > 0) {                                                                                   \
78                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
79                                 captureScreen();                                                                \
80                 }                                                                                                               \
81         } while(0)
82
83 #define SCREENSHOT_UNLOCK()                                                                             \
84         do {                                                                                                            \
85                 LOG("screenshot_unlock : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
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                 LOG("screenshot_set : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
96                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
97                 old = gTraceInfo.screenshot.state;                                              \
98                 if(gTraceInfo.screenshot.state >= 0)                                    \
99                         gTraceInfo.screenshot.state = 1;                                        \
100                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
101                 if(old == 2) {                                                                                  \
102                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
103                                 captureScreen();                                                                \
104                 }                                                                                                               \
105         } while(0)
106
107 #define SCREENSHOT_UNSET()                                                                              \
108         do {                                                                                                            \
109                 LOG("screenshot_unset : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
110                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
111                 if(gTraceInfo.screenshot.state >= 0)                                    \
112                         gTraceInfo.screenshot.state = 0;                                        \
113                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
114         } while(0)
115
116 #define SCREENSHOT_DONE()                                                                               \
117         do {                                                                                                            \
118                 int old;                                                                                                \
119                 LOG("screenshot_done : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
120                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
121                 old = gTraceInfo.screenshot.state;                                              \
122                 if(gTraceInfo.screenshot.state == 1)                                    \
123                         gTraceInfo.screenshot.state = 2;                                        \
124                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
125                 if(old == 1) {                                                                                  \
126                         activateCaptureTimer();                                                         \
127                 }                                                                                                               \
128         } while(0)
129
130 #define SCREENSHOT_TIMEOUT()                                                                    \
131         do {                                                                                                            \
132                 int old;                                                                                                \
133                 LOG("screenshot_timeout : %d, %s\n", gTraceInfo.screenshot.state, __func__); \
134                 pthread_mutex_lock(&(gTraceInfo.screenshot.ssMutex));   \
135                 old = gTraceInfo.screenshot.state;                                              \
136                 if(gTraceInfo.screenshot.state == 2)                                    \
137                         gTraceInfo.screenshot.state = 0;                                        \
138                 pthread_mutex_unlock(&(gTraceInfo.screenshot.ssMutex)); \
139                 if(old == 2) {                                                                                  \
140                         if(isOptionEnabled(OPT_SNAPSHOT))                                       \
141                                 captureScreen();                                                                \
142                 }                                                                                                               \
143         } while(0)
144
145 #define NUM_ORIGINAL_LIBRARY    9
146
147 typedef enum
148 {
149         LIBC = 0,
150         LIBPTHREAD = 1,
151         LIBELEMENTARY = 2,
152         LIBOSP_UIFW = 3,
153         LIBOSP_APPFW = 4,
154         LIBOSP_WEB = 5,
155         LIBECORE_INPUT_EVAS = 6,
156         LIBDAEMON = 7,
157         LIBCAPI_APPFW_APPLICATION = 8
158 } ORIGINAL_LIBRARY;
159
160 extern 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         unsigned long           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
219 // screen capture functions
220 int initialize_screencapture();
221 int finalize_screencapture();
222 int captureScreen();
223 int activateCaptureTimer();
224 void _cb_render_post(void* data, Evas* e, void* eventinfo);
225
226 // event related functions
227 int initialize_event();
228 int finalize_event();
229 int getOrientation();
230 void on_orientation_changed(int angle, bool capi);
231
232 int remove_indir(const char* dirname);
233
234 // query functions
235 #define isOptionEnabled(OPT)    ((gTraceInfo.optionflag & OPT) != 0)
236
237 #ifdef __cplusplus
238 }
239 #endif
240
241 #endif  // _DAHELPER_H_