diff options
Diffstat (limited to 'indra/llcommon')
-rwxr-xr-x | indra/llcommon/llcommon.cpp | 14 | ||||
-rwxr-xr-x | indra/llcommon/llfasttimer.cpp | 2 | ||||
-rwxr-xr-x | indra/llcommon/llthread.cpp | 2 | ||||
-rw-r--r-- | indra/llcommon/lltrace.cpp | 26 | ||||
-rw-r--r-- | indra/llcommon/lltrace.h | 68 | ||||
-rw-r--r-- | indra/llcommon/lltraceaccumulators.h | 7 | ||||
-rw-r--r-- | indra/llcommon/lltracethreadrecorder.cpp | 14 | ||||
-rw-r--r-- | indra/llcommon/lltracethreadrecorder.h | 10 |
8 files changed, 79 insertions, 64 deletions
diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp index c720df7555..96ec0cdefe 100755 --- a/indra/llcommon/llcommon.cpp +++ b/indra/llcommon/llcommon.cpp @@ -30,10 +30,13 @@ #include "llmemory.h" #include "llthread.h" #include "lltrace.h" +#include "lltracethreadrecorder.h" //static BOOL LLCommon::sAprInitialized = FALSE; +static LLTrace::ThreadRecorder* sMasterThreadRecorder = NULL; + //static void LLCommon::initClass() { @@ -45,13 +48,20 @@ void LLCommon::initClass() } LLTimer::initClass(); LLThreadSafeRefCount::initThreadSafeRefCount(); - LLTrace::init(); + + if (!sMasterThreadRecorder) + { + sMasterThreadRecorder = new LLTrace::ThreadRecorder(); + LLTrace::set_master_thread_recorder(sMasterThreadRecorder); + } } //static void LLCommon::cleanupClass() { - LLTrace::cleanup(); + delete sMasterThreadRecorder; + sMasterThreadRecorder = NULL; + LLTrace::set_master_thread_recorder(NULL); LLThreadSafeRefCount::cleanupThreadSafeRefCount(); LLTimer::cleanupClass(); if (sAprInitialized) diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 7a7f1c79c1..a72f16d385 100755 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -250,7 +250,7 @@ void TimeBlock::updateTimes() { // walk up stack of active timers and accumulate current time while leaving timing structures active BlockTimerStackRecord* stack_record = LLThreadLocalSingletonPointer<BlockTimerStackRecord>::getInstance(); - if (stack_record) return; + if (!stack_record) return; U64 cur_time = getCPUClockCount64(); BlockTimer* cur_timer = stack_record->mActiveTimer; diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index d07cccdf15..166a4eb26d 100755 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -93,7 +93,7 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap { LLThread *threadp = (LLThread *)datap; - LLTrace::ThreadRecorder thread_recorder(LLTrace::getUIThreadRecorder()); + LLTrace::ThreadRecorder thread_recorder(*LLTrace::get_master_thread_recorder()); #if !LL_DARWIN sThreadID = threadp->mID; diff --git a/indra/llcommon/lltrace.cpp b/indra/llcommon/lltrace.cpp index 26c19e5121..3dffbe6d4a 100644 --- a/indra/llcommon/lltrace.cpp +++ b/indra/llcommon/lltrace.cpp @@ -30,34 +30,26 @@ #include "lltracethreadrecorder.h" #include "llfasttimer.h" -static S32 sInitializationCount = 0; - namespace LLTrace { -void init() +TraceBase::TraceBase( const char* name, const char* description ) +: mName(name), + mDescription(description ? description : "") { - if (sInitializationCount++ == 0) +#ifndef LL_RELEASE_FOR_DOWNLOAD + if (LLTrace::get_master_thread_recorder() != NULL) { - gUIThreadRecorder = new ThreadRecorder(); + llerrs << "Attempting to declare trace object after program initialization. Trace objects should be statically initialized." << llendl; } +#endif } -bool isInitialized() +const char* TraceBase::getUnitLabel() { - return sInitializationCount > 0; + return ""; } -void cleanup() -{ - if (--sInitializationCount == 0) - { - delete gUIThreadRecorder; - gUIThreadRecorder = NULL; - } -} - - TimeBlockTreeNode::TimeBlockTreeNode() : mBlock(NULL), mParent(NULL), diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 72ef51c232..1cde450dc2 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -53,19 +53,29 @@ STORAGE_TYPE storage_value(LLUnit<STORAGE_TYPE, UNIT_TYPE> val) { return val.val template<typename UNIT_TYPE, typename STORAGE_TYPE> STORAGE_TYPE storage_value(LLUnitImplicit<STORAGE_TYPE, UNIT_TYPE> val) { return val.value(); } -void init(); -void cleanup(); -bool isInitialized(); +class TraceBase +{ +public: + TraceBase(const char* name, const char* description); + virtual ~TraceBase() {}; + virtual const char* getUnitLabel(); + + const std::string& getName() const { return mName; } + +protected: + const std::string mName; + const std::string mDescription; +}; template<typename ACCUMULATOR> class TraceType -: public LLInstanceTracker<TraceType<ACCUMULATOR>, std::string> +: public TraceBase, + public LLInstanceTracker<TraceType<ACCUMULATOR>, std::string> { public: TraceType(const char* name, const char* description = NULL) : LLInstanceTracker<TraceType<ACCUMULATOR>, std::string>(name), - mName(name), - mDescription(description ? description : ""), + TraceBase(name, description), mAccumulatorIndex(AccumulatorBuffer<ACCUMULATOR>::getDefaultBuffer()->reserveSlot()) {} @@ -78,13 +88,7 @@ public: size_t getIndex() const { return mAccumulatorIndex; } static size_t getNumIndices() { return AccumulatorBuffer<ACCUMULATOR>::getNumIndices(); } - virtual const char* getUnitLabel() { return ""; } - - const std::string& getName() const { return mName; } - -protected: - const std::string mName; - const std::string mDescription; +private: const size_t mAccumulatorIndex; }; @@ -320,7 +324,7 @@ class MemTrackable template<typename TRACKED, typename TRACKED_IS_TRACKER> struct TrackMemImpl; - typedef MemTrackable<DERIVED> mem_trackable_t; + typedef MemTrackable<DERIVED, ALIGNMENT> mem_trackable_t; public: typedef void mem_trackable_tag_t; @@ -332,7 +336,7 @@ public: void* operator new(size_t size) { - MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = mem_trackable_t::sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mSize.sample(accumulator->mSize.getLastValue() + (F64)size); @@ -344,7 +348,7 @@ public: void operator delete(void* ptr, size_t size) { - MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = mem_trackable_t::sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mSize.sample(accumulator->mSize.getLastValue() - (F64)size); @@ -356,7 +360,7 @@ public: void *operator new [](size_t size) { - MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = mem_trackable_t::sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mSize.sample(accumulator->mSize.getLastValue() + (F64)size); @@ -368,7 +372,7 @@ public: void operator delete[](void* ptr, size_t size) { - MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = mem_trackable_t::sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mSize.sample(accumulator->mSize.getLastValue() - (F64)size); @@ -394,14 +398,16 @@ public: } - void memClaimAmount(size_t size) + template<typename AMOUNT_T> + AMOUNT_T& memClaimAmount(AMOUNT_T& size) { - MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); - mMemFootprint += size; + MemStatAccumulator* accumulator = sMemStat.getPrimaryAccumulator(); + mMemFootprint += (size_t)size; if (accumulator) { accumulator->mSize.sample(accumulator->mSize.getLastValue() + (F64)size); } + return size; } // remove memory we had claimed from our calculated footprint @@ -419,24 +425,28 @@ public: return value; } - void memDisclaimAmount(size_t size) + template<typename AMOUNT_T> + AMOUNT_T& memDisclaimAmount(AMOUNT_T& size) { - MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mSize.sample(accumulator->mSize.getLastValue() - (F64)size); } + return size; } private: size_t mMemFootprint; + static MemStatHandle sMemStat; + template<typename TRACKED, typename TRACKED_IS_TRACKER = void> struct TrackMemImpl { static void claim(mem_trackable_t& tracker, const TRACKED& tracked) { - MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = sMemStat.getPrimaryAccumulator(); if (accumulator) { size_t footprint = MemFootprint<TRACKED>::measure(tracked); @@ -447,7 +457,7 @@ private: static void disclaim(mem_trackable_t& tracker, const TRACKED& tracked) { - MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = sMemStat.getPrimaryAccumulator(); if (accumulator) { size_t footprint = MemFootprint<TRACKED>::measure(tracked); @@ -462,7 +472,7 @@ private: { static void claim(mem_trackable_t& tracker, TRACKED& tracked) { - MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mChildSize.sample(accumulator->mChildSize.getLastValue() + (F64)MemFootprint<TRACKED>::measure(tracked)); @@ -471,7 +481,7 @@ private: static void disclaim(mem_trackable_t& tracker, TRACKED& tracked) { - MemStatAccumulator* accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator* accumulator = sMemStat.getPrimaryAccumulator(); if (accumulator) { accumulator->mChildSize.sample(accumulator->mChildSize.getLastValue() - (F64)MemFootprint<TRACKED>::measure(tracked)); @@ -480,5 +490,9 @@ private: }; }; +template<typename DERIVED, size_t ALIGNMENT> +MemStatHandle MemTrackable<DERIVED, ALIGNMENT>::sMemStat(typeid(DERIVED).name()); + + } #endif // LL_LLTRACE_H diff --git a/indra/llcommon/lltraceaccumulators.h b/indra/llcommon/lltraceaccumulators.h index 825cc9e3a8..fac6347ff9 100644 --- a/indra/llcommon/lltraceaccumulators.h +++ b/indra/llcommon/lltraceaccumulators.h @@ -33,6 +33,7 @@ #include "llunit.h" #include "lltimer.h" #include "llrefcount.h" +#include "llthreadlocalstorage.h" namespace LLTrace { @@ -142,12 +143,6 @@ namespace LLTrace // NOTE: this is not thread-safe. We assume that slots are reserved in the main thread before any child threads are spawned size_t reserveSlot() { -#ifndef LL_RELEASE_FOR_DOWNLOAD - if (LLTrace::isInitialized()) - { - llerrs << "Attempting to declare trace object after program initialization. Trace objects should be statically initialized." << llendl; - } -#endif size_t next_slot = sNextStorageSlot++; if (next_slot >= mStorageSize) { diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index e88c5bf177..7ac0e75154 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -31,13 +31,14 @@ namespace LLTrace { -ThreadRecorder* gUIThreadRecorder = NULL; +static ThreadRecorder* sMasterThreadRecorder = NULL; /////////////////////////////////////////////////////////////////////// // ThreadRecorder /////////////////////////////////////////////////////////////////////// ThreadRecorder::ThreadRecorder() +: mMasterRecorder(NULL) { init(); } @@ -268,10 +269,15 @@ void ThreadRecorder::pullFromChildren() } -ThreadRecorder& getUIThreadRecorder() +void set_master_thread_recorder(ThreadRecorder* recorder) { - llassert(gUIThreadRecorder != NULL); - return *gUIThreadRecorder; + sMasterThreadRecorder = recorder; +} + + +ThreadRecorder* get_master_thread_recorder() +{ + return sMasterThreadRecorder; } LLThreadLocalPointer<ThreadRecorder>& get_thread_recorder_ptr() diff --git a/indra/llcommon/lltracethreadrecorder.h b/indra/llcommon/lltracethreadrecorder.h index b5ed77416c..535f855200 100644 --- a/indra/llcommon/lltracethreadrecorder.h +++ b/indra/llcommon/lltracethreadrecorder.h @@ -92,13 +92,11 @@ namespace LLTrace }; - //FIXME: let user code set up thread recorder topology - extern ThreadRecorder* gUIThreadRecorder ; - - const LLThreadLocalPointer<class ThreadRecorder>& get_thread_recorder(); - void set_thread_recorder(class ThreadRecorder*); - ThreadRecorder& getUIThreadRecorder(); + const LLThreadLocalPointer<ThreadRecorder>& get_thread_recorder(); + void set_thread_recorder(ThreadRecorder*); + void set_master_thread_recorder(ThreadRecorder*); + ThreadRecorder* get_master_thread_recorder(); } #endif // LL_LLTRACETHREADRECORDER_H |