add tbm_surface_internal_set_debug_data function for debugging 37/83337/2
authorChangyeon Lee <cyeon.lee@samsung.com>
Wed, 10 Aug 2016 06:49:51 +0000 (15:49 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Wed, 10 Aug 2016 07:52:49 +0000 (16:52 +0900)
debug data will be print in tbm_bufmgr_debug_show

Change-Id: If351c9e987eb5a397707aae5cd94f79502daf89d

src/tbm_bufmgr.c
src/tbm_bufmgr_int.h
src/tbm_surface_internal.c
src/tbm_surface_internal.h

index bc4bb2a..8586100 100644 (file)
@@ -634,6 +634,9 @@ tbm_bufmgr_init(int fd)
        /* intialize surf_list */
        LIST_INITHEAD(&gBufMgr->surf_list);
 
+       /* intialize debug_key_list */
+       LIST_INITHEAD(&gBufMgr->debug_key_list);
+
        pthread_mutex_unlock(&gLock);
        return gBufMgr;
 }
@@ -1294,6 +1297,9 @@ tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
        int i;
        char app_name[255] = {0,};
        unsigned int pid = 0;
+       char title[255] = {0,};
+       char data[255] = {0,};
+       tbm_surface_debug_data *debug_old_data = NULL, *debug_tmp = NULL;
 
        pthread_mutex_lock(&gLock);
 
@@ -1303,11 +1309,20 @@ tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
        TBM_DEBUG("============TBM DEBUG: %s(%d)===========================\n",
                  app_name, getpid());
        memset(app_name, 0x0, 255 * sizeof(char));
+       snprintf(title, 255, "%s", "no  surface     refcnt  width  height  bpp  size    n_b  n_p  flags  format    app_name       ");
+       if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) {
+               LIST_FOR_EACH_ENTRY_SAFE(debug_old_data, debug_tmp, &bufmgr->debug_key_list, item_link) {
+                       strncat(title, "  ", 2);
+                       strncat(title, debug_old_data->key, strlen(debug_old_data->key) + 1);
+               }
+       }
 
        TBM_DEBUG("[tbm_surface information]\n");
-       TBM_DEBUG("no  surface              refcnt  width  height  bpp  size      num_bos num_planes flags format              app_name\n");
+       TBM_DEBUG("%s\n", title);
        /* show the tbm_surface information in surf_list */
        if (!LIST_IS_EMPTY(&bufmgr->surf_list)) {
+               char *value = NULL;
+
                LIST_FOR_EACH_ENTRY_SAFE(surf, tmp_surf, &bufmgr->surf_list, item_link) {
                        pid = _tbm_surface_internal_get_debug_pid(surf);
                        if (!pid) {
@@ -1318,7 +1333,7 @@ tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
                        _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",
+                       snprintf(data, 255, "%-2d  %-9p    %-4d  %-5d  %-6d  %-3d  %-6d   %-2d   %-2d    %-3d  %-8s  %-15s",
                                  ++surf_cnt,
                                  surf,
                                  surf->refcnt,
@@ -1329,9 +1344,24 @@ 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) + 11,
                                  app_name);
 
+                       if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) {
+                               LIST_FOR_EACH_ENTRY_SAFE(debug_old_data, debug_tmp, &bufmgr->debug_key_list, item_link) {
+                                       strncat(data, "  ", 2);
+
+                                       value = _tbm_surface_internal_get_debug_data(surf, debug_old_data->key);
+                                       if (value) {
+                                               strncat(data, value, strlen(value) + 1);
+                                       }
+                                       else {
+                                               strncat(data, "none", strlen("none") + 1);
+                                       }
+                               }
+                       }
+                       TBM_DEBUG("%s\n", data);
+
                        for (i = 0; i < surf->num_bos; i++) {
                                TBM_DEBUG(" bo:%-12p  %-26d%-10d\n",
                                          surf->bos[i],
@@ -1347,12 +1377,12 @@ tbm_bufmgr_debug_show(tbm_bufmgr bufmgr)
        TBM_DEBUG("\n");
 
        TBM_DEBUG("[tbm_bo information]\n");
-       TBM_DEBUG("no  bo                   refcnt  size     lock_cnt map_cnt flags surface\n");
+       TBM_DEBUG("no  bo          refcnt  size    lock_cnt  map_cnt  flags  surface\n");
 
        /* show the tbm_bo information in bo_list */
        if (!LIST_IS_EMPTY(&bufmgr->bo_list)) {
                LIST_FOR_EACH_ENTRY_SAFE(bo, tmp_bo, &bufmgr->bo_list, item_link) {
-                       TBM_DEBUG("%-4d%-11p   %-6d%-12d%-9d%-9d%-4d%-11p\n",
+                       TBM_DEBUG("%-4d%-11p   %-4d  %-6d     %-5d     %-4d    %-3d  %-11p\n",
                                  ++bo_cnt,
                                  bo,
                                  bo->ref_cnt,
index c27630d..c3e8040 100644 (file)
@@ -241,6 +241,8 @@ struct _tbm_bufmgr {
 
        struct list_head surf_list;     /* list of surfaces belonging to bufmgr */
 
+       struct list_head debug_key_list; /* list of debug data key list belonging to bufmgr */
+
        void *module_data;
 
        tbm_bufmgr_backend backend;     /* bufmgr backend */
@@ -272,6 +274,8 @@ struct _tbm_surface {
        struct list_head item_link; /* link of surface */
 
        struct list_head user_data_list;        /* list of the user_date in surface */
+
+       struct list_head debug_data_list;       /* list of debug data */
 };
 
 typedef struct {
@@ -283,6 +287,14 @@ typedef struct {
        struct list_head item_link;
 } tbm_user_data;
 
+typedef struct {
+       char *key;
+       char *value;
+
+       /* link of user_data */
+       struct list_head item_link;
+} tbm_surface_debug_data;
+
 tbm_bufmgr _tbm_bufmgr_get_bufmgr(void);
 int _tbm_bo_set_surface(tbm_bo bo, tbm_surface_h surface);
 int _tbm_surface_is_valid(tbm_surface_h surface);
@@ -296,6 +308,7 @@ unsigned int tbm_surface_internal_get_height(tbm_surface_h surface);
 tbm_format tbm_surface_internal_get_format(tbm_surface_h surface);
 unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface);
 char *_tbm_surface_internal_format_to_str(tbm_format format);
+char * _tbm_surface_internal_get_debug_data(tbm_surface_h surface, char *key);
 
 tbm_user_data *user_data_lookup(struct list_head *user_data_list,
                                unsigned long key);
index 731f7c9..91c3380 100644 (file)
@@ -67,6 +67,16 @@ _tbm_surface_internal_get_time(void)
        return time / 1000.0;
 }
 
+static void
+_tbm_surface_internal_debug_data_delete(tbm_surface_debug_data *debug_data)
+{
+       LIST_DEL(&debug_data->item_link);
+
+       if (debug_data->key) free(debug_data->key);
+       if (debug_data->value) free(debug_data->value);
+       free(debug_data);
+}
+
 char *
 _tbm_surface_internal_format_to_str(tbm_format format)
 {
@@ -277,6 +287,7 @@ _tbm_surface_internal_destroy(tbm_surface_h surface)
        int i;
        tbm_bufmgr bufmgr = surface->bufmgr;
        tbm_user_data *old_data = NULL, *tmp = NULL;
+       tbm_surface_debug_data *debug_old_data = NULL, *debug_tmp = NULL;
 
        /* destory the user_data_list */
        if (!LIST_IS_EMPTY(&surface->user_data_list)) {
@@ -293,6 +304,11 @@ _tbm_surface_internal_destroy(tbm_surface_h surface)
                surface->bos[i] = NULL;
        }
 
+       if (!LIST_IS_EMPTY(&surface->debug_data_list)) {
+               LIST_FOR_EACH_ENTRY_SAFE(debug_old_data, debug_tmp, &surface->debug_data_list, item_link)
+                       _tbm_surface_internal_debug_data_delete(debug_old_data);
+       }
+
        LIST_DEL(&surface->item_link);
 
        free(surface);
@@ -300,6 +316,13 @@ _tbm_surface_internal_destroy(tbm_surface_h surface)
 
        if (LIST_IS_EMPTY(&bufmgr->surf_list)) {
                LIST_DELINIT(&bufmgr->surf_list);
+
+               if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) {
+                       LIST_FOR_EACH_ENTRY_SAFE(debug_old_data, debug_tmp, &bufmgr->debug_key_list, item_link) {
+                               _tbm_surface_internal_debug_data_delete(debug_old_data);
+                       }
+               }
+
                _deinit_surface_bufmgr();
        }
 }
@@ -685,6 +708,7 @@ tbm_surface_internal_create_with_flags(int width, int height,
                        _tbm_surface_internal_format_to_str(format), flags, surf);
 
        LIST_INITHEAD(&surf->user_data_list);
+       LIST_INITHEAD(&surf->debug_data_list);
 
        LIST_ADD(&surf->item_link, &mgr->surf_list);
 
@@ -797,6 +821,7 @@ tbm_surface_internal_create_with_bos(tbm_surface_info_s *info,
                        info->width, info->height, _tbm_surface_internal_format_to_str(info->format), num);
 
        LIST_INITHEAD(&surf->user_data_list);
+       LIST_INITHEAD(&surf->debug_data_list);
 
        LIST_ADD(&surf->item_link, &mgr->surf_list);
 
@@ -1271,6 +1296,86 @@ tbm_surface_internal_set_debug_pid(tbm_surface_h surface, unsigned int pid)
        surface->debug_pid = pid;
 }
 
+static tbm_surface_debug_data *
+_tbm_surface_internal_debug_data_create(char *key, char *value)
+{
+       tbm_surface_debug_data *debug_data = NULL;
+
+       debug_data = calloc(1, sizeof(tbm_surface_debug_data));
+       if (!debug_data)
+               return NULL;
+
+       if (key) debug_data->key = strdup(key);
+       if (value) debug_data->value = strdup(value);
+
+       return debug_data;
+}
+
+int
+tbm_surface_internal_set_debug_data(tbm_surface_h surface, char *key, char *value)
+{
+       TBM_RETURN_VAL_IF_FAIL(tbm_surface_internal_is_valid(surface), 0);
+       TBM_RETURN_VAL_IF_FAIL(key, 0);
+
+       tbm_surface_debug_data *debug_data = NULL;
+       tbm_surface_debug_data *old_data = NULL, *tmp = NULL;
+       tbm_bufmgr bufmgr = surface->bufmgr;
+
+       TBM_RETURN_VAL_IF_FAIL(bufmgr, 0);
+
+       if (!LIST_IS_EMPTY(&surface->debug_data_list)) {
+               LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, &surface->debug_data_list, item_link) {
+                       if (!strcmp(old_data->key ,key)) {
+                               if (value)
+                                       old_data->value = strdup(value);
+                               else
+                                       old_data->value = NULL;
+                       }
+               }
+       }
+
+       debug_data = _tbm_surface_internal_debug_data_create(key, value);
+       if (!debug_data) {
+               TBM_TRACE("error: tbm_surface(%p) key(%s) value(%s)\n", surface, key, value);
+               return 0;
+       }
+
+       TBM_TRACE("tbm_surface(%p) key(%s) value(%s)\n", surface, key, value);
+
+       LIST_ADD(&debug_data->item_link, &surface->debug_data_list);
+
+       if (!LIST_IS_EMPTY(&bufmgr->debug_key_list)) {
+               LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, &bufmgr->debug_key_list, item_link) {
+                       if (!strcmp(old_data->key ,key)) {
+                               return 1;
+                       }
+               }
+       }
+
+       debug_data = _tbm_surface_internal_debug_data_create(key, NULL);
+       LIST_ADD(&debug_data->item_link, &bufmgr->debug_key_list);
+
+       return 1;
+}
+
+char *
+_tbm_surface_internal_get_debug_data(tbm_surface_h surface, char *key)
+{
+       TBM_RETURN_VAL_IF_FAIL(tbm_surface_internal_is_valid(surface), NULL);
+
+       tbm_surface_debug_data *old_data = NULL, *tmp = NULL;
+
+       if (!LIST_IS_EMPTY(&surface->debug_data_list)) {
+               LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, &surface->debug_data_list, item_link) {
+                       if (!strcmp(old_data->key, key)) {
+                               return old_data->value;
+                       }
+               }
+       }
+
+       return NULL;
+}
+
 typedef struct _tbm_surface_dump_info tbm_surface_dump_info;
 typedef struct _tbm_surface_dump_buf_info tbm_surface_dump_buf_info;
 
@@ -1562,7 +1667,6 @@ tbm_surface_internal_dump_end(void)
                }
        }
 
-
        /* free resources */
        if (!LIST_IS_EMPTY(&g_dump_info->surface_list)) {
                LIST_FOR_EACH_ENTRY_SAFE(buf_info, tmp, &g_dump_info->surface_list, link) {
index e31c8d9..be88d50 100644 (file)
@@ -350,6 +350,16 @@ void tbm_surface_internal_set_debug_pid(tbm_surface_h surface,
                                        unsigned int pid);
 
 /**
+ * @brief Set the string value to the tbm_surface for debugging.
+ * @since_tizen 3.0
+ * @param[in] surface : the tbm_surface_h
+ * @param[in] key : the key for debugging
+ * @param[in] value : the value for debugging
+ */
+int tbm_surface_internal_set_debug_data(tbm_surface_h surface,
+                                       char *key, char *value);
+
+/**
  * @brief Adds a user_data to the tbm surface.
  * @since_tizen 3.0
  * @param[in] surface : the tbm surface.