diff --git a/xpcom/base/FunctionTimer.cpp b/xpcom/base/FunctionTimer.cpp index 5b994fe68f9..0d25eb414a6 100644 --- a/xpcom/base/FunctionTimer.cpp +++ b/xpcom/base/FunctionTimer.cpp @@ -86,6 +86,7 @@ FunctionTimer::InitTimers() } FunctionTimerLog::FunctionTimerLog(const char *fname) + : mLatest(sAppStart) { if (strcmp(fname, "stdout") == 0) { mFile = stdout; @@ -119,11 +120,18 @@ void FunctionTimerLog::LogString(const char *str) { if (mFile) { - TimeDuration elapsed = TimeStamp::Now() - sAppStart; + mLatest = TimeStamp::Now(); + TimeDuration elapsed = mLatest - sAppStart; fprintf((FILE*)mFile, "[% 9.2f] %s\n", elapsed.ToSeconds() * 1000.0, str); } } +TimeDuration +FunctionTimerLog::LatestSinceStartup() const +{ + return mLatest - sAppStart; +} + int FunctionTimer::ft_vsnprintf(char *str, int maxlen, const char *fmt, va_list args) { diff --git a/xpcom/base/FunctionTimer.h b/xpcom/base/FunctionTimer.h index 2362d2e7231..0d71ff25c0b 100644 --- a/xpcom/base/FunctionTimer.h +++ b/xpcom/base/FunctionTimer.h @@ -112,6 +112,11 @@ #define NS_TIME_FUNCTION_ELAPSED_SINCE_MARK \ ft__autogen.ElapsedSinceMark +// A TimeDuration value representing the elapsed time between the +// last logged event of any sort and the app startup. +#define NS_TIME_FUNCTION_LATEST \ + mozilla::FunctionTimer::LatestSinceStartup() + #else #define NS_TIME_FUNCTION do { } while (0) @@ -122,6 +127,7 @@ #define NS_TIME_FUNCTION_MARK(...) do { } while (0) #define NS_TIME_FUNCTION_ELAPSED (0) #define NS_TIME_FUNCTION_ELAPSED_SINCE_MARK (0) +#define NS_TIME_FUNCTION_LATEST (mozilla::TimeDuration(0)) #endif @@ -135,8 +141,11 @@ public: void LogString(const char *str); + TimeDuration LatestSinceStartup() const; + private: void *mFile; + TimeStamp mLatest; }; class NS_COM FunctionTimer @@ -199,6 +208,10 @@ public: return 0.0; } + static inline TimeDuration LatestSinceStartup() { + return sLog ? sLog->LatestSinceStartup() : TimeDuration(0); + } + FunctionTimer(double minms, const char *s, ...) : mMinMs(minms), mHasMinMs(PR_TRUE), mEnabled(sLog && s && *s), mDepth(++sDepth)