SH-3468 WIP add memory tracking base class

attempted fix for gcc compile errors
can't use typeid() on a class that doesn't have a method
defined in a translation unit
fix is to force classes deriving from LLMemTrackable to
use their own static member named sMemStat
master
Richard Linden 2013-01-04 13:48:35 -08:00
parent b2197101c4
commit cbff0e7ab8
13 changed files with 36 additions and 21 deletions

View File

@ -660,13 +660,13 @@ struct MemFootprint<std::list<T> >
}
};
template<typename T>
template<typename DERIVED>
class MemTrackable
{
template<typename TRACKED, typename TRACKED_IS_TRACKER>
struct TrackMemImpl;
typedef MemTrackable<T> mem_trackable_t;
typedef MemTrackable<DERIVED> mem_trackable_t;
public:
typedef void mem_trackable_tag_t;
@ -681,7 +681,7 @@ public:
// reserve 8 bytes for allocation size (and preserving 8 byte alignment of structs)
void* allocation = ::operator new(allocation_size + 8);
*(size_t*)allocation = allocation_size;
MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator();
MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator();
if (accumulator)
{
accumulator->mSize += allocation_size;
@ -693,7 +693,7 @@ public:
void operator delete(void* ptr)
{
size_t* allocation_size = (size_t*)((char*)ptr - 8);
MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator();
MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator();
if (accumulator)
{
accumulator->mSize -= *allocation_size;
@ -707,7 +707,7 @@ public:
{
size_t* result = (size_t*)malloc(size + 8);
*result = size;
MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator();
MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator();
if (accumulator)
{
accumulator->mSize += size;
@ -719,7 +719,7 @@ public:
void operator delete[](void* ptr)
{
size_t* allocation_size = (size_t*)((char*)ptr - 8);
MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator();
MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator();
if (accumulator)
{
accumulator->mSize -= *allocation_size;
@ -747,7 +747,7 @@ public:
void memClaim(size_t size)
{
MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator();
MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator();
mMemFootprint += size;
if (accumulator)
{
@ -772,7 +772,7 @@ public:
void memDisclaim(size_t size)
{
MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator();
MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator();
if (accumulator)
{
accumulator->mSize -= size;
@ -788,7 +788,7 @@ private:
{
static void claim(mem_trackable_t& tracker, const TRACKED& tracked)
{
MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator();
MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator();
if (accumulator)
{
size_t footprint = MemFootprint<TRACKED>::measure(tracked);
@ -799,7 +799,7 @@ private:
static void disclaim(mem_trackable_t& tracker, const TRACKED& tracked)
{
MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator();
MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator();
if (accumulator)
{
size_t footprint = MemFootprint<TRACKED>::measure(tracked);
@ -814,7 +814,7 @@ private:
{
static void claim(mem_trackable_t& tracker, TRACKED& tracked)
{
MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator();
MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator();
if (accumulator)
{
accumulator->mChildSize += MemFootprint<TRACKED>::measure(tracked);
@ -823,17 +823,14 @@ private:
static void disclaim(mem_trackable_t& tracker, TRACKED& tracked)
{
MemStatAccumulator* accumulator = sStat.getPrimaryAccumulator();
MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator();
if (accumulator)
{
accumulator->mChildSize -= MemFootprint<TRACKED>::measure(tracked);
}
}
};
static MemStat sStat;
};
template<typename T> MemStat MemTrackable<T>::sStat(typeid(T).name());
}
#endif // LL_LLTRACE_H

View File

@ -50,6 +50,7 @@ LLMutex* LLImage::sMutex = NULL;
bool LLImage::sUseNewByteRange = false;
S32 LLImage::sMinimalReverseByteRangePercent = 75;
LLPrivateMemoryPool* LLImageBase::sPrivatePoolp = NULL ;
LLTrace::MemStat LLImage::sMemStat("LLImage");
//static
void LLImage::initClass(bool use_new_byte_range, S32 minimal_reverse_byte_range_percent)

View File

@ -165,6 +165,8 @@ public:
static void destroyPrivatePool() ;
static LLPrivateMemoryPool* getPrivatePool() {return sPrivatePoolp;}
static LLTrace::MemStat sMemStat;
private:
U8 *mData;
S32 mDataSize;

View File

@ -47,6 +47,8 @@
const F32 CURSOR_FLASH_DELAY = 1.0f; // in seconds
const S32 CURSOR_THICKNESS = 2;
LLTrace::MemStat LLTextSegment::sMemStat("LLTextSegment");
LLTextBase::line_info::line_info(S32 index_start, S32 index_end, LLRect rect, S32 line_num)
: mDocIndexStart(index_start),
mDocIndexEnd(index_end),

View File

@ -94,10 +94,12 @@ public:
/*virtual*/ void localPointToScreen(S32 local_x, S32 local_y, S32* screen_x, S32* screen_y) const;
/*virtual*/ BOOL hasMouseCapture();
S32 getStart() const { return mStart; }
void setStart(S32 start) { mStart = start; }
S32 getEnd() const { return mEnd; }
void setEnd( S32 end ) { mEnd = end; }
S32 getStart() const { return mStart; }
void setStart(S32 start) { mStart = start; }
S32 getEnd() const { return mEnd; }
void setEnd( S32 end ) { mEnd = end; }
static LLTrace::MemStat sMemStat;
protected:
S32 mStart;

View File

@ -67,6 +67,7 @@ LLView* LLView::sPreviewClickedElement = NULL;
BOOL LLView::sDrawPreviewHighlights = FALSE;
S32 LLView::sLastLeftXML = S32_MIN;
S32 LLView::sLastBottomXML = S32_MIN;
LLTrace::MemStat LLView::sMemStat("LLView");
std::vector<LLViewDrawContext*> LLViewDrawContext::sDrawContextStack;
LLView::DrilldownFunc LLView::sDrilldown =

View File

@ -673,6 +673,7 @@ public:
static S32 sLastLeftXML;
static S32 sLastBottomXML;
static BOOL sForceReshape;
static LLTrace::MemStat sMemStat;
};
class LLCompareByTabOrder

View File

@ -35,6 +35,8 @@
// external library headers
// other Linden headers
LLTrace::MemStat LLViewModel::sMemStat("LLViewModel");
///
LLViewModel::LLViewModel()
: mDirty(false)

View File

@ -83,6 +83,8 @@ public:
//
void setDirty() { mDirty = true; }
static LLTrace::MemStat sMemStat;
protected:
LLSD mValue;
bool mDirty;

View File

@ -58,6 +58,7 @@ const F32 MIN_SHADOW_CASTER_RADIUS = 2.0f;
static LLFastTimer::DeclareTimer FTM_CULL_REBOUND("Cull Rebound");
extern bool gShiftFrame;
LLTrace::MemStat LLDrawable::sMemStat("LLDrawable");
////////////////////////

View File

@ -314,6 +314,7 @@ public:
LLSpatialBridge* getSpatialBridge() { return (LLSpatialBridge*) (LLDrawable*) mSpatialBridge; }
static F32 sCurPixelAngle; //current pixels per radian
static LLTrace::MemStat sMemStat;
private:
typedef std::vector<LLFace*> face_list_t;

View File

@ -112,6 +112,9 @@ BOOL LLViewerObject::sMapDebug = TRUE;
LLColor4 LLViewerObject::sEditSelectColor( 1.0f, 1.f, 0.f, 0.3f); // Edit OK
LLColor4 LLViewerObject::sNoEditSelectColor( 1.0f, 0.f, 0.f, 0.3f); // Can't edit
S32 LLViewerObject::sAxisArrowLength(50);
LLTrace::MemStat LLViewerObject::sMemStat("LLViewerObject");
BOOL LLViewerObject::sPulseEnabled(FALSE);
BOOL LLViewerObject::sUseSharedDrawables(FALSE); // TRUE

View File

@ -670,8 +670,6 @@ protected:
void deleteParticleSource();
void setParticleSource(const LLPartSysData& particle_parameters, const LLUUID& owner_id);
public:
private:
void setNameValueList(const std::string& list); // clears nv pairs and then individually adds \n separated NV pairs from \0 terminated string
void deleteTEImages(); // correctly deletes list of images
@ -750,6 +748,8 @@ protected:
static S32 sAxisArrowLength;
static LLTrace::MemStat sMemStat;
// These two caches are only correct for non-parented objects right now!
mutable LLVector3 mPositionRegion;
mutable LLVector3 mPositionAgent;