From 5d366f7e422129ec0c229b78f247b66e4ba63a59 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 30 Jul 2014 19:57:06 -0700 Subject: Display the QElapsedTimer reference time in %{time} This allows the time to be synchronized between different programs, as opposed to how long it has been since the message pattern was first parsed... Change-Id: If8bdfa0d997ca418a5fcae40f8c34fb77f90d2aa Reviewed-by: Shawn Rutledge --- src/corelib/global/qlogging.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/corelib/global') diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 0271573445..7763a15b3a 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -828,6 +828,9 @@ struct QMessagePattern { const char **literals; const char **tokens; QString timeFormat; +#ifndef QT_BOOTSTRAPPED + QElapsedTimer timer; +#endif #ifdef QLOGGING_HAVE_BACKTRACE int backtraceDepth; QString backtraceSeparator; @@ -835,10 +838,6 @@ struct QMessagePattern { bool fromEnvironment; static QBasicMutex mutex; -#ifndef QT_BOOTSTRAPPED - QElapsedTimer timer; - QDateTime startTime; -#endif }; QBasicMutex QMessagePattern::mutex; @@ -851,9 +850,6 @@ QMessagePattern::QMessagePattern() , backtraceSeparator(QLatin1Char('|')) #endif , fromEnvironment(false) -#ifndef QT_BOOTSTRAPPED - , startTime(QDateTime::currentDateTime()) -#endif { #ifndef QT_BOOTSTRAPPED timer.start(); @@ -1204,6 +1200,12 @@ QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, con if (pattern->timeFormat == QLatin1String("process")) { quint64 ms = pattern->timer.elapsed(); message.append(QString().sprintf("%6d.%03d", uint(ms / 1000), uint(ms % 1000))); + } else if (pattern->timeFormat == QLatin1String("boot")) { + // just print the milliseconds since the elapsed timer reference + // like the Linux kernel does + pattern->timer.elapsed(); + uint ms = pattern->timer.msecsSinceReference(); + message.append(QString().sprintf("%6d.%03d", uint(ms / 1000), uint(ms % 1000))); } else if (pattern->timeFormat.isEmpty()) { message.append(QDateTime::currentDateTime().toString(Qt::ISODate)); } else { @@ -1554,6 +1556,9 @@ void qErrnoWarning(int code, const char *msg, ...) \row \li \c %{threadid} \li ID of current thread \row \li \c %{type} \li "debug", "warning", "critical" or "fatal" \row \li \c %{time process} \li time of the message, in seconds since the process started (the token "process" is literal) + \row \li \c %{time boot} \li the time of the message, in seconds since the system boot if that + can be determined (the token "boot" is literal). If the time since boot could not be obtained, + the output is indeterminate (see QElapsedTimer::msecsSinceReference()). \row \li \c %{time [format]} \li system time when the message occurred, formatted by passing the \c format to \l QDateTime::toString(). If the format is not specified, the format of Qt::ISODate is used. -- cgit v1.2.3