mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-05 17:16:50 +08:00
[mpp_buffer]: Add mem and buffer usage function
Change-Id: I356ef9311802868fe8d234dbff178ad8463985d0 Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
This commit is contained in:
@@ -309,6 +309,9 @@ MppBufferType mpp_buffer_group_type(MppBufferGroup group);
|
||||
*/
|
||||
MPP_RET mpp_buffer_group_limit_config(MppBufferGroup group, size_t size, RK_S32 count);
|
||||
|
||||
RK_U32 mpp_buffer_total_now();
|
||||
RK_U32 mpp_buffer_total_max();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -77,6 +77,9 @@ private:
|
||||
RK_U32 finalizing;
|
||||
RK_U32 finished;
|
||||
|
||||
RK_U32 total_size;
|
||||
RK_U32 total_max;
|
||||
|
||||
// misc group for internal / externl buffer with different type
|
||||
MppBufferGroupImpl *misc[MPP_BUFFER_MODE_BUTT][MPP_BUFFER_TYPE_BUTT];
|
||||
RK_U32 misc_count;
|
||||
@@ -105,6 +108,10 @@ public:
|
||||
MppBufferGroupImpl *get_group_by_id(RK_U32 id);
|
||||
void dump_misc_group();
|
||||
RK_U32 is_finalizing();
|
||||
void inc_total(RK_U32 size);
|
||||
void dec_total(RK_U32 size);
|
||||
RK_U32 get_total_now() { return total_size; };
|
||||
RK_U32 get_total_max() { return total_max; };
|
||||
};
|
||||
|
||||
static const char *mode2str[MPP_BUFFER_MODE_BUTT] = {
|
||||
@@ -211,6 +218,9 @@ static MPP_RET deinit_buffer_no_lock(MppBufferImpl *buffer, const char *caller)
|
||||
group->usage -= buffer->info.size;
|
||||
group->buffer_count--;
|
||||
|
||||
if (group->mode == MPP_BUFFER_INTERNAL)
|
||||
MppBufferService::get_instance()->dec_total(buffer->info.size);
|
||||
|
||||
buffer_group_add_log(group, buffer, BUF_DESTROY, caller);
|
||||
|
||||
if (group->is_orphan && !group->usage && !group->is_finalizing) {
|
||||
@@ -301,6 +311,8 @@ MPP_RET mpp_buffer_create(const char *tag, const char *caller,
|
||||
ret = MPP_ERR_MALLOC;
|
||||
goto RET;
|
||||
}
|
||||
if (group->mode == MPP_BUFFER_INTERNAL)
|
||||
MppBufferService::get_instance()->inc_total(info->size);
|
||||
|
||||
p->info = *info;
|
||||
p->mode = group->mode;
|
||||
@@ -581,6 +593,30 @@ void mpp_buffer_service_dump()
|
||||
MppBufferService::get_instance()->dump_misc_group();
|
||||
}
|
||||
|
||||
void MppBufferService::inc_total(RK_U32 size)
|
||||
{
|
||||
total_size += size;
|
||||
if (total_size > total_max)
|
||||
total_max = total_size;
|
||||
}
|
||||
|
||||
void MppBufferService::dec_total(RK_U32 size)
|
||||
{
|
||||
total_size -= size;
|
||||
}
|
||||
|
||||
RK_U32 mpp_buffer_total_now()
|
||||
{
|
||||
AutoMutex auto_lock(MppBufferService::get_lock());
|
||||
return MppBufferService::get_instance()->get_total_now();
|
||||
}
|
||||
|
||||
RK_U32 mpp_buffer_total_max()
|
||||
{
|
||||
AutoMutex auto_lock(MppBufferService::get_lock());
|
||||
return MppBufferService::get_instance()->get_total_max();
|
||||
}
|
||||
|
||||
MppBufferGroupImpl *mpp_buffer_get_misc_group(MppBufferMode mode, MppBufferType type)
|
||||
{
|
||||
AutoMutex auto_lock(MppBufferService::get_lock());
|
||||
@@ -606,6 +642,8 @@ MppBufferService::MppBufferService()
|
||||
group_count(0),
|
||||
finalizing(0),
|
||||
finished(0),
|
||||
total_size(0),
|
||||
total_max(0),
|
||||
misc_count(0)
|
||||
{
|
||||
RK_S32 i, j;
|
||||
|
@@ -56,6 +56,8 @@ void *mpp_osal_realloc(const char *caller, void *ptr, size_t size);
|
||||
void mpp_osal_free(const char *caller, void *ptr);
|
||||
|
||||
void mpp_show_mem_status();
|
||||
RK_U32 mpp_mem_total_now();
|
||||
RK_U32 mpp_mem_total_max();
|
||||
|
||||
/*
|
||||
* mpp memory usage snapshot tool
|
||||
|
@@ -121,6 +121,8 @@ public:
|
||||
size_t size_0, size_t size_1);
|
||||
|
||||
void dump(const char *caller);
|
||||
RK_U32 total_now(void) { return m_total_size; }
|
||||
RK_U32 total_max(void) { return m_total_max; }
|
||||
|
||||
Mutex lock;
|
||||
RK_U32 debug;
|
||||
@@ -144,7 +146,8 @@ private:
|
||||
RK_S32 log_cnt;
|
||||
|
||||
MppMemLog *logs;
|
||||
RK_U32 total_size;
|
||||
RK_U32 m_total_size;
|
||||
RK_U32 m_total_max;
|
||||
|
||||
MppMemService(const MppMemService &);
|
||||
MppMemService &operator=(const MppMemService &);
|
||||
@@ -208,7 +211,8 @@ MppMemService::MppMemService()
|
||||
log_idx(0),
|
||||
log_cnt(0),
|
||||
logs(NULL),
|
||||
total_size(0)
|
||||
m_total_size(0),
|
||||
m_total_max(0)
|
||||
{
|
||||
mpp_env_get_u32("mpp_mem_debug", &debug, 0);
|
||||
|
||||
@@ -303,7 +307,7 @@ void MppMemService::add_node(const char *caller, void *ptr, size_t size)
|
||||
|
||||
if (debug & MEM_NODE_LOG)
|
||||
mpp_log("mem cnt: %5d total %8d inc size %8d at %s\n",
|
||||
nodes_cnt, total_size, size, caller);
|
||||
nodes_cnt, m_total_size, size, caller);
|
||||
|
||||
if (nodes_cnt >= nodes_max) {
|
||||
mpp_err("******************************************************\n");
|
||||
@@ -327,7 +331,9 @@ void MppMemService::add_node(const char *caller, void *ptr, size_t size)
|
||||
nodes_idx = 0;
|
||||
|
||||
nodes_cnt++;
|
||||
total_size += size;
|
||||
m_total_size += size;
|
||||
if (m_total_size > m_total_max)
|
||||
m_total_max = m_total_size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -364,11 +370,11 @@ void MppMemService::del_node(const char *caller, void *ptr, size_t *size)
|
||||
*size = node->size;
|
||||
node->index = ~node->index;
|
||||
nodes_cnt--;
|
||||
total_size -= node->size;
|
||||
m_total_size -= node->size;
|
||||
|
||||
if (debug & MEM_NODE_LOG)
|
||||
mpp_log("mem cnt: %5d total %8d dec size %8d at %s\n",
|
||||
nodes_cnt, total_size, node->size, caller);
|
||||
nodes_cnt, m_total_size, node->size, caller);
|
||||
return ;
|
||||
}
|
||||
}
|
||||
@@ -399,7 +405,7 @@ void *MppMemService::delay_del_node(const char *caller, void *ptr, size_t *size)
|
||||
MPP_MEM_ASSERT(i < nodes_max);
|
||||
if (debug & MEM_NODE_LOG)
|
||||
mpp_log("mem cnt: %5d total %8d dec size %8d at %s\n",
|
||||
nodes_cnt, total_size, node->size, caller);
|
||||
nodes_cnt, m_total_size, node->size, caller);
|
||||
|
||||
MppMemNode *free_node = NULL;
|
||||
|
||||
@@ -453,7 +459,7 @@ void *MppMemService::delay_del_node(const char *caller, void *ptr, size_t *size)
|
||||
memset(node->ptr, MEM_CHECK_MARK, node->size);
|
||||
|
||||
node->index = ~node->index;
|
||||
total_size -= node->size;
|
||||
m_total_size -= node->size;
|
||||
nodes_cnt--;
|
||||
|
||||
return ret;
|
||||
@@ -535,14 +541,14 @@ void MppMemService::reset_node(const char *caller, void *ptr, void *ret, size_t
|
||||
|
||||
if (debug & MEM_NODE_LOG)
|
||||
mpp_log("mem cnt: %5d total %8d equ size %8d at %s\n",
|
||||
nodes_cnt, total_size, size, __FUNCTION__);
|
||||
nodes_cnt, m_total_size, size, __FUNCTION__);
|
||||
|
||||
MPP_MEM_ASSERT(nodes_cnt <= nodes_max);
|
||||
|
||||
for (i = 0; i < nodes_max; i++, node++) {
|
||||
if (node->index >= 0 && node->ptr == ptr) {
|
||||
total_size += size;
|
||||
total_size -= node->size;
|
||||
m_total_size += size;
|
||||
m_total_size -= node->size;
|
||||
|
||||
node->ptr = ret;
|
||||
node->size = size;
|
||||
@@ -746,3 +752,15 @@ void mpp_show_mem_status()
|
||||
if (service.debug & MEM_DEBUG_EN)
|
||||
service.dump(__FUNCTION__);
|
||||
}
|
||||
|
||||
RK_U32 mpp_mem_total_now()
|
||||
{
|
||||
AutoMutex auto_lock(&service.lock);
|
||||
return service.total_now();
|
||||
}
|
||||
|
||||
RK_U32 mpp_mem_total_max()
|
||||
{
|
||||
AutoMutex auto_lock(&service.lock);
|
||||
return service.total_max();
|
||||
}
|
||||
|
Reference in New Issue
Block a user