From d1b78b29d64216e4df4b4f1ee14d89c7e3ae6a6f Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Tue, 15 Dec 2015 17:46:27 +0900 Subject: [PATCH] set debug_pid to the surface print application name with this debug_pid. Change-Id: If0ec80d3ac2bb02d8f06e18cd1d15c117aa70c40 --- src/tbm_bufmgr.c | 75 ++++++++++++++++++++++++++++++++++++++++++++-- src/tbm_bufmgr_int.h | 4 +++ src/tbm_surface_internal.c | 17 +++++++++++ src/tbm_surface_internal.h | 8 +++++ 4 files changed, 101 insertions(+), 3 deletions(-) mode change 100644 => 100755 src/tbm_surface_internal.h diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index 2e092f5..a2e79dc 100755 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -107,6 +107,58 @@ _tbm_set_last_result(tbm_error_e err) tbm_last_error = err; } +static void +_tbm_util_get_appname_brief(char *brief) +{ + char delim[] = "/"; + char *token = NULL; + char temp[255] = {0,}; + char *saveptr = NULL; + + token = strtok_r(brief, delim, &saveptr); + + while (token != NULL) { + memset(temp, 0x00, 255*sizeof(char)); + strncpy(temp, token, 254*sizeof(char)); + token = strtok_r(NULL, delim, &saveptr); + } + + snprintf(brief, sizeof(temp), "%s", temp); +} + +static void +_tbm_util_get_appname_from_pid(long pid, char *str) +{ + FILE* fp; + int len; + long app_pid = pid; + char fn_cmdline[255] = {0,}; + char cmdline[255] = {0,}; + + snprintf(fn_cmdline, sizeof(fn_cmdline), "/proc/%ld/cmdline",app_pid); + + fp = fopen(fn_cmdline, "r"); + if(fp == 0) { + fprintf(stderr,"cannot file open /proc/%ld/cmdline", app_pid); + return; + } + + if (!fgets(cmdline, 255, fp)) { + fprintf(stderr, "fail to get appname for pid(%ld)\n", app_pid); + fclose(fp); + return; + } + fclose(fp); + + len = strlen(cmdline); + if(len < 1) + memset(cmdline, 0x00,255); + else + cmdline[len] = 0; + + snprintf(str, sizeof(cmdline), "%s", cmdline); +} + static inline int _tgl_init (int fd, unsigned int key) { @@ -1708,10 +1760,15 @@ tbm_bufmgr_debug_show (tbm_bufmgr bufmgr) tbm_surface_h surf = NULL, tmp_surf = NULL; int surf_cnt = 0; int i; + char app_name[255] = {0,}; + unsigned int pid = 0; pthread_mutex_lock (&gLock); - TBM_DEBUG("============TBM DEBUG: PID(%d)===========================\n", getpid()); + _tbm_util_get_appname_from_pid(getpid(), app_name); + _tbm_util_get_appname_brief(app_name); + TBM_DEBUG("============TBM DEBUG: %s(%d)===========================\n", app_name, getpid()); + memset(app_name, 0x0, 255*sizeof(char)); TBM_DEBUG("[tbm_surface information]\n"); TBM_DEBUG("no surface refcnt width height bpp size num_bos num_planes flags format app_name\n"); @@ -1720,7 +1777,16 @@ tbm_bufmgr_debug_show (tbm_bufmgr bufmgr) { LIST_FOR_EACH_ENTRY_SAFE (surf, tmp_surf, &bufmgr->surf_list, item_link) { - TBM_DEBUG("%-4d%-23p%-6d%-7d%-8d%-5d%-12d%-10d%-9d%-4d%-20s\n", + pid = _tbm_surface_internal_get_debug_pid(surf); + if (!pid) { + /* if pid is null, set the self_pid */ + pid = getpid(); + } + + _tbm_util_get_appname_from_pid(pid, app_name); + _tbm_util_get_appname_brief(app_name); + + TBM_DEBUG("%-4d%-23p%-6d%-7d%-8d%-5d%-12d%-10d%-9d%-4d%-20s%s\n", ++surf_cnt, surf, surf->refcnt, @@ -1731,7 +1797,8 @@ tbm_bufmgr_debug_show (tbm_bufmgr bufmgr) surf->num_bos, surf->num_planes, surf->flags, - _tbm_surface_internal_format_to_str(surf->info.format)); + _tbm_surface_internal_format_to_str(surf->info.format), + app_name); for (i = 0; i < surf->num_bos; i++) { TBM_DEBUG(" bo:%-11p(key:%2d) %-26d%-10d\n", surf->bos[i], @@ -1739,6 +1806,8 @@ tbm_bufmgr_debug_show (tbm_bufmgr bufmgr) surf->bos[i]->ref_cnt, tbm_bo_size(surf->bos[i])/1024); } + + memset(app_name, 0x0, 255*sizeof(char)); } } else diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h index 5d46572..e9647f8 100755 --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -200,6 +200,8 @@ struct _tbm_surface { int refcnt; + unsigned int debug_pid; + struct list_head item_link; /* link of surface */ }; @@ -215,6 +217,8 @@ unsigned int tbm_surface_internal_get_width (tbm_surface_h surface); unsigned int tbm_surface_internal_get_height (tbm_surface_h surface); tbm_format tbm_surface_internal_get_format (tbm_surface_h surface); char *_tbm_surface_internal_format_to_str(tbm_format format); +unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface); + #endif /* _TBM_BUFMGR_INT_H_ */ diff --git a/src/tbm_surface_internal.c b/src/tbm_surface_internal.c index 71bf485..a8cd287 100755 --- a/src/tbm_surface_internal.c +++ b/src/tbm_surface_internal.c @@ -937,3 +937,20 @@ tbm_surface_internal_get_plane_bo_idx (tbm_surface_h surface, int plane_idx) return bo_idx; } +unsigned int +_tbm_surface_internal_get_debug_pid(tbm_surface_h surface) +{ + TBM_RETURN_VAL_IF_FAIL (surface, 0); + + return surface->debug_pid; +} + +void +tbm_surface_internal_set_debug_pid(tbm_surface_h surface, unsigned int pid) +{ + TBM_RETURN_IF_FAIL (surface); + + surface->debug_pid = pid; +} + + diff --git a/src/tbm_surface_internal.h b/src/tbm_surface_internal.h old mode 100644 new mode 100755 index a9ada40..6e9ae20 --- a/src/tbm_surface_internal.h +++ b/src/tbm_surface_internal.h @@ -337,6 +337,14 @@ int tbm_surface_internal_get_bpp (tbm_format format); */ int tbm_surface_internal_get_plane_bo_idx (tbm_surface_h surface, int plane_idx); +/** + * @brief Set the pid to the tbm_surface for debugging. + * @since_tizen 3.0 + * @param[in] surface : the tbm_surface_h + * @param[in] pid : the pid + */ +void tbm_surface_internal_set_debug_pid(tbm_surface_h surface, unsigned int pid); + #ifdef __cplusplus } #endif -- 2.7.4