Bug 580063: Add a LatestSinceStartup() method to function timer logs. r=vlad a=benjamin

This commit is contained in:
Steve Fink 2010-09-05 16:17:02 +02:00
parent 46fd89bffd
commit 7aae2e5530
2 changed files with 22 additions and 1 deletions

View File

@ -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)
{

View File

@ -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)