From 8ac77194373f016f501a9db0787a10926aa2648e Mon Sep 17 00:00:00 2001 From: Neti Ravi Kumar Date: Wed, 28 Dec 2011 10:31:23 +0530 Subject: [PATCH] Dump PMEM usage in out of memory cases for debugging (cherry picked from commit 87e533f5a605e5fa99f84aeb8869d5f084369c6d) Change-Id: I0f4b99c115b36144587cc770cb3722b89d7cffbd --- libgralloc/pmem_bestfit_alloc.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libgralloc/pmem_bestfit_alloc.cpp b/libgralloc/pmem_bestfit_alloc.cpp index d13317e..e3875e9 100644 --- a/libgralloc/pmem_bestfit_alloc.cpp +++ b/libgralloc/pmem_bestfit_alloc.cpp @@ -125,6 +125,36 @@ ssize_t SimpleBestFitAllocator::alloc(size_t size, uint32_t flags) } return (free_chunk->start)*kMemoryAlign; } + // we are out of PMEM. Print pmem stats + // check if there is any leak or fragmentation + + LOGD (" Out of PMEM. Dumping PMEM stats for debugging"); + LOGD (" ------------- PRINT PMEM STATS --------------"); + + cur = mList.head(); + static uint32_t node_count; + static uint64_t allocated, free_space; + + while (cur) { + LOGD (" Node %d -> Start Address : %u Size %u Free info %d",\ + node_count++, cur->start, cur->size, cur->free); + + // if cur-> free is 1 , the node is free + // calculate the total allocated and total free stats also + + if (cur->free) + free_space += cur->size; + else + allocated += cur->size; + // read next node + cur = cur->next; + } + LOGD (" Total Allocated: %l Total Free: %l", allocated, free_space ); + + node_count = 0; + allocated = 0; + free_space = 0; + LOGD ("----------------------------------------------"); return -ENOMEM; }