summaryrefslogtreecommitdiffstats
path: root/tests/auto/addresscache/tst_addresscache.cpp
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2017-10-22 23:43:01 +0200
committerUlf Hermann <ulf.hermann@qt.io>2019-05-02 14:42:12 +0000
commit25df99e71def3c3e516a94999c0e05c9e82402a4 (patch)
tree777333dcbca59e2e7a01d73240103e1788c3320b /tests/auto/addresscache/tst_addresscache.cpp
parent6a41c2d90a43e1406f6ac27cacc1e5f6affe7108 (diff)
Cache address location information per elf file
Instead of using one large shared address cache that needs to be cleared every now and then, cache the address location information per elf file using relative addresses. This means we don't need to clear this cache at all, as the lookup for a relative address into a given elf file will always return the same data. This greatly improves the performance under some situations where the cache is cleared often. For one of my files, it drops the time from 55s down to 18s. Additionally, this patch paves the way to share (parts of) this cache in PerfUnwind. Most of its contents are not PID specific anymore. Change-Id: I79616fbb5c45a2543845df2d05d9936e49401627 Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Diffstat (limited to 'tests/auto/addresscache/tst_addresscache.cpp')
-rw-r--r--tests/auto/addresscache/tst_addresscache.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/auto/addresscache/tst_addresscache.cpp b/tests/auto/addresscache/tst_addresscache.cpp
new file mode 100644
index 0000000..2086410
--- /dev/null
+++ b/tests/auto/addresscache/tst_addresscache.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Enterprise Perf Profiler Add-on.
+**
+** GNU General Public License Usage
+** This file may be used under the terms of the GNU General Public License
+** version 3 as published by the Free Software Foundation and appearing in
+** the file LICENSE.GPLv3 included in the packaging of this file. Please
+** review the following information to ensure the GNU General Public License
+** requirements will be met: https://www.gnu.org/licenses/gpl.html.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://www.qt.io/contact-us
+**
+****************************************************************************/
+
+#include <QObject>
+#include <QTest>
+#include <QDebug>
+#include <QTemporaryFile>
+
+#include "perfaddresscache.h"
+
+class TestAddressCache : public QObject
+{
+ Q_OBJECT
+private slots:
+ void testRelative()
+ {
+ PerfElfMap::ElfInfo info_a{{}, 0x100, 100, 0,
+ QByteArrayLiteral("libfoo.so"),
+ QByteArrayLiteral("/usr/lib/libfoo.so")};
+ PerfElfMap::ElfInfo info_b = info_a;
+ info_b.addr = 0x200;
+
+ PerfAddressCache cache;
+ PerfAddressCache::AddressCacheEntry entry{42, true};
+ cache.cache(info_a, 0x110, entry);
+ QCOMPARE(cache.find(info_a, 0x110).locationId, entry.locationId);
+ QCOMPARE(cache.find(info_b, 0x210).locationId, entry.locationId);
+ }
+
+ void testInvalid()
+ {
+ PerfAddressCache cache;
+ PerfAddressCache::AddressCacheEntry entry{42, true};
+ cache.cache(PerfElfMap::ElfInfo{}, 0x110, entry);
+ QCOMPARE(cache.find(PerfElfMap::ElfInfo{}, 0x110).locationId, entry.locationId);
+ }
+
+ void testEmpty()
+ {
+ PerfAddressCache cache;
+ QCOMPARE(cache.find(PerfElfMap::ElfInfo{}, 0x123).locationId, -1);
+ }
+};
+
+QTEST_GUILESS_MAIN(TestAddressCache)
+
+#include "tst_addresscache.moc"