diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-02-18 12:28:57 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-03-03 19:05:11 -0800 |
commit | bd728d11495175f90d83db8cdc58c2ac72046de2 (patch) | |
tree | 0f6cf5f4d549a2506d28b5880197e2ae463d0e19 /src/corelib/global | |
parent | ff2535de5c3d0cdcd9232780f53fd4ff00ea822a (diff) |
Logging: cache the last library file name in a backtrace
They usually come in groups, so this avoids extra work.
Change-Id: Ic15405335d804bdea761fffd16d4fb5c41e122f0
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/corelib/global')
-rw-r--r-- | src/corelib/global/qlogging.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index a94dd1eeaa..55f2e63519 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -1335,6 +1335,8 @@ static QStringList backtraceFramesForLogMessage(int frameCount) # if QT_CONFIG(dladdr) // use dladdr() instead of backtrace_symbols() + QString cachedLibrary; + const char *cachedFname = nullptr; auto decodeFrame = [&](const void *addr) -> DecodedFrame { Dl_info info; if (!dladdr(addr, &info)) @@ -1351,9 +1353,12 @@ static QStringList backtraceFramesForLogMessage(int frameCount) if (shouldSkipFrame(lib, fn)) return {}; - QString library = QString::fromUtf8(lib.data(), lib.size()); QString function = demangled(fn); - return { library, function }; + if (lib.data() != cachedFname) { + cachedFname = lib.data(); + cachedLibrary = QString::fromUtf8(cachedFname, lib.size()); + } + return { cachedLibrary, function }; }; # else // The results of backtrace_symbols looks like this: |