From: Roman Marchenko Date: Thu, 17 Aug 2017 16:39:23 +0000 (+0300) Subject: tbm_bufmgr_debug: change signature of tbm_bufmgr_debug_tbm_info_get X-Git-Tag: accepted/tizen/4.0/unified/20170829.020611~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F44%2F144744%2F4;p=platform%2Fcore%2Fuifw%2Flibtbm.git tbm_bufmgr_debug: change signature of tbm_bufmgr_debug_tbm_info_get Change-Id: I575b38c41a1a4a53ecd7c497caba508deceb877e Signed-off-by: Roman Marchenko --- diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index 130f29c..3f8343d 100644 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -1495,24 +1495,34 @@ tbm_get_last_error(void) return tbm_last_error; } -void -tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr, char *str, int *len) +char * +tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr) { char app_name[255] = {0,}, title[512] = {0,}; tbm_surface_debug_data *debug_old_data = NULL; + char *str; + int len = 1024*4; + int c = 0; pthread_mutex_lock(&gLock); if (!TBM_BUFMGR_IS_VALID(bufmgr) || (bufmgr != gBufMgr)) { TBM_LOG_E("invalid bufmgr\n"); pthread_mutex_unlock(&gLock); - return; + return NULL; + } + + str = malloc(len); + if (!str) { + TBM_LOG_E("Fail to allocate the string.\n"); + pthread_mutex_unlock(&gLock); + return NULL; } - TBM_SNPRINTF(str, len, "\n"); + TBM_SNRPRINTF(str, len, c, "\n"); _tbm_util_get_appname_from_pid(getpid(), app_name); _tbm_util_get_appname_brief(app_name); - TBM_SNPRINTF(str, len, "============TBM DEBUG: %s(%d)===========================\n", + TBM_SNRPRINTF(str, len, c, "============TBM DEBUG: %s(%d)===========================\n", app_name, getpid()); snprintf(title, 255, "%s", "no surface refcnt width height bpp size n_b n_p flags format app_name "); @@ -1524,8 +1534,8 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr, char *str, int *len) } } - TBM_SNPRINTF(str, len, "[tbm_surface information]\n"); - TBM_SNPRINTF(str, len, "%s\n", title); + TBM_SNRPRINTF(str, len, c, "[tbm_surface information]\n"); + TBM_SNRPRINTF(str, len, c, "%s\n", title); /* show the tbm_surface information in surf_list */ if (!LIST_IS_EMPTY(&bufmgr->surf_list)) { @@ -1574,21 +1584,21 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr, char *str, int *len) strncat(data, "none", MAX_SIZE_N(title)); } } - TBM_SNPRINTF(str, len, "%s\n", data); + TBM_SNRPRINTF(str, len, c, "%s\n", data); for (i = 0; i < surf->num_bos; i++) { - TBM_SNPRINTF(str, len, " bo:%-12p %-26d%-10d\n", + TBM_SNRPRINTF(str, len, c, " bo:%-12p %-26d%-10d\n", surf->bos[i], surf->bos[i]->ref_cnt, bufmgr->backend->bo_size(surf->bos[i]) / 1024); } } } else - TBM_SNPRINTF(str, len, " no tbm_surfaces.\n"); - TBM_SNPRINTF(str, len, "\n"); + TBM_SNRPRINTF(str, len, c, " no tbm_surfaces.\n"); + TBM_SNRPRINTF(str, len, c, "\n"); - TBM_SNPRINTF(str, len, "[tbm_bo information]\n"); - TBM_SNPRINTF(str, len, "no bo refcnt size lock_cnt map_cnt flags surface name\n"); + TBM_SNRPRINTF(str, len, c, "[tbm_bo information]\n"); + TBM_SNRPRINTF(str, len, c, "no bo refcnt size lock_cnt map_cnt flags surface name\n"); /* show the tbm_bo information in bo_list */ if (!LIST_IS_EMPTY(&bufmgr->bo_list)) { @@ -1596,7 +1606,7 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr, char *str, int *len) tbm_bo bo = NULL; LIST_FOR_EACH_ENTRY(bo, &bufmgr->bo_list, item_link) { - TBM_SNPRINTF(str, len, "%-4d%-11p %-4d %-6d %-5d %-4u %-3d %-11p %-4d\n", + TBM_SNRPRINTF(str, len, c, "%-4d%-11p %-4d %-6d %-5d %-4u %-3d %-11p %-4d\n", ++bo_cnt, bo, bo->ref_cnt, @@ -1608,21 +1618,25 @@ tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr, char *str, int *len) tbm_bo_export(bo)); } } else - TBM_SNPRINTF(str, len, "no tbm_bos.\n"); - TBM_SNPRINTF(str, len, "\n"); + TBM_SNRPRINTF(str, len, c, "no tbm_bos.\n"); + TBM_SNRPRINTF(str, len, c, "\n"); - TBM_SNPRINTF(str, len, "===============================================================\n"); + TBM_SNRPRINTF(str, len, c, "===============================================================\n"); pthread_mutex_unlock(&gLock); + + return str; } void tbm_bufmgr_debug_show(tbm_bufmgr bufmgr) { - char str[1024*4]; - int len = sizeof(str); - tbm_bufmgr_debug_tbm_info_get(bufmgr, str, &len); - TBM_DEBUG(" %s", str); + char * str; + str = tbm_bufmgr_debug_tbm_info_get(bufmgr); + if (str) { + TBM_DEBUG(" %s", str); + free(str); + } } void diff --git a/src/tbm_bufmgr.h b/src/tbm_bufmgr.h index 7d89204..e386bea 100644 --- a/src/tbm_bufmgr.h +++ b/src/tbm_bufmgr.h @@ -1029,13 +1029,12 @@ int tbm_bo_get_flags(tbm_bo bo); void tbm_bufmgr_debug_show(tbm_bufmgr bufmgr); /** - * @brief Print out to str the information of tbm_bos. + * @brief Get string with the information of tbm_bos. * @since_tizen 3.0 * @param[in] bufmgr : the buffer manager - * @param[out] str : - * @param[out] len : + * @return sting with info if this function succeeds, otherwise NULL. It has to be free by user. */ -void tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr, char * str, int * len); +char * tbm_bufmgr_debug_tbm_info_get(tbm_bufmgr bufmgr); /** * @brief Print out the trace of tbm_bos. diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h index 57b73bc..92262fd 100644 --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -197,19 +197,21 @@ extern int bDlog; surf->item_link.next->prev == &surf->item_link) -#define TBM_SNPRINTF(p, len, fmt, ARG...) \ +#define TBM_SNRPRINTF(p, len, count, fmt, ARG...) \ do { \ - if (p && len && *len > 0) { \ - int s = snprintf(p, *len, fmt, ##ARG); \ - p += s; \ - *len -= s; \ - } \ - else { \ - TBM_DEBUG(fmt, ##ARG);\ + if (p) { \ + int rest = len - count; \ + int s = snprintf(&p[count], rest, fmt, ##ARG); \ + while (s >= rest) { \ + len *= 2; \ + p = realloc(p, len); \ + rest = len - count; \ + s = snprintf(&p[count], rest, fmt, ##ARG); \ + } \ + count += s; \ } \ } while (0) - struct list_head { struct list_head *prev; struct list_head *next;