diff options
Diffstat (limited to 'indra/llcommon')
-rwxr-xr-x | indra/llcommon/lldate.cpp | 6 | ||||
-rwxr-xr-x | indra/llcommon/lldefs.h | 3 | ||||
-rwxr-xr-x | indra/llcommon/llfasttimer.cpp | 6 | ||||
-rwxr-xr-x | indra/llcommon/llfasttimer.h | 32 | ||||
-rwxr-xr-x | indra/llcommon/llpreprocessor.h | 7 | ||||
-rwxr-xr-x | indra/llcommon/llsdparam.cpp | 2 | ||||
-rwxr-xr-x | indra/llcommon/llsdparam.h | 4 | ||||
-rwxr-xr-x | indra/llcommon/llstring.cpp | 6 | ||||
-rw-r--r-- | indra/llcommon/lltrace.h | 100 | ||||
-rw-r--r-- | indra/llcommon/lltracethreadrecorder.cpp | 4 |
10 files changed, 131 insertions, 39 deletions
diff --git a/indra/llcommon/lldate.cpp b/indra/llcommon/lldate.cpp index 4f2e1304b2..b32c3f6830 100755 --- a/indra/llcommon/lldate.cpp +++ b/indra/llcommon/lldate.cpp @@ -86,11 +86,11 @@ std::string LLDate::asRFC1123() const return toHTTPDateString (std::string ("%A, %d %b %Y %H:%M:%S GMT")); } -LLFastTimer::DeclareTimer FT_DATE_FORMAT("Date Format"); +LLTrace::TimeBlock FT_DATE_FORMAT("Date Format"); std::string LLDate::toHTTPDateString (std::string fmt) const { - LLFastTimer ft1(FT_DATE_FORMAT); + LL_RECORD_BLOCK_TIME(FT_DATE_FORMAT); time_t locSeconds = (time_t) mSecondsSinceEpoch; struct tm * gmt = gmtime (&locSeconds); @@ -99,7 +99,7 @@ std::string LLDate::toHTTPDateString (std::string fmt) const std::string LLDate::toHTTPDateString (tm * gmt, std::string fmt) { - LLFastTimer ft1(FT_DATE_FORMAT); + LL_RECORD_BLOCK_TIME(FT_DATE_FORMAT); // avoid calling setlocale() unnecessarily - it's expensive. static std::string prev_locale = ""; diff --git a/indra/llcommon/lldefs.h b/indra/llcommon/lldefs.h index d57b9dccff..5a4b8325f4 100755 --- a/indra/llcommon/lldefs.h +++ b/indra/llcommon/lldefs.h @@ -244,8 +244,5 @@ inline void llswap(LLDATATYPE& lhs, LLDATATYPE& rhs) rhs = tmp; } -#define LL_GLUE_IMPL(x, y) x##y -#define LL_GLUE_TOKENS(x, y) LL_GLUE_IMPL(x, y) - #endif // LL_LLDEFS_H diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index 2235eb1a08..be240c754a 100755 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -276,13 +276,13 @@ void TimeBlock::updateTimes() } } -static LLFastTimer::DeclareTimer FTM_PROCESS_TIMES("Process FastTimer Times"); +static LLTrace::TimeBlock FTM_PROCESS_TIMES("Process FastTimer Times"); // not thread safe, so only call on main thread //static void TimeBlock::processTimes() { - LLFastTimer _(FTM_PROCESS_TIMES); + LL_RECORD_BLOCK_TIME(FTM_PROCESS_TIMES); get_clock_count(); // good place to calculate clock frequency // set up initial tree @@ -413,7 +413,7 @@ void TimeBlock::writeLog(std::ostream& os) LLSDSerialize::toXML(sd, os); LLMutexLock lock(sLogLock); sLogQueue.pop(); - } + } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 7bad6134c5..e6bf544b51 100755 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -35,28 +35,56 @@ class LLMutex; +#define LL_RECORD_BLOCK_TIME(timer_stat) const LLTrace::BlockTimer& LL_GLUE_TOKENS(block_time_recorder, __LINE__)(LLTrace::timeThisBlock(timer_stat)); (void)LL_GLUE_TOKENS(block_time_recorder, __LINE__); + namespace LLTrace { +class BlockTimer timeThisBlock(class TimeBlock& timer); + class BlockTimer { public: - friend class TimeBlock; typedef BlockTimer self_t; typedef class TimeBlock DeclareTimer; - BlockTimer(TimeBlock& timer); ~BlockTimer(); F64Seconds getElapsedTime(); private: + friend class TimeBlock; + // FIXME: this friendship exists so that each thread can instantiate a root timer, + // which could be a derived class with a public constructor instead, possibly + friend class ThreadRecorder; + friend BlockTimer timeThisBlock(TimeBlock&); + BlockTimer(TimeBlock& timer); +#if !defined(MSC_VER) || MSC_VER < 1700 + // Visual Studio 2010 has a bug where capturing an object returned by value + // into a local reference requires access to the copy constructor at the call site. + // This appears to be fixed in 2012. +public: +#endif + // no-copy + BlockTimer(const BlockTimer& other) {}; + +private: U64 mStartTime; U64 mBlockStartTotalTimeCounter; BlockTimerStackRecord mParentTimerData; }; +// this dummy function assists in allocating a block timer with stack-based lifetime. +// this is done by capturing the return value in a stack-allocated const reference variable. +// (This is most easily done using the macro LL_RECORD_BLOCK_TIME) +// Otherwise, it would be possible to store a BlockTimer on the heap, resulting in non-nested lifetimes, +// which would break the invariants of the timing hierarchy logic +LL_FORCE_INLINE class BlockTimer timeThisBlock(class TimeBlock& timer) +{ + return BlockTimer(timer); +} + // stores a "named" timer instance to be reused via multiple BlockTimer stack instances class TimeBlock : public TraceType<TimeBlockAccumulator>, diff --git a/indra/llcommon/llpreprocessor.h b/indra/llcommon/llpreprocessor.h index 0fcc872690..309165da7f 100755 --- a/indra/llcommon/llpreprocessor.h +++ b/indra/llcommon/llpreprocessor.h @@ -191,9 +191,12 @@ #define LL_TO_STRING_HELPER(x) #x #define LL_TO_STRING(x) LL_TO_STRING_HELPER(x) -#define LL_FILE_LINENO(msg) __FILE__ "(" LL_TO_STRING(__LINE__) ") : " msg +#define LL_FILE_LINENO_MSG(msg) __FILE__ "(" LL_TO_STRING(__LINE__) ") : " msg +#define LL_GLUE_IMPL(x, y) x##y +#define LL_GLUE_TOKENS(x, y) LL_GLUE_IMPL(x, y) + #if LL_WINDOWS -#define LL_COMPILE_TIME_MESSAGE(msg) __pragma(message(LL_FILE_LINENO(msg))) +#define LL_COMPILE_TIME_MESSAGE(msg) __pragma(message(LL_FILE_LINENO_MSG(msg))) #else // no way to get gcc 4.2 to print a user-defined diagnostic message only when a macro is used #define LL_COMPILE_TIME_MESSAGE(msg) diff --git a/indra/llcommon/llsdparam.cpp b/indra/llcommon/llsdparam.cpp index c1ba777543..371bd49c04 100755 --- a/indra/llcommon/llsdparam.cpp +++ b/indra/llcommon/llsdparam.cpp @@ -37,7 +37,7 @@ static LLInitParam::Parser::parser_write_func_map_t sWriteFuncs; static LLInitParam::Parser::parser_inspect_func_map_t sInspectFuncs; static const LLSD NO_VALUE_MARKER; -LLFastTimer::DeclareTimer FTM_SD_PARAM_ADAPTOR("LLSD to LLInitParam conversion"); +LLTrace::TimeBlock FTM_SD_PARAM_ADAPTOR("LLSD to LLInitParam conversion"); // // LLParamSDParser diff --git a/indra/llcommon/llsdparam.h b/indra/llcommon/llsdparam.h index 7cfc265c62..47ec6414dd 100755 --- a/indra/llcommon/llsdparam.h +++ b/indra/llcommon/llsdparam.h @@ -110,7 +110,7 @@ private: }; -extern LL_COMMON_API LLFastTimer::DeclareTimer FTM_SD_PARAM_ADAPTOR; +extern LL_COMMON_API LLTrace::TimeBlock FTM_SD_PARAM_ADAPTOR; template<typename T> class LLSDParamAdapter : public T { @@ -118,7 +118,7 @@ public: LLSDParamAdapter() {} LLSDParamAdapter(const LLSD& sd) { - LLFastTimer _(FTM_SD_PARAM_ADAPTOR); + LL_RECORD_BLOCK_TIME(FTM_SD_PARAM_ADAPTOR); LLParamSDParser parser; // don't spam for implicit parsing of LLSD, as we want to allow arbitrary freeform data and ignore most of it bool parse_silently = true; diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp index e6e80fa279..a4b1d2ede3 100755 --- a/indra/llcommon/llstring.cpp +++ b/indra/llcommon/llstring.cpp @@ -36,7 +36,7 @@ #include <winnls.h> // for WideCharToMultiByte #endif -LLFastTimer::DeclareTimer FT_STRING_FORMAT("String Format"); +LLTrace::TimeBlock FT_STRING_FORMAT("String Format"); std::string ll_safe_string(const char* in) @@ -1195,7 +1195,7 @@ bool LLStringUtil::formatDatetime(std::string& replacement, std::string token, template<> S32 LLStringUtil::format(std::string& s, const format_map_t& substitutions) { - LLFastTimer ft(FT_STRING_FORMAT); + LL_RECORD_BLOCK_TIME(FT_STRING_FORMAT); S32 res = 0; std::string output; @@ -1268,7 +1268,7 @@ S32 LLStringUtil::format(std::string& s, const format_map_t& substitutions) template<> S32 LLStringUtil::format(std::string& s, const LLSD& substitutions) { - LLFastTimer ft(FT_STRING_FORMAT); + LL_RECORD_BLOCK_TIME(FT_STRING_FORMAT); S32 res = 0; if (!substitutions.isMap()) diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index bf8e950a8c..a465a7f426 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -38,8 +38,6 @@ #include <list> -#define LL_RECORD_BLOCK_TIME(block_timer) LLTrace::TimeBlock::Recorder LL_GLUE_TOKENS(block_time_recorder, __COUNTER__)(block_timer); - namespace LLTrace { class Recording; @@ -89,7 +87,7 @@ public: size_t getIndex() const { return mAccumulatorIndex; } static size_t getNumIndices() { return AccumulatorBuffer<ACCUMULATOR>::getNumIndices(); } -private: +protected: const size_t mAccumulatorIndex; }; @@ -329,7 +327,7 @@ class MemTrackable struct TrackMemImpl; typedef MemTrackable<DERIVED, ALIGNMENT> mem_trackable_t; - + static MemStatHandle sMemStat; public: typedef void mem_trackable_tag_t; @@ -340,38 +338,100 @@ public: void* operator new(size_t size) { - MemStatAccumulator& accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)size : (F64)size); accumulator.mAllocatedCount++; - return ::operator new(size); + if (ALIGNMENT == LL_DEFAULT_HEAP_ALIGN) + { + return ::operator new(size); + } + else if (ALIGNMENT == 16) + { + return ll_aligned_malloc_16(size); + } + else if (ALIGNMENT == 32) + { + return ll_aligned_malloc_32(size); + } + else + { + return ll_aligned_malloc(size, ALIGNMENT); + } } void operator delete(void* ptr, size_t size) { - MemStatAccumulator& accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)size : -(F64)size); accumulator.mAllocatedCount--; accumulator.mDeallocatedCount++; - ::operator delete(ptr); + + if (ALIGNMENT == LL_DEFAULT_HEAP_ALIGN) + { + ::operator delete(ptr); + } + else if (ALIGNMENT == 16) + { + ll_aligned_free_16(ptr); + } + else if (ALIGNMENT == 32) + { + return ll_aligned_free_32(ptr); + } + else + { + return ll_aligned_free(ptr); + } } void *operator new [](size_t size) { - MemStatAccumulator& accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)size : (F64)size); accumulator.mAllocatedCount++; - return ::operator new[](size); + if (alignment == LL_DEFAULT_HEAP_ALIGN) + { + return ::operator new[](size); + } + else if (ALIGNMENT == 16) + { + return ll_aligned_malloc_16(size); + } + else if (ALIGNMENT == 32) + { + return ll_aligned_malloc_32(size); + } + else + { + return ll_aligned_malloc(size, ALIGNMENT); + } } void operator delete[](void* ptr, size_t size) { - MemStatAccumulator& accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)size : -(F64)size); accumulator.mAllocatedCount--; accumulator.mDeallocatedCount++; - ::operator delete[](ptr); + + if (alignment == LL_DEFAULT_HEAP_ALIGN) + { + ::operator delete[](ptr); + } + else if (ALIGNMENT == 16) + { + ll_aligned_free_16(ptr); + } + else if (ALIGNMENT == 32) + { + return ll_aligned_free_32(ptr); + } + else + { + return ll_aligned_free(ptr); + } } // claim memory associated with other objects/data as our own, adding to our calculated footprint @@ -393,7 +453,7 @@ public: template<typename AMOUNT_T> AMOUNT_T& memClaimAmount(AMOUNT_T& size) { - MemStatAccumulator& accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); mMemFootprint += (size_t)size; accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)size : (F64)size); return size; @@ -417,7 +477,7 @@ public: template<typename AMOUNT_T> AMOUNT_T& memDisclaimAmount(AMOUNT_T& size) { - MemStatAccumulator& accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)size : -(F64)size); return size; } @@ -430,7 +490,7 @@ private: { static void claim(mem_trackable_t& tracker, const TRACKED& tracked) { - MemStatAccumulator& accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); size_t footprint = MemFootprint<TRACKED>::measure(tracked); accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() + (F64)footprint : (F64)footprint); tracker.mMemFootprint += footprint; @@ -438,7 +498,7 @@ private: static void disclaim(mem_trackable_t& tracker, const TRACKED& tracked) { - MemStatAccumulator& accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); size_t footprint = MemFootprint<TRACKED>::measure(tracked); accumulator.mSize.sample(accumulator.mSize.hasValue() ? accumulator.mSize.getLastValue() - (F64)footprint : -(F64)footprint); tracker.mMemFootprint -= footprint; @@ -450,17 +510,21 @@ private: { static void claim(mem_trackable_t& tracker, TRACKED& tracked) { - MemStatAccumulator& accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); accumulator.mChildSize.sample(accumulator.mChildSize.hasValue() ? accumulator.mChildSize.getLastValue() + (F64)MemFootprint<TRACKED>::measure(tracked) : (F64)MemFootprint<TRACKED>::measure(tracked)); } static void disclaim(mem_trackable_t& tracker, TRACKED& tracked) { - MemStatAccumulator& accumulator = DERIVED::sMemStat.getPrimaryAccumulator(); + MemStatAccumulator& accumulator = sMemStat.getPrimaryAccumulator(); accumulator.mChildSize.sample(accumulator.mChildSize.hasValue() ? accumulator.mChildSize.getLastValue() - (F64)MemFootprint<TRACKED>::measure(tracked) : -(F64)MemFootprint<TRACKED>::measure(tracked)); } }; }; +// pretty sure typeid of containing class in static object constructor doesn't work in gcc +template<typename DERIVED, size_t ALIGNMENT> +MemStatHandle MemTrackable<DERIVED, ALIGNMENT>::sMemStat(typeid(DERIVED).name()); + } #endif // LL_LLTRACE_H diff --git a/indra/llcommon/lltracethreadrecorder.cpp b/indra/llcommon/lltracethreadrecorder.cpp index 28470fb4c4..4129f1f889 100644 --- a/indra/llcommon/lltracethreadrecorder.cpp +++ b/indra/llcommon/lltracethreadrecorder.cpp @@ -249,11 +249,11 @@ void ThreadRecorder::pushToParent() } -static LLFastTimer::DeclareTimer FTM_PULL_TRACE_DATA_FROM_CHILDREN("Pull child thread trace data"); +static LLTrace::TimeBlock FTM_PULL_TRACE_DATA_FROM_CHILDREN("Pull child thread trace data"); void ThreadRecorder::pullFromChildren() { - LLFastTimer _(FTM_PULL_TRACE_DATA_FROM_CHILDREN); + LL_RECORD_BLOCK_TIME(FTM_PULL_TRACE_DATA_FROM_CHILDREN); if (mActiveRecordings.empty()) return; { LLMutexLock lock(&mChildListMutex); |