4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
8 * Jaewon Lim <jaewon81.lim@samsung.com>
9 * Woojin Jung <woojin2.jung@samsung.com>
10 * Juyoung Kim <j0.kim@samsung.com>
11 * Anastasia Lyupa <a.lyupa@samsung.com>
13 * This library is free software; you can redistribute it and/or modify it under
14 * the terms of the GNU Lesser General Public License as published by the
15 * Free Software Foundation; either version 2.1 of the License, or (at your option)
18 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
19 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
21 * License for more details.
23 * You should have received a copy of the GNU Lesser General Public License
24 * along with this library; if not, write to the Free Software Foundation, Inc., 51
25 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 * - Samsung RnD Institute Russia
40 #include "probeinfo.h"
47 #define likely(x) __builtin_expect((x),1)
48 #define unlikely(x) __builtin_expect((x),0)
51 #define NUM_OF_MONITOR 3
52 #define DA_LOG_MAX 4096
53 #define PERROR_MSG_MAX 128
55 #define DEFAULT_TOKEN "`,"
57 #define CALLER_ADDRESS \
58 ((void*) __builtin_extract_return_addr(__builtin_return_address(0)))
60 #define BACKTRACE_SYMBOLS cached_backtrace_symbols
79 char data[DA_LOG_MAX];
87 unsigned long currentTime;
88 unsigned int callDepth;
91 /***************************************************************************
93 ***************************************************************************/
95 int preBlockBegin(void* caller, bool bFiltering, enum DaOptions);
98 int postBlockBegin(int preresult);
101 void probeBlockStart();
102 void probeBlockEnd();
104 unsigned int getCurrentEventIndex();
105 unsigned int getCallDepth();
106 unsigned long getTraceState();
107 unsigned long getCurrentTime();
108 bool setProbePoint(probeInfo_t * iProbe);
109 int update_heap_memory_size(bool isAdd, size_t size);
111 bool printLogStr(const char* str, int msgType);
112 //bool printLog(log_t* log, int msgType);
113 int __appendTypeLog(log_t* log, int nInput, char* token, ...);
114 int getBacktraceString(log_t* log, int bufsize);
116 //char* captureScreenShotX(int* width, int* height);
117 //void releaseScreenShotX();
119 //int printSamplingLog(void);
121 //bool captureScreen(unsigned int logNum);
122 //void captureProbe();
123 //int registeScreenChange(int renderID);
124 //void detectTouchEvent(int touchID);
125 //int getTouchState();
126 //int isPossibleCapture();
129 /***************************************************************************
131 ***************************************************************************/
133 // ========================= print log =====================================
134 #define PRINTMSG(msg) printLogStr(msg, MSG_MSG)
136 // =========================== declare variables ===========================
137 // local variable is faster than heap allocated variable
138 // array variable initialization with declare is expensive than memset
140 // declare variable for standard api (not tizen related api)
141 #define DECLARE_VARIABLE_STANDARD \
142 probeInfo_t probeInfo; \
144 bool bfiltering = true; \
145 int olderrno, newerrno; \
146 int __attribute__((unused)) ret
148 // ========================== get function pointer =========================
150 #define GET_REAL_FUNCP(FUNCNAME, SONAME, FUNCTIONPOINTER) \
152 if(!FUNCTIONPOINTER) { \
154 if(lib_handle[SONAME] == NULL) { \
155 lib_handle[SONAME] = dlopen(lib_string[SONAME], RTLD_LAZY); \
156 if(lib_handle[SONAME] == NULL) { \
157 char perror_msg[PERROR_MSG_MAX]; \
158 sprintf(perror_msg, "dlopen failed : %s", lib_string[SONAME]); \
159 perror(perror_msg); \
163 FUNCTIONPOINTER = dlsym(lib_handle[SONAME], #FUNCNAME); \
164 if(FUNCTIONPOINTER == NULL || dlerror() != NULL) { \
165 perror("dlsym failed : " #FUNCNAME); \
172 #define GET_REAL_FUNC(FUNCNAME, SONAME) \
173 GET_REAL_FUNCP(FUNCNAME, SONAME, FUNCNAME##p)
175 #define GET_REAL_FUNCP_RTLD_NEXT(FUNCNAME, FUNCTIONPOINTER) \
177 if(!FUNCTIONPOINTER) { \
179 FUNCTIONPOINTER = dlsym(RTLD_NEXT, #FUNCNAME); \
180 if(FUNCTIONPOINTER == NULL || dlerror() != NULL) { \
181 perror("dlsym failed"); \
188 #define GET_REAL_FUNC_RTLD_NEXT(FUNCNAME) \
189 GET_REAL_FUNCP_RTLD_NEXT(FUNCNAME, FUNCNAME##p)
191 #define GET_REAL_FUNCP_RTLD_NEXT_CPP(FUNCNAME, FUNCTIONPOINTER) \
193 if(!FUNCTIONPOINTER) { \
195 void* funcp = dlsym(RTLD_NEXT, #FUNCNAME); \
196 if(funcp == NULL || dlerror() != NULL) { \
197 perror("dlsym failed : " #FUNCNAME); \
200 memcpy(&FUNCTIONPOINTER, &funcp, sizeof(void*)); \
205 #define GET_REAL_FUNC_RTLD_NEXT_CPP(FUNCNAME) \
206 GET_REAL_FUNCP_RTLD_NEXT_CPP(FUNCNAME, FUNCNAME##p)
208 // ======================= pre block macro ================================
210 #define PRE_PROBEBLOCK_BEGIN() \
211 if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) { \
212 setProbePoint(&probeInfo)
214 #define PRE_PROBEBLOCK_END() \
220 #define PRE_PROBEBLOCK() \
221 PRE_PROBEBLOCK_BEGIN(); \
224 // ===================== unconditional probe block ========================
226 #define PRE_UNCONDITIONAL_BLOCK_BEGIN() \
229 setProbePoint(&probeInfo)
231 #define PRE_UNCONDITIONAL_BLOCK_END() \
235 #define POST_UNCONDITIONAL_BLOCK_BEGIN(LCTYPE) \
239 APPEND_LOG_BASIC(LCTYPE)
241 #define POST_UNCONDITIONAL_BLOCK_END() \
242 printLog(&log, MSG_LOG); \
246 // ========================= simplify macro ================================
248 #define BEFORE_ORIGINAL(FUNCNAME, LIBNAME) \
249 DECLARE_VARIABLE_STANDARD; \
250 GET_REAL_FUNC(FUNCNAME, LIBNAME); \
253 #define BEFORE_ORIGINAL_NOFILTER(FUNCNAME, LIBNAME) \
254 DECLARE_VARIABLE_STANDARD; \
255 GET_REAL_FUNC(FUNCNAME, LIBNAME); \
256 bfiltering = false; \