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