summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2015-01-18 14:56:21 +0100
committerKai Koehne <kai.koehne@theqtcompany.com>2015-02-14 18:43:35 +0000
commit2be0d3088fc5bc52ece6b28157b28d16699ccb9b (patch)
tree5dacfd6ea8f436239cd524cb16d620aa78defb61 /src/corelib
parent0eedca658a52f96175fc7ee3980179872464f061 (diff)
qFormatLogMessage: optimize %{backtrace}
backtrace_symbols is very slow because it tries to find the function name from the address. In order to do that it needs to do a linear search over all symbols. (Because the hash table goes the other way to find the address from the symbol name) The code is going to skip a few frames from QtCore. Since we cannot know how many, we take a few more than necessary. This patch changes the additional number of frames from 15 to 7 (Usually, there are about 5 suppressed frames). We call backtrace_symbols several times for only one frame at the time. So we are not looking up addresses we don't need after we printed the right number of frames. Calling many times backtrace_symbols means we do more malloc, but that's negligible compared to the time we save. We anyway do a lot of other allocations because of the regexp operations and such So this patch is then saving about 10 frames lookups which allow to print about 6 qDebug per miliseconds instead of only 2 when using %{backtrace depth=2} Change-Id: Ic6ece2145d53dc570c80fcb0e4455dcef6bc40cb Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/global/qlogging.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index 18b672d7ee..5f11334a82 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -1154,13 +1154,13 @@ QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, con
message.append(QString::number(qlonglong(QThread::currentThread()->currentThread()), 16));
#ifdef QLOGGING_HAVE_BACKTRACE
} else if (token == backtraceTokenC) {
- QVarLengthArray<void*, 32> buffer(15 + pattern->backtraceDepth);
+ QVarLengthArray<void*, 32> buffer(7 + pattern->backtraceDepth);
int n = backtrace(buffer.data(), buffer.size());
if (n > 0) {
- QScopedPointer<char*, QScopedPointerPodDeleter> strings(backtrace_symbols(buffer.data(), n));
int numberPrinted = 0;
for (int i = 0; i < n && numberPrinted < pattern->backtraceDepth; ++i) {
- QString trace = QString::fromLatin1(strings.data()[i]);
+ QScopedPointer<char*, QScopedPointerPodDeleter> strings(backtrace_symbols(buffer.data() + i, 1));
+ QString trace = QString::fromLatin1(strings.data()[0]);
// The results of backtrace_symbols looks like this:
// /lib/libc.so.6(__libc_start_main+0xf3) [0x4a937413]
// The offset and function name are optional.