From f908ff9bb658aa86aa53760c51070415e69f951d Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 1 Nov 2011 20:35:49 +0000 Subject: [PATCH] mmlr + bonefish: * Fix build broken in r43078. The slab_debug_add_allocation_for_caller() wasn't guarded correctly. * slab_debug_add_allocation_for_caller(): Add bool resetAllocationInfos parameter, which makes the function clear the allocation tracking infos after processing the data. * "allocations_per_caller" KDL command: Add option "-r" to reset the allocation tracking infos. The next invocation of the command will only show the allocations made after the reset. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43079 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/slab/MemoryManager.cpp | 5 ++-- src/system/kernel/slab/MemoryManager.h | 3 +- src/system/kernel/slab/Slab.cpp | 36 +++++++++++++++--------- src/system/kernel/slab/slab_debug.h | 7 ++++- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/system/kernel/slab/MemoryManager.cpp b/src/system/kernel/slab/MemoryManager.cpp index f242455541..21c70e2fc1 100644 --- a/src/system/kernel/slab/MemoryManager.cpp +++ b/src/system/kernel/slab/MemoryManager.cpp @@ -869,7 +869,7 @@ MemoryManager::PerformMaintenance() #if SLAB_MEMORY_MANAGER_ALLOCATION_TRACKING /*static*/ bool -MemoryManager::AnalyzeAllocationCallers() +MemoryManager::AnalyzeAllocationCallers(bool resetAllocationInfos) { for (AreaTable::Iterator it = sAreaTable.GetIterator(); Area* area = it.Next();) { @@ -893,7 +893,8 @@ MemoryManager::AnalyzeAllocationCallers() size_t size = reference - chunkAddress + 1; slab_debug_add_allocation_for_caller( - _TrackingInfoFor((void*)chunkAddress, size), size); + _TrackingInfoFor((void*)chunkAddress, size), size, + resetAllocationInfos); } } } diff --git a/src/system/kernel/slab/MemoryManager.h b/src/system/kernel/slab/MemoryManager.h index 4adcf2f433..df2c6af94b 100644 --- a/src/system/kernel/slab/MemoryManager.h +++ b/src/system/kernel/slab/MemoryManager.h @@ -60,7 +60,8 @@ public: static bool MaintenanceNeeded(); static void PerformMaintenance(); - static bool AnalyzeAllocationCallers(); + static bool AnalyzeAllocationCallers( + bool resetAllocationInfos); private: struct Tracing; diff --git a/src/system/kernel/slab/Slab.cpp b/src/system/kernel/slab/Slab.cpp index 22f65899aa..3dc5e63615 100644 --- a/src/system/kernel/slab/Slab.cpp +++ b/src/system/kernel/slab/Slab.cpp @@ -370,8 +370,8 @@ caller_info_compare_count(const void* _a, const void* _b) bool -slab_debug_add_allocation_for_caller(const AllocationTrackingInfo* info, - size_t allocationSize) +slab_debug_add_allocation_for_caller(AllocationTrackingInfo* info, + size_t allocationSize, bool resetAllocationInfos) { if (!info->IsInitialized()) return true; @@ -394,6 +394,9 @@ slab_debug_add_allocation_for_caller(const AllocationTrackingInfo* info, callerInfo->count++; callerInfo->size += allocationSize; + if (resetAllocationInfos) + info->Clear(); + return true; } @@ -401,13 +404,14 @@ slab_debug_add_allocation_for_caller(const AllocationTrackingInfo* info, #if SLAB_OBJECT_CACHE_ALLOCATION_TRACKING static bool -analyze_allocation_callers(ObjectCache* cache, const SlabList& slabList) +analyze_allocation_callers(ObjectCache* cache, const SlabList& slabList, + bool resetAllocationInfos) { for (SlabList::ConstIterator it = slabList.GetIterator(); slab* slab = it.Next();) { for (uint32 i = 0; i < slab->size; i++) { if (!slab_debug_add_allocation_for_caller(&slab->tracking[i], - cache->object_size)) { + cache->object_size, resetAllocationInfos)) { return false; } } @@ -418,10 +422,11 @@ analyze_allocation_callers(ObjectCache* cache, const SlabList& slabList) static bool -analyze_allocation_callers(ObjectCache* cache) +analyze_allocation_callers(ObjectCache* cache, bool resetAllocationInfos) { - return analyze_allocation_callers(cache, cache->full) - && analyze_allocation_callers(cache, cache->partial); + return analyze_allocation_callers(cache, cache->full, resetAllocationInfos) + && analyze_allocation_callers(cache, cache->partial, + resetAllocationInfos); } #endif // SLAB_OBJECT_CACHE_ALLOCATION_TRACKING @@ -431,6 +436,7 @@ static int dump_allocations_per_caller(int argc, char **argv) { bool sortBySize = true; + bool resetAllocationInfos = false; ObjectCache* cache = NULL; for (int32 i = 1; i < argc; i++) { @@ -445,6 +451,8 @@ dump_allocations_per_caller(int argc, char **argv) } cache = (ObjectCache*)(addr_t)cacheAddress; + } else if (strcmp(argv[i], "-r") == 0) { + resetAllocationInfos = true; } else { print_debugger_command_usage(argv[0]); return 0; @@ -455,7 +463,7 @@ dump_allocations_per_caller(int argc, char **argv) if (cache != NULL) { #if SLAB_OBJECT_CACHE_ALLOCATION_TRACKING - if (!analyze_allocation_callers(cache)) + if (!analyze_allocation_callers(cache, resetAllocationInfos)) return 0; #else kprintf("Object cache allocation tracking not available. " @@ -469,13 +477,13 @@ dump_allocations_per_caller(int argc, char **argv) ObjectCacheList::Iterator it = sObjectCaches.GetIterator(); while (it.HasNext()) { - if (!analyze_allocation_callers(it.Next())) + if (!analyze_allocation_callers(it.Next(), resetAllocationInfos)) return 0; } #endif #if SLAB_MEMORY_MANAGER_ALLOCATION_TRACKING - if (!MemoryManager::AnalyzeAllocationCallers()) + if (!MemoryManager::AnalyzeAllocationCallers(resetAllocationInfos)) return 0; #endif } @@ -1061,12 +1069,14 @@ slab_init_post_area() add_debugger_command_etc("allocations_per_caller", &dump_allocations_per_caller, "Dump current heap allocations summed up per caller", - "[ \"-c\" ] [ -o ]\n" + "[ -c ] [ -o ] [ -r ]\n" "The current allocations will by summed up by caller (their count and\n" "size) printed in decreasing order by size or, if \"-c\" is\n" "specified, by allocation count. If given specifies\n" - "the address of the object cache for which to print the allocations.\n", - 0); + "the address of the object cache for which to print the allocations.\n" + "If \"-r\" is given, the allocation infos are reset after gathering\n" + "the information, so the next command invocation will only show the\n" + "allocations made after the reset.\n", 0); #endif // SLAB_ALLOCATION_TRACKING_AVAILABLE } diff --git a/src/system/kernel/slab/slab_debug.h b/src/system/kernel/slab/slab_debug.h index 0181d61ee5..bc356b11a3 100644 --- a/src/system/kernel/slab/slab_debug.h +++ b/src/system/kernel/slab/slab_debug.h @@ -93,8 +93,13 @@ void dump_object_depot(object_depot* depot); int dump_object_depot(int argCount, char** args); int dump_depot_magazine(int argCount, char** args); +#if SLAB_ALLOCATION_TRACKING_AVAILABLE + bool slab_debug_add_allocation_for_caller( - const AllocationTrackingInfo* info, size_t allocationSize); + AllocationTrackingInfo* info, size_t allocationSize, + bool resetAllocationInfos); + +#endif // SLAB_ALLOCATION_TRACKING_AVAILABLE #if PARANOID_KERNEL_MALLOC || PARANOID_KERNEL_FREE