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
This commit is contained in:
Ingo Weinhold
2011-11-01 20:35:49 +00:00
parent 0422a0f3ae
commit f908ff9bb6
4 changed files with 34 additions and 17 deletions
+3 -2
View File
@@ -869,7 +869,7 @@ MemoryManager::PerformMaintenance()
#if SLAB_MEMORY_MANAGER_ALLOCATION_TRACKING #if SLAB_MEMORY_MANAGER_ALLOCATION_TRACKING
/*static*/ bool /*static*/ bool
MemoryManager::AnalyzeAllocationCallers() MemoryManager::AnalyzeAllocationCallers(bool resetAllocationInfos)
{ {
for (AreaTable::Iterator it = sAreaTable.GetIterator(); for (AreaTable::Iterator it = sAreaTable.GetIterator();
Area* area = it.Next();) { Area* area = it.Next();) {
@@ -893,7 +893,8 @@ MemoryManager::AnalyzeAllocationCallers()
size_t size = reference - chunkAddress + 1; size_t size = reference - chunkAddress + 1;
slab_debug_add_allocation_for_caller( slab_debug_add_allocation_for_caller(
_TrackingInfoFor((void*)chunkAddress, size), size); _TrackingInfoFor((void*)chunkAddress, size), size,
resetAllocationInfos);
} }
} }
} }
+2 -1
View File
@@ -60,7 +60,8 @@ public:
static bool MaintenanceNeeded(); static bool MaintenanceNeeded();
static void PerformMaintenance(); static void PerformMaintenance();
static bool AnalyzeAllocationCallers(); static bool AnalyzeAllocationCallers(
bool resetAllocationInfos);
private: private:
struct Tracing; struct Tracing;
+23 -13
View File
@@ -370,8 +370,8 @@ caller_info_compare_count(const void* _a, const void* _b)
bool bool
slab_debug_add_allocation_for_caller(const AllocationTrackingInfo* info, slab_debug_add_allocation_for_caller(AllocationTrackingInfo* info,
size_t allocationSize) size_t allocationSize, bool resetAllocationInfos)
{ {
if (!info->IsInitialized()) if (!info->IsInitialized())
return true; return true;
@@ -394,6 +394,9 @@ slab_debug_add_allocation_for_caller(const AllocationTrackingInfo* info,
callerInfo->count++; callerInfo->count++;
callerInfo->size += allocationSize; callerInfo->size += allocationSize;
if (resetAllocationInfos)
info->Clear();
return true; return true;
} }
@@ -401,13 +404,14 @@ slab_debug_add_allocation_for_caller(const AllocationTrackingInfo* info,
#if SLAB_OBJECT_CACHE_ALLOCATION_TRACKING #if SLAB_OBJECT_CACHE_ALLOCATION_TRACKING
static bool 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(); for (SlabList::ConstIterator it = slabList.GetIterator();
slab* slab = it.Next();) { slab* slab = it.Next();) {
for (uint32 i = 0; i < slab->size; i++) { for (uint32 i = 0; i < slab->size; i++) {
if (!slab_debug_add_allocation_for_caller(&slab->tracking[i], if (!slab_debug_add_allocation_for_caller(&slab->tracking[i],
cache->object_size)) { cache->object_size, resetAllocationInfos)) {
return false; return false;
} }
} }
@@ -418,10 +422,11 @@ analyze_allocation_callers(ObjectCache* cache, const SlabList& slabList)
static bool static bool
analyze_allocation_callers(ObjectCache* cache) analyze_allocation_callers(ObjectCache* cache, bool resetAllocationInfos)
{ {
return analyze_allocation_callers(cache, cache->full) return analyze_allocation_callers(cache, cache->full, resetAllocationInfos)
&& analyze_allocation_callers(cache, cache->partial); && analyze_allocation_callers(cache, cache->partial,
resetAllocationInfos);
} }
#endif // SLAB_OBJECT_CACHE_ALLOCATION_TRACKING #endif // SLAB_OBJECT_CACHE_ALLOCATION_TRACKING
@@ -431,6 +436,7 @@ static int
dump_allocations_per_caller(int argc, char **argv) dump_allocations_per_caller(int argc, char **argv)
{ {
bool sortBySize = true; bool sortBySize = true;
bool resetAllocationInfos = false;
ObjectCache* cache = NULL; ObjectCache* cache = NULL;
for (int32 i = 1; i < argc; i++) { for (int32 i = 1; i < argc; i++) {
@@ -445,6 +451,8 @@ dump_allocations_per_caller(int argc, char **argv)
} }
cache = (ObjectCache*)(addr_t)cacheAddress; cache = (ObjectCache*)(addr_t)cacheAddress;
} else if (strcmp(argv[i], "-r") == 0) {
resetAllocationInfos = true;
} else { } else {
print_debugger_command_usage(argv[0]); print_debugger_command_usage(argv[0]);
return 0; return 0;
@@ -455,7 +463,7 @@ dump_allocations_per_caller(int argc, char **argv)
if (cache != NULL) { if (cache != NULL) {
#if SLAB_OBJECT_CACHE_ALLOCATION_TRACKING #if SLAB_OBJECT_CACHE_ALLOCATION_TRACKING
if (!analyze_allocation_callers(cache)) if (!analyze_allocation_callers(cache, resetAllocationInfos))
return 0; return 0;
#else #else
kprintf("Object cache allocation tracking not available. " kprintf("Object cache allocation tracking not available. "
@@ -469,13 +477,13 @@ dump_allocations_per_caller(int argc, char **argv)
ObjectCacheList::Iterator it = sObjectCaches.GetIterator(); ObjectCacheList::Iterator it = sObjectCaches.GetIterator();
while (it.HasNext()) { while (it.HasNext()) {
if (!analyze_allocation_callers(it.Next())) if (!analyze_allocation_callers(it.Next(), resetAllocationInfos))
return 0; return 0;
} }
#endif #endif
#if SLAB_MEMORY_MANAGER_ALLOCATION_TRACKING #if SLAB_MEMORY_MANAGER_ALLOCATION_TRACKING
if (!MemoryManager::AnalyzeAllocationCallers()) if (!MemoryManager::AnalyzeAllocationCallers(resetAllocationInfos))
return 0; return 0;
#endif #endif
} }
@@ -1061,12 +1069,14 @@ slab_init_post_area()
add_debugger_command_etc("allocations_per_caller", add_debugger_command_etc("allocations_per_caller",
&dump_allocations_per_caller, &dump_allocations_per_caller,
"Dump current heap allocations summed up per caller", "Dump current heap allocations summed up per caller",
"[ \"-c\" ] [ -o <object cache> ]\n" "[ -c ] [ -o <object cache> ] [ -r ]\n"
"The current allocations will by summed up by caller (their count and\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" "size) printed in decreasing order by size or, if \"-c\" is\n"
"specified, by allocation count. If given <object cache> specifies\n" "specified, by allocation count. If given <object cache> specifies\n"
"the address of the object cache for which to print the allocations.\n", "the address of the object cache for which to print the allocations.\n"
0); "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 #endif // SLAB_ALLOCATION_TRACKING_AVAILABLE
} }
+6 -1
View File
@@ -93,8 +93,13 @@ void dump_object_depot(object_depot* depot);
int dump_object_depot(int argCount, char** args); int dump_object_depot(int argCount, char** args);
int dump_depot_magazine(int argCount, char** args); int dump_depot_magazine(int argCount, char** args);
#if SLAB_ALLOCATION_TRACKING_AVAILABLE
bool slab_debug_add_allocation_for_caller( 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 #if PARANOID_KERNEL_MALLOC || PARANOID_KERNEL_FREE