FastAlloc: track allocation tick in debug mode,
minor enhancements to debug output
This commit is contained in:
parent
fff9c93568
commit
c370a9cb98
2 changed files with 55 additions and 10 deletions
|
@ -75,12 +75,13 @@ FastAlloc::moreStructs(int bucket)
|
||||||
|
|
||||||
#if FAST_ALLOC_DEBUG
|
#if FAST_ALLOC_DEBUG
|
||||||
|
|
||||||
#include <iomanip>
|
|
||||||
#include <iostream>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
|
||||||
|
#include "base/cprintf.hh"
|
||||||
|
#include "sim/core.hh" // for curTick
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
// count of in-use FastAlloc objects
|
// count of in-use FastAlloc objects
|
||||||
|
@ -103,6 +104,7 @@ FastAlloc::FastAlloc()
|
||||||
{
|
{
|
||||||
// mark this object in use
|
// mark this object in use
|
||||||
inUse = true;
|
inUse = true;
|
||||||
|
whenAllocated = curTick;
|
||||||
|
|
||||||
// update count
|
// update count
|
||||||
++numInUse;
|
++numInUse;
|
||||||
|
@ -131,6 +133,13 @@ FastAlloc::~FastAlloc()
|
||||||
inUseNext->inUsePrev = inUsePrev;
|
inUseNext->inUsePrev = inUsePrev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Note that in all the display functions below we suppress anything
|
||||||
|
// with a zero allocation timestamp... there are a bunch of static or
|
||||||
|
// quasi-static structures that get allocated during initialization
|
||||||
|
// and we generally don't care about them so this gets them out of the
|
||||||
|
// way.
|
||||||
|
|
||||||
// summarize in-use list
|
// summarize in-use list
|
||||||
void
|
void
|
||||||
FastAlloc::dump_summary()
|
FastAlloc::dump_summary()
|
||||||
|
@ -139,17 +148,19 @@ FastAlloc::dump_summary()
|
||||||
|
|
||||||
for (FastAlloc *p = inUseHead.inUseNext; p != &inUseHead; p = p->inUseNext)
|
for (FastAlloc *p = inUseHead.inUseNext; p != &inUseHead; p = p->inUseNext)
|
||||||
{
|
{
|
||||||
|
if (p->whenAllocated != 0)
|
||||||
++typemap[typeid(*p).name()];
|
++typemap[typeid(*p).name()];
|
||||||
}
|
}
|
||||||
|
|
||||||
map<string, int>::const_iterator mapiter;
|
map<string, int>::const_iterator mapiter;
|
||||||
|
|
||||||
cout << " count type\n"
|
cprintf(" count type\n"
|
||||||
<< " ----- ----\n";
|
" ----- ----\n");
|
||||||
for (mapiter = typemap.begin(); mapiter != typemap.end(); ++mapiter)
|
for (mapiter = typemap.begin(); mapiter != typemap.end(); ++mapiter)
|
||||||
cout << setw(6) << mapiter->second << " " << mapiter->first << endl;
|
cprintf("%6d %s\n",mapiter->second, mapiter->first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// show oldest n items on in-use list
|
// show oldest n items on in-use list
|
||||||
void
|
void
|
||||||
FastAlloc::dump_oldest(int n)
|
FastAlloc::dump_oldest(int n)
|
||||||
|
@ -157,16 +168,44 @@ FastAlloc::dump_oldest(int n)
|
||||||
// sanity check: don't want to crash the debugger if you forget to
|
// sanity check: don't want to crash the debugger if you forget to
|
||||||
// pass in a parameter
|
// pass in a parameter
|
||||||
if (n < 0 || n > numInUse) {
|
if (n < 0 || n > numInUse) {
|
||||||
cout << "FastAlloc::dump_oldest: bad arg " << n
|
cprintf("FastAlloc::dump_oldest: bad arg %d (%d objects in use)\n",
|
||||||
<< " (" << numInUse << " objects in use" << endl;
|
n, numInUse);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FastAlloc *p = inUseHead.inUseNext;
|
for (FastAlloc *p = inUseHead.inUseNext;
|
||||||
p != &inUseHead && n > 0;
|
p != &inUseHead && n > 0;
|
||||||
p = p->inUseNext, --n)
|
p = p->inUseNext, --n) {
|
||||||
cout << p << " " << typeid(*p).name() << endl;
|
if (p->whenAllocated != 0)
|
||||||
|
cprintf("%x %15d %s\n", p, p->whenAllocated, typeid(*p).name());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// show oldest n items on in-use list for specified type
|
||||||
|
void
|
||||||
|
FastAlloc::dump_oldest_of_type(int n, const char *type_name)
|
||||||
|
{
|
||||||
|
// sanity check: don't want to crash the debugger if you forget to
|
||||||
|
// pass in a parameter
|
||||||
|
if (n < 0 || n > numInUse) {
|
||||||
|
cprintf("FastAlloc::dump_oldest_of_type: bad arg %d "
|
||||||
|
"(%d objects in use)\n",
|
||||||
|
n, numInUse);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (FastAlloc *p = inUseHead.inUseNext;
|
||||||
|
p != &inUseHead && n > 0;
|
||||||
|
p = p->inUseNext) {
|
||||||
|
if (p->whenAllocated != 0 &&
|
||||||
|
strcmp(typeid(*p).name(), type_name) == 0) {
|
||||||
|
cprintf("%x %15d\n", p, p->whenAllocated);
|
||||||
|
--n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// C interfaces to FastAlloc::dump_summary() and FastAlloc::dump_oldest().
|
// C interfaces to FastAlloc::dump_summary() and FastAlloc::dump_oldest().
|
||||||
|
|
|
@ -74,6 +74,10 @@ class FastAlloc
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#if FAST_ALLOC_DEBUG
|
||||||
|
#include "sim/host.hh" // for Tick
|
||||||
|
#endif
|
||||||
|
|
||||||
class FastAlloc
|
class FastAlloc
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -127,6 +131,7 @@ class FastAlloc
|
||||||
bool inUse; // in-use flag
|
bool inUse; // in-use flag
|
||||||
FastAlloc *inUsePrev; // ptrs to build list of in-use objects
|
FastAlloc *inUsePrev; // ptrs to build list of in-use objects
|
||||||
FastAlloc *inUseNext;
|
FastAlloc *inUseNext;
|
||||||
|
Tick whenAllocated;
|
||||||
|
|
||||||
// static (global) debugging vars
|
// static (global) debugging vars
|
||||||
static int numInUse; // count in-use objects
|
static int numInUse; // count in-use objects
|
||||||
|
@ -137,6 +142,7 @@ class FastAlloc
|
||||||
// versions that might be more agreeable to call from gdb)
|
// versions that might be more agreeable to call from gdb)
|
||||||
static void dump_summary();
|
static void dump_summary();
|
||||||
static void dump_oldest(int n);
|
static void dump_oldest(int n);
|
||||||
|
static void dump_oldest_of_type(int n, const char *type_name);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue