From 9d2855931b8344a9ce1b8d72191779c186e5148b Mon Sep 17 00:00:00 2001 From: Vitaliy Cherepanov Date: Fri, 25 Jul 2014 12:38:58 +0400 Subject: [PATCH] [FEATURE] add evas_gl_ probes Change-Id: If427748901885dc2ae44e06f36f9ac59e1d8d86b Signed-off-by: Vitaliy Cherepanov --- Makefile | 10 +- .../{common_probe_init.cpp => common_probe_init.c} | 60 ++++++- include/common_probe_init.h | 20 ++- {probe_graphics => include}/da_gles20.h | 18 +- include/daprobe.h | 12 +- probe_capi/capi_appfw.c | 44 ++--- probe_graphics/da_evas_gl.c | 185 +++++++++++++++++++++ probe_graphics/da_gles20_tizen.cpp | 38 ----- probe_memory/libdamemmanage.c | 1 + scripts/api_names.txt | 14 ++ 10 files changed, 311 insertions(+), 91 deletions(-) rename helper/{common_probe_init.cpp => common_probe_init.c} (63%) rename {probe_graphics => include}/da_gles20.h (88%) create mode 100644 probe_graphics/da_evas_gl.c diff --git a/Makefile b/Makefile index 593e6f8..4383672 100644 --- a/Makefile +++ b/Makefile @@ -94,13 +94,13 @@ CAPI_SRCS = $(COMMON_SRCS) \ # ./probe_ui/capi_capture.c TIZEN_SRCS = $(COMMON_SRCS) $(CAPI_SRCS)\ - ./helper/addr-tizen.c \ - ./helper/common_probe_init.cpp \ - ./probe_memory/libdanew.cpp \ - ./probe_graphics/da_gles20_tizen.cpp \ + ./helper/addr-tizen.c \ + ./helper/common_probe_init.c \ + ./probe_memory/libdanew.cpp \ + ./probe_graphics/da_evas_gl.c \ + ./probe_graphics/da_gles20_tizen.cpp \ ./probe_graphics/da_gles20_native.cpp - ASM_SRC = ./helper/da_call_original.S ## Totally brain-dead. diff --git a/helper/common_probe_init.cpp b/helper/common_probe_init.c similarity index 63% rename from helper/common_probe_init.cpp rename to helper/common_probe_init.c index 7b4883f..4ecabd7 100644 --- a/helper/common_probe_init.cpp +++ b/helper/common_probe_init.c @@ -27,23 +27,21 @@ */ #include +#include "da_gles20.h" +#include "binproto.h" #include "common_probe_init.h" - - //#define EGL_TEST -void dummy() -{ - return; -} - void probe_terminate_with_err(const char *msg, const char *func_name, ORIGINAL_LIBRARY id) { char error_msg[1024]; + const char *lib_name = "unknown"; - sprintf(error_msg, "%s : [%s], %s", msg, func_name, lib_string[id]); + if (id < NUM_ORIGINAL_LIBRARY) + lib_name = lib_string[id]; + sprintf(error_msg, "%s : [%s], %s", msg, func_name, lib_name); perror(error_msg); PRINTERR(error_msg); //wait for flush @@ -62,6 +60,12 @@ void probe_terminate_with_err(const char *msg, const char *func_name, // search original function by name // function have no return becouse on error it terminates main application #ifdef EGL_TEST + +void dummy() +{ + return; +} + void init_probe_egl(__attribute__ ((unused))const char *func_name, void **func_pointer, __attribute__ ((unused))ORIGINAL_LIBRARY id) { @@ -83,9 +87,47 @@ void init_probe_egl(const char *func_name, void **func_pointer, probe_terminate_with_err("dlopen failed", func_name, id); }; faddr = dlsym(lib_handle[id], func_name); - if (faddr == __null || dlerror() != __null) + if (faddr == NULL || dlerror() != NULL) probe_terminate_with_err("dlsym failed", func_name, id); memcpy(func_pointer, &faddr, sizeof(faddr)); (gProbeBlockCount--); } #endif + + +void init_probe_gl(const char *func_name, void **func_pointer, + ORIGINAL_LIBRARY id, int blockresult, int32_t vAPI_ID) +{ + void *faddr; + probeInfo_t tempProbeInfo; + + probeBlockStart(); + if (lib_handle[id] == ((void *)0)) { + lib_handle[id] = dlopen(lib_string[id], RTLD_LAZY); + if (lib_handle[id] == ((void *)0)) + probe_terminate_with_err("dlopen failed", func_name, id); + + setProbePoint(&tempProbeInfo); + if (blockresult != 0) { + /* get max value */ + char maxValString[64]; + GLint maxVal[2]; + glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVal[0]); + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxVal[1]); + sprintf(maxValString, "%d,%d", maxVal[0], maxVal[1]); + PREPARE_LOCAL_BUF(); + PACK_COMMON_BEGIN(MSG_PROBE_GL, vAPI_ID, "", 0); + PACK_COMMON_END('p', 1, 0, 0); + PACK_GL_ADD(APITYPE_INIT, 0, maxValString); + FLUSH_LOCAL_BUF(); + } + } + + faddr = dlsym(lib_handle[id], func_name); + if (faddr == NULL || dlerror() != NULL) + probe_terminate_with_err("function not found in lib", func_name, + id); + + memcpy(func_pointer, &faddr, sizeof(faddr)); + probeBlockEnd(); +} diff --git a/include/common_probe_init.h b/include/common_probe_init.h index 541f9bb..f2daf25 100644 --- a/include/common_probe_init.h +++ b/include/common_probe_init.h @@ -28,8 +28,11 @@ #ifndef __COMMON_PROBE_INIT_H__ #define __COMMON_PROBE_INIT_H__ -#include "dahelper.h" +#ifdef __cplusplus +extern "C" { +#endif +#include "dahelper.h" //////////////////////////////////////////////////////////////////////////// //egl init probe function // params: @@ -39,8 +42,17 @@ // info // search original function by name // function have no return becouse on error it terminates main application -void init_probe_egl(const char *func_name, void **func_pointer, ORIGINAL_LIBRARY id); +extern void init_probe_egl(const char *func_name, void **func_pointer, + ORIGINAL_LIBRARY id); + +extern void init_probe_gl(const char *func_name, void **func_pointer, + ORIGINAL_LIBRARY id, int blockresult, int32_t vAPI_ID); + +extern void probe_terminate_with_err(const char *msg, const char *func_name, + ORIGINAL_LIBRARY id); + +#ifdef __cplusplus +} /* extern "C" */ +#endif -void probe_terminate_with_err(const char *msg, const char *func_name, - ORIGINAL_LIBRARY id); #endif /* __COMMON_PROBE_INIT_H__ */ diff --git a/probe_graphics/da_gles20.h b/include/da_gles20.h similarity index 88% rename from probe_graphics/da_gles20.h rename to include/da_gles20.h index dcdaa38..d3e3cf8 100644 --- a/probe_graphics/da_gles20.h +++ b/include/da_gles20.h @@ -62,7 +62,9 @@ extern EGLContext eglGetCurrentContext(void); #define PACK_GL_ADD_COMMON(GL_api_type, GL_elapsed_time) \ do { /* PACK_GL_ADD_COMMON */ \ - BUF_PTR = pack_int64(BUF_PTR, voidp_to_uint64((void *)eglGetCurrentContext()));\ + /* TODO restore eglGetCurrentContext */ \ + /*BUF_PTR = pack_int64(BUF_PTR, voidp_to_uint64((void *)eglGetCurrentContext()));*/\ + BUF_PTR = pack_int64(BUF_PTR, voidp_to_uint64((void *)0));\ BUF_PTR = pack_int32(BUF_PTR, (uint32_t)GL_api_type); \ BUF_PTR = pack_int64(BUF_PTR, (uint64_t)GL_elapsed_time); \ } while (0) @@ -156,5 +158,19 @@ extern EGLContext eglGetCurrentContext(void); FLUSH_LOCAL_BUF(); \ POST_PACK_PROBEBLOCK_END() +#define BEFORE_EVAS_GL(FUNCNAME) \ + DECLARE_VARIABLE_STANDARD_NORET; \ + GLenum error = GL_NO_ERROR; \ + static methodType FUNCNAME ## p = 0; \ + int32_t vAPI_ID = API_ID_ ## FUNCNAME; \ + uint64_t start_nsec = 0; \ + PRE_PROBEBLOCK(); \ + if(blockresult != 0) \ + start_nsec = get_current_nsec(); \ + GET_REAL_FUNC_RTLD_NEXT(FUNCNAME) + +GLenum glGetError(void); +void glGetIntegerv(GLenum pname, GLint * params); + #endif /* DA_GLES20_H_ */ diff --git a/include/daprobe.h b/include/daprobe.h index 3c37edb..3e62798 100644 --- a/include/daprobe.h +++ b/include/daprobe.h @@ -178,14 +178,16 @@ typedef struct { // =========================== declare variables =========================== // local variable is faster than heap allocated variable // array variable initialization with declare is expensive than memset +#define DECLARE_ERRNO_VARS \ + int olderrno = 0; \ + int newerrno = 0; // declare variable for standard api (not tizen related api) #define DECLARE_VARIABLE_STANDARD \ probeInfo_t probeInfo; \ int blockresult = 0; \ bool bfiltering = true; \ - int olderrno = 0; \ - int newerrno = 0; \ + DECLARE_ERRNO_VARS; \ int __attribute__((unused)) ret // declare variable for standard api (not tizen related api) without ret @@ -230,10 +232,8 @@ typedef struct { if(!FUNCTIONPOINTER) { \ probeBlockStart(); \ FUNCTIONPOINTER = dlsym(RTLD_NEXT, #FUNCNAME); \ - if(FUNCTIONPOINTER == NULL || dlerror() != NULL) { \ - fprintf(stderr, "dlsym failed <%s>\n", #FUNCNAME); \ - exit(0); \ - } \ + if(FUNCTIONPOINTER == NULL || dlerror() != NULL) \ + probe_terminate_with_err("function not found", #FUNCNAME, -1); \ probeBlockEnd(); \ } \ } while(0) diff --git a/probe_capi/capi_appfw.c b/probe_capi/capi_appfw.c index 716e250..5578450 100644 --- a/probe_capi/capi_appfw.c +++ b/probe_capi/capi_appfw.c @@ -32,10 +32,12 @@ #include #include +#include "damaps.h" #include "daprobe.h" #include "dahelper.h" #include "probeinfo.h" #include "binproto.h" +#include "common_probe_init.h" /* FIXME think of a better solution for conditional build. */ #ifndef PRIVATE_CAPI_APPFW @@ -54,25 +56,19 @@ app_event_callback_s gAppCallback; #define PACK_ORIGINAL_APPFWCYCLE(API_ID, RTYPE, RVAL, INPUTFORMAT, ...) \ newerrno = errno; \ do { \ - if(postBlockBegin(blockresult)) { \ - PREPARE_LOCAL_BUF(); \ - PACK_COMMON_BEGIN(MSG_PROBE_LIFECYCLE, API_ID, INPUTFORMAT, __VA_ARGS__); \ - PACK_COMMON_END(RTYPE, RVAL, newerrno, blockresult); \ - FLUSH_LOCAL_BUF(); \ - postBlockEnd(); \ - } \ + PREPARE_LOCAL_BUF(); \ + PACK_COMMON_BEGIN(MSG_PROBE_LIFECYCLE, API_ID, INPUTFORMAT, __VA_ARGS__); \ + PACK_COMMON_END(RTYPE, RVAL, newerrno, blockresult); \ + FLUSH_LOCAL_BUF(); \ } while(0); \ errno = (newerrno != 0) ? newerrno : olderrno -static enum DaOptions _sopt = OPT_ALWAYSON; - static bool _dalc_app_create(void *user_data) { bool bret = false; - DECLARE_VARIABLE_STANDARD; + DECLARE_ERRNO_VARS; + int blockresult = 1; - bfiltering = false; - PRE_PROBEBLOCK(); bret = gAppCallback.create(user_data); PACK_ORIGINAL_APPFWCYCLE(API_ID__dalc_app_create, 'b', bret, "p", @@ -83,10 +79,8 @@ static bool _dalc_app_create(void *user_data) static void _dalc_app_terminate(void *user_data) { - DECLARE_VARIABLE_STANDARD; - - bfiltering = false; - PRE_PROBEBLOCK(); + DECLARE_ERRNO_VARS; + int blockresult = 1; gAppCallback.terminate(user_data); @@ -96,10 +90,8 @@ static void _dalc_app_terminate(void *user_data) static void _dalc_app_pause(void *user_data) { - DECLARE_VARIABLE_STANDARD; - - bfiltering = false; - PRE_PROBEBLOCK(); + DECLARE_ERRNO_VARS; + int blockresult = 1; gAppCallback.pause(user_data); @@ -109,10 +101,8 @@ static void _dalc_app_pause(void *user_data) static void _dalc_app_resume(void *user_data) { - DECLARE_VARIABLE_STANDARD; - - bfiltering = false; - PRE_PROBEBLOCK(); + DECLARE_ERRNO_VARS; + int blockresult = 1; gAppCallback.resume(user_data); @@ -126,10 +116,8 @@ static void _dalc_app_control(app_control_h handle, void *user_data) static void _dalc_app_service(service_h handle, void *user_data) #endif /* PRIVATE_CAPI_APPFW */ { - DECLARE_VARIABLE_STANDARD; - - bfiltering = false; - PRE_PROBEBLOCK(); + DECLARE_ERRNO_VARS; + int blockresult = 1; #ifdef PRIVATE_CAPI_APPFW gAppCallback.app_control(handle, user_data); diff --git a/probe_graphics/da_evas_gl.c b/probe_graphics/da_evas_gl.c new file mode 100644 index 0000000..4ed385f --- /dev/null +++ b/probe_graphics/da_evas_gl.c @@ -0,0 +1,185 @@ +/* + * DA probe + * + * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * + * Vitaliy Cherepanov + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Contributors: + * - Samsung RnD Institute Russia + * + */ + +#include "da_gles20.h" +#include "daprobe.h" +#include "binproto.h" +#include "common_probe_init.h" + +static enum DaOptions _sopt = OPT_GLES; + +/* Evas open gl API functions */ + +void evas_gl_free(Evas_GL *evas_gl) +{ + typedef void (*methodType)(Evas_GL *evas_gl); + BEFORE_EVAS_GL(evas_gl_free); + evas_gl_freep(evas_gl); + GL_GET_ERROR(); + AFTER('v', NO_RETURN_VALUE, APITYPE_CONTEXT, "", "p", + evas_gl); +} + +void evas_gl_config_free(Evas_GL_Config *cfg) +{ + typedef void (*methodType)(Evas_GL_Config *cfg); + BEFORE_EVAS_GL(evas_gl_config_free); + evas_gl_config_freep(cfg); + GL_GET_ERROR(); + AFTER('v', NO_RETURN_VALUE, APITYPE_CONTEXT, "", "p", + cfg); +} + +void evas_gl_surface_destroy(Evas_GL *evas_gl, Evas_GL_Surface *surf) +{ + typedef void (*methodType)(Evas_GL *evas_gl, Evas_GL_Surface *surf); + BEFORE_EVAS_GL(evas_gl_surface_destroy); + evas_gl_surface_destroyp(evas_gl, surf); + GL_GET_ERROR(); + AFTER('v', NO_RETURN_VALUE, APITYPE_CONTEXT, "", "pp", + evas_gl, surf); +} + +void evas_gl_context_destroy(Evas_GL *evas_gl, Evas_GL_Context *ctx) +{ + typedef void (*methodType)(Evas_GL *evas_gl, Evas_GL_Context *ctx); + BEFORE_EVAS_GL(evas_gl_context_destroy); + evas_gl_context_destroyp(evas_gl, ctx); + GL_GET_ERROR(); + AFTER('v', NO_RETURN_VALUE, APITYPE_CONTEXT, "", "pp", + evas_gl, ctx); +} + + +Evas_GL *evas_gl_new(Evas *e) +{ + typedef Evas_GL *(*methodType)(Evas *e); + BEFORE_EVAS_GL(evas_gl_new); + Evas_GL *res = evas_gl_newp(e); + GL_GET_ERROR(); + AFTER('p', res, APITYPE_CONTEXT, "", "p", + e); + return res; +} + +Evas_GL_Config *evas_gl_config_new(void) +{ + typedef Evas_GL_Config *(*methodType)(void); + BEFORE_EVAS_GL(evas_gl_config_new); + Evas_GL_Config *res = evas_gl_config_newp(); + GL_GET_ERROR(); + AFTER_NO_PARAM('p', res, APITYPE_CONTEXT, ""); + return res; +} + +Evas_GL_Surface *evas_gl_surface_create(Evas_GL *evas_gl, Evas_GL_Config *cfg, + int w, int h) +{ + typedef Evas_GL_Surface *(*methodType)(Evas_GL *evas_gl, + Evas_GL_Config *cfg, + int w, int h); + BEFORE_EVAS_GL(evas_gl_surface_create); + Evas_GL_Surface *res = evas_gl_surface_createp(evas_gl, cfg, w, h); + GL_GET_ERROR(); + AFTER('p', res, APITYPE_CONTEXT, "", "ppdd", + evas_gl, cfg, w, h); + return res; +} + +Evas_GL_Context *evas_gl_context_create(Evas_GL *evas_gl, + Evas_GL_Context *share_ctx) +{ + typedef Evas_GL_Context *(*methodType)(Evas_GL *evas_gl, Evas_GL_Context *share_ctx); + BEFORE_EVAS_GL(evas_gl_context_create); + Evas_GL_Context *res = evas_gl_context_createp(evas_gl, share_ctx); + GL_GET_ERROR(); + AFTER('p', res, APITYPE_CONTEXT, "", "pp", + evas_gl, share_ctx); + return res; +} + +Eina_Bool evas_gl_make_current(Evas_GL *evas_gl, Evas_GL_Surface *surf, + Evas_GL_Context *ctx) +{ + typedef Eina_Bool (*methodType)(Evas_GL *evas_gl, Evas_GL_Surface *surf, + Evas_GL_Context *ctx); + BEFORE_EVAS_GL(evas_gl_make_current); + Eina_Bool res = evas_gl_make_currentp(evas_gl, surf, ctx); + GL_GET_ERROR(); + AFTER('b', res, APITYPE_CONTEXT, "", "ppp", + evas_gl, surf, ctx); + return res; +} + +const char *evas_gl_string_query(Evas_GL *evas_gl, int name) +{ + typedef const char *(*methodType)(Evas_GL *evas_gl, int name); + BEFORE_EVAS_GL(evas_gl_string_query); + const char *res = evas_gl_string_queryp(evas_gl, name); + GL_GET_ERROR(); + AFTER('s', res, APITYPE_CONTEXT, "", "pd", + evas_gl, name); + return res; +} + +Evas_GL_Func evas_gl_proc_address_get(Evas_GL *evas_gl, const char *name) +{ + typedef Evas_GL_Func(*methodType)(Evas_GL *evas_gl, const char *name); + BEFORE_EVAS_GL(evas_gl_proc_address_get); + Evas_GL_Func res = evas_gl_proc_address_getp(evas_gl, name); + GL_GET_ERROR(); + AFTER('p', res, APITYPE_CONTEXT, "", "ps", + evas_gl, name); + return res; +} + +Eina_Bool evas_gl_native_surface_get(Evas_GL *evas_gl, Evas_GL_Surface *surf, + Evas_Native_Surface *ns) +{ + typedef Eina_Bool(*methodType)(Evas_GL *evas_gl, Evas_GL_Surface *surf, + Evas_Native_Surface *ns); + BEFORE_EVAS_GL(evas_gl_native_surface_get); + Eina_Bool res = evas_gl_native_surface_getp(evas_gl, surf, ns); + GL_GET_ERROR(); + AFTER('b', res, APITYPE_CONTEXT, "", "ppp", + evas_gl, surf, ns); + return res; +} + +Evas_GL_API *evas_gl_api_get(Evas_GL *evas_gl) +{ + typedef Evas_GL_API *(*methodType)(Evas_GL *evas_gl); + BEFORE_EVAS_GL(evas_gl_api_get); + Evas_GL_API *res = evas_gl_api_getp(evas_gl); + + GL_GET_ERROR(); + AFTER('p', res, APITYPE_CONTEXT, "", "p", + evas_gl); + return res; +} + diff --git a/probe_graphics/da_gles20_tizen.cpp b/probe_graphics/da_gles20_tizen.cpp index 610950c..2b6f58e 100644 --- a/probe_graphics/da_gles20_tizen.cpp +++ b/probe_graphics/da_gles20_tizen.cpp @@ -38,44 +38,6 @@ static char contextValue[MAX_GL_CONTEXT_VALUE_SIZE]; static enum DaOptions _sopt = OPT_GLES; static __thread GLenum gl_error_external = GL_NO_ERROR; -GLenum glGetError(void); -void glGetIntegerv(GLenum pname, GLint * params); - -static void init_probe_gl(const char *func_name, void **func_pointer, - ORIGINAL_LIBRARY id, int blockresult, int32_t vAPI_ID) -{ - void *faddr; - - probeBlockStart(); - if (lib_handle[id] == ((void *)0)) { - lib_handle[id] = dlopen(lib_string[id], RTLD_LAZY); - if (lib_handle[id] == ((void *)0)) - probe_terminate_with_err("dlopen failed", func_name, id); - - probeInfo_t tempProbeInfo; - setProbePoint(&tempProbeInfo); - if (blockresult != 0) { - /* get max value */ - char maxValString[64]; - GLint maxVal[2]; - glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVal[0]); - glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxVal[1]); - sprintf(maxValString, "%d,%d", maxVal[0], maxVal[1]); - PREPARE_LOCAL_BUF(); - PACK_COMMON_BEGIN(MSG_PROBE_GL, vAPI_ID, "", 0); - PACK_COMMON_END('p', 1, 0, 0); - PACK_GL_ADD(APITYPE_INIT, 0, maxValString); - FLUSH_LOCAL_BUF(); - } - } - - faddr = dlsym(lib_handle[id], func_name); - if (faddr == NULL || dlerror() != NULL) - probe_terminate_with_err("dlopen failed", func_name, id); - - memcpy(func_pointer, &faddr, sizeof(faddr)); - probeBlockEnd(); -} // ================================================================== // A 2 // ================================================================== diff --git a/probe_memory/libdamemmanage.c b/probe_memory/libdamemmanage.c index 7e75780..117259f 100644 --- a/probe_memory/libdamemmanage.c +++ b/probe_memory/libdamemmanage.c @@ -42,6 +42,7 @@ #include "dautil.h" #include "da_memory.h" #include "binproto.h" +#include "common_probe_init.h" static enum DaOptions _sopt = OPT_ALLOC; diff --git a/scripts/api_names.txt b/scripts/api_names.txt index a95ac35..d1ffa3c 100644 --- a/scripts/api_names.txt +++ b/scripts/api_names.txt @@ -285,6 +285,20 @@ ecore_event_evas_mouse_button_down ecore_event_evas_mouse_button_up ecore_event_evas_mouse_move +evas_gl_free +evas_gl_config_free +evas_gl_surface_destroy +evas_gl_context_destroy +evas_gl_new +evas_gl_config_new +evas_gl_surface_create +evas_gl_context_create +evas_gl_make_current +evas_gl_string_query +evas_gl_proc_address_get +evas_gl_native_surface_get +evas_gl_api_get + accept accept4 bind -- 2.7.4