diff options
| author | Thiago Macieira <thiago.macieira@intel.com> | 2025-01-07 23:43:55 -0300 |
|---|---|---|
| committer | Thiago Macieira <thiago.macieira@intel.com> | 2025-01-16 16:05:19 -0800 |
| commit | 9dc294143d8fab498268f88c176b1af16de9b2ee (patch) | |
| tree | 7327be3675949fe9312b770edd15efac8f42aa67 /src/corelib/global/qlogging.cpp | |
| parent | b86bcf5c25d0072300a8b0a4b5cfe942cabf53ad (diff) | |
QMessagePattern: replace Q{Elapsed,Deadline}Timer with std::chrono
There's nothing wrong with those two, but we don't need the middle men
to the monotonic clock. This also reduces the sizeof QMessagePattern by
one quint64 (QElapsedTimer is 16 bytes in Qt 6).
Pick-to: 6.9
Change-Id: I0eb171f03ee8f3a7148bfffd5534a7f3daba3a01
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Diffstat (limited to 'src/corelib/global/qlogging.cpp')
| -rw-r--r-- | src/corelib/global/qlogging.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 7b1a1f1db49..72fb1668777 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -16,8 +16,6 @@ #include <QtCore/private/qlocking_p.h> #include "qloggingcategory.h" #ifndef QT_BOOTSTRAPPED -#include "qelapsedtimer.h" -#include "qdeadlinetimer.h" #include "qdatetime.h" #include "qcoreapplication.h" #include "qthread.h" @@ -121,6 +119,7 @@ static QT_PREPEND_NAMESPACE(qint64) qt_gettid() #include <cstdlib> #include <algorithm> +#include <chrono> #include <memory> #include <vector> @@ -1152,7 +1151,7 @@ struct QMessagePattern std::unique_ptr<const char *[]> tokens; QList<QString> timeArgs; // timeFormats in sequence of %{time #ifndef QT_BOOTSTRAPPED - QElapsedTimer timer; + std::chrono::steady_clock::time_point appStartTime = std::chrono::steady_clock::now(); #endif #ifdef QLOGGING_HAVE_BACKTRACE struct BacktraceParams @@ -1187,9 +1186,6 @@ Q_CONSTINIT QBasicMutex QMessagePattern::mutex; QMessagePattern::QMessagePattern() { -#ifndef QT_BOOTSTRAPPED - timer.start(); -#endif const QString envPattern = qEnvironmentVariable("QT_MESSAGE_PATTERN"); if (envPattern.isEmpty()) { setDefaultPattern(); @@ -1677,15 +1673,17 @@ static QString formatLogMessage(QtMsgType type, const QMessageLogContext &contex message.append(formatBacktraceForLogMessage(backtraceParams, context)); #endif } else if (token == timeTokenC) { + using namespace std::chrono; QString timeFormat = pattern->timeArgs.at(timeArgsIdx); timeArgsIdx++; if (timeFormat == "process"_L1) { - quint64 ms = pattern->timer.elapsed(); + auto elapsed = steady_clock::now() - pattern->appStartTime; + quint64 ms = duration_cast<milliseconds>(elapsed).count(); message.append(QString::asprintf("%6d.%03d", uint(ms / 1000), uint(ms % 1000))); } else if (timeFormat == "boot"_L1) { // just print the milliseconds since the elapsed timer reference // like the Linux kernel does - qint64 ms = QDeadlineTimer::current().deadline(); + qint64 ms = duration_cast<milliseconds>(steady_clock::now().time_since_epoch()).count(); message.append(QString::asprintf("%6d.%03d", uint(ms / 1000), uint(ms % 1000))); #if QT_CONFIG(datestring) } else if (timeFormat.isEmpty()) { |
