Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Caller / Callee functionality #26

Merged
merged 1 commit into from
Feb 17, 2017
Merged

Conversation

nwrogers
Copy link
Contributor

@nwrogers nwrogers commented Feb 14, 2017

Implement logic to perfparser to aggregate by symbol the caller/calle performance results from the perf data. Add support to GUI to display the results in a table view with a new callercalleemodel. Fixes #5

Copy link
Member

@milianw milianw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some nitpicks, and more work on the algorithm to build the caller/callee model. I really suggest you look at what I did for heaptrack, since that should work nicely - I just recently fixed a remaining bug therein.

src/main.cpp Outdated
@@ -39,6 +40,7 @@ int main(int argc, char** argv)
QApplication app(argc, argv);
qRegisterMetaType<FrameData>();
qRegisterMetaType<SummaryData>();
qRegisterMetaType <QVector<FrameData>>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove space in front of the <

QVariant CallerCalleeModel::data(const QModelIndex& index, int role) const
{
const auto* item = &m_rows.at(index.row());
//const auto& item = (role == MaxCostRole) ? m_maxCost : m_rows.at(index.row());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove


#include "framedata.h"

//using CallerCalleeRows = QVector<CallerCalleeData>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@@ -863,24 +863,38 @@ struct PerfParserPrivate
setParents(&topDownResult.children, nullptr);
}

static void buildCallerCalleeResult(const QVector<FrameData>& bottomUpData, QVector<FrameData>& callerCalleeData)
{
static QSet<QString> callerCalleeRecursionGuard;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must not be static, I actually doubt that this algorithm produces the correct results. Please check the current master of heaptrack for how to to this, and test with a recursive test application.

If you need help, let me know. I'll try to find some time later tonight to write a proper unit test for this which you can use then as basis. It's about time I start with unit test coverage, it will make your life much easier.

The problem is the following: The bottom up data contains all call graphs in a "merged" way, but the recursion guard must only be used for individual call graphs. You can get from the "merged" tree of call stacks to a single stack by doing a depth-first search and then bubbling up the parent chain. I.e. the individual stacks are the parent-chains of every leaf in the bottomUpData tree. Now for every individual stack you'll have to guard against repeated counts of costs in the face of recursion, so you'll clear the set whenever you hit the next leaf before bubbling up the parent chain.

The comment I wrote initially didn't explicitly say that, so sorry if that wasn't clear.

CallerCalleeModel::CallerCalleeModel(QObject* parent)
: QAbstractTableModel(parent)
{
//qRegisterMetaType<CallerCalleeRows>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

#include "callercalleemodel.h"

namespace{
QString basename(const QString& path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused, remove

if (!item) {
return {};
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a check on role == Qt::InitialSortOrderRole and return Qt::DescendingOrder; for the cost columns

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the requested change in headerData

} else {
for (FrameData& callerCalleeRow : callerCalleeData) {
if (callerCalleeRow.location == row.location) {
callerCalleeRow.inclusiveCost++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still potentially counting the same thing multiple times, i.e. when you have a recursive stack

a > b > a > b

then the first two frames will not yet be in the set and thus added to the list, but then the last two frames will get their inclusive cost incremented while that shouldn't be the case for the caller/callee data representation.

@nwrogers nwrogers force-pushed the CallerCallee branch 2 times, most recently from bef3835 to 58f6c14 Compare February 14, 2017 22:27
Copy link
Member

@milianw milianw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a typo in your commit message, you write "calle" instead of "callee"

if (role != Qt::DisplayRole || orientation != Qt::Horizontal) {
return {};
}
if (role == Qt::InitialSortOrderRole) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will never be called b/c you have an early return above (role != Qt::DisplayRole)

break;
}
} else if (role == FilterRole) {
return item->symbol + item->binary + item->location;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a // TODO: optimize this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, wrap it in a QString(...) to make the conversion from QStringBuilder explicit. I just pushed some changes which will make this necessary


void resetData(const QVector<FrameData>& rows);
private:
QVector<FrameData> m_rows;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say use a FrameData here as "root" which holds the rows in it's children. The advantage is that this will allow us to track the total cost in the root object, for use in calculating the fractional cost.

Copy link
Member

@milianw milianw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add a simple test following the existing one to tst_models.cpp

src/main.cpp Outdated
@@ -39,6 +40,7 @@ int main(int argc, char** argv)
QApplication app(argc, argv);
qRegisterMetaType<FrameData>();
qRegisterMetaType<SummaryData>();
qRegisterMetaType<QVector<FrameData>>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you use FrameData as root in the model, these change is not needed

connect(m_parser, &PerfParser::callerCalleeDataAvailable,
this, [this, callerCalleeCostModel] (const QVector<FrameData>& data) {
callerCalleeCostModel->resetData(data);
ui->callerCalleeTableView->sortByColumn(CallerCalleeModel::InclusiveCost);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't be needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this isn't here it sorts by symbol, is that what we want?

break;
}
} else if (role == FilterRole) {
return item->symbol + item->binary + item->location;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, wrap it in a QString(...) to make the conversion from QStringBuilder explicit. I just pushed some changes which will make this necessary

src/main.cpp Outdated
@@ -28,6 +28,7 @@
#include <QApplication>
#include <QCommandLineParser>
#include <QFile>
#include <QVector>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed anymore

connect(m_parser, &PerfParser::callerCalleeDataAvailable,
this, [this, callerCalleeCostModel] (const FrameData& data) {
callerCalleeCostModel->setData(data);
ui->callerCalleeTableView->sortByColumn(CallerCalleeModel::InclusiveCost);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still shouldn't be required

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should read better. this is fine of course, ignore the comment above


int CallerCalleeModel::rowCount(const QModelIndex& parent) const
{
if (parent.column() > 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>=

the test found this issue in the existing model for me

int rowCount(const QModelIndex &parent = {}) const override;

QModelIndex index(int row, int column, const QModelIndex& parent) const override;
QModelIndex parent(const QModelIndex& child) const override;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to supply neither index nor parent at all for a QAbstractTableModel. It has default implementations that are fine for us (afaik?)

since this is not a tree, accessing the data is trivial: m_rows.value(index.row())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it turns out this is half true. True, I didn't need to override parent but I do need to override index, otherwise I get a segfaults in CallerCalleeModel::itemFromIndex.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need itemFromIndex either, as I said it is: m_rows.value(index.row()) for a simple table


bool operator<(const CallerCalleeLocation& location) const
{
return std::tie(symbol, binary)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

join with next line (or is it too long? in that case, one more space in the line below, so that the std::tie aligns


while (node) {
const auto needle = std::tie(node->symbol, node->binary);
if (!recursionGuard.contains({node->symbol, node->binary})) { // aggregate caller-callee data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use needle

const auto needle = std::tie(node->symbol, node->binary);
if (!recursionGuard.contains({node->symbol, node->binary})) { // aggregate caller-callee data
auto it = std::lower_bound(callerCalleeData->children.begin(), callerCalleeData->children.end(), needle,
[](const FrameData& frame, const auto needle) { return std::tie(frame.symbol, frame.binary) < needle; });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you implemented operator< above, so use it:

return CallerCalleeLocation(frame.symbol, frame.binary) < needle;

auto it = std::lower_bound(callerCalleeData->children.begin(), callerCalleeData->children.end(), needle,
[](const FrameData& frame, const auto needle) { return std::tie(frame.symbol, frame.binary) < needle; });

if (it == callerCalleeData->children.end() || std::tie(it->symbol, it->binary) != needle) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably also replace tie with CallerCalleeLocation

it->inclusiveCost += 1;
if (!node->parent) {
it->selfCost += 1;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove empty line

it->selfCost += 1;

}
recursionGuard.insert({node->symbol, node->binary});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needle

@nwrogers nwrogers force-pushed the CallerCallee branch 3 times, most recently from 34381e8 to 02830eb Compare February 16, 2017 14:48
Copy link
Member

@milianw milianw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work, two minor nitpicks then this is ready to go in

return !(location1.symbol == location2.symbol && location1.binary == location2.binary);
}

inline uint qHash(const CallerCalleeLocation &key, uint seed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default initialize seed = 0


inline uint qHash(const CallerCalleeLocation &key, uint seed)
{
Util::HashCombineCommutative hash;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use HashCombine, not the Commutative version

performance results from the perf data.  Add support to GUI to display
the results in a table view with a new callercalleemodel and add a small
qtest to test the model. Fixes KDAB#5
@milianw milianw merged commit bd735e5 into KDAB:master Feb 17, 2017
lievenhey added a commit that referenced this pull request Jun 7, 2024
The crash is caused because the destructor is called in one thread while
other threads still execute. This patch waits in the destructor till all
threads terminate.

Backtrace:
==91946==ERROR: AddressSanitizer: heap-use-after-free on address 0x513000001bb9 at pc 0x5555566c3173 bp 0x7fffca5fe900 sp 0x7fffca5fe8f0
READ of size 1 at 0x513000001bb9 thread T25 (GlobalQueue[06])
    #0 0x5555566c3172 in std::__atomic_base<bool>::load(std::memory_order) const /usr/include/c++/14.1.1/bits/atomic_base.h:501
    #1 0x5555566c3172 in std::atomic<bool>::operator bool() const /usr/include/c++/14.1.1/atomic:92
    #2 0x55555667846a in operator() /home/lieven/KDAB/hotspot/src/parsers/perf/perfparser.cpp:1684
    #3 0x5555566c10bc in call /usr/include/qt/QtCore/qobjectdefs_impl.h:146
    #4 0x5555566b9353 in call<QtPrivate::List<QProcess::ProcessError>, void> /usr/include/qt/QtCore/qobjectdefs_impl.h:256
    #5 0x5555566b1239 in impl /usr/include/qt/QtCore/qobjectdefs_impl.h:443
    #6 0x7ffff46df99d  (/usr/lib/libQt5Core.so.5+0x2df99d) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #7 0x7ffff4630793 in QProcess::errorOccurred(QProcess::ProcessError) (/usr/lib/libQt5Core.so.5+0x230793) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #8 0x7ffff462c846  (/usr/lib/libQt5Core.so.5+0x22c846) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #9 0x7ffff4630f6c  (/usr/lib/libQt5Core.so.5+0x230f6c) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #10 0x7ffff46df961  (/usr/lib/libQt5Core.so.5+0x2df961) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #11 0x7ffff46e096d in QSocketNotifier::activated(QSocketDescriptor, QSocketNotifier::Type, QSocketNotifier::QPrivateSignal) (/usr/lib/libQt5Core.so.5+0x2e096d) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #12 0x7ffff46e0aa4 in QSocketNotifier::event(QEvent*) (/usr/lib/libQt5Core.so.5+0x2e0aa4) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #13 0x7ffff5d56330 in QApplicationPrivate::notify_helper(QObject*, QEvent*) (/usr/lib/libQt5Widgets.so.5+0x156330) (BuildId: 254b52226c3f04da1b93d83e86adb3e3cffb6f76)
    #14 0x7ffff46ab967 in QCoreApplication::notifyInternal2(QObject*, QEvent*) (/usr/lib/libQt5Core.so.5+0x2ab967) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #15 0x7ffff46f8f0d  (/usr/lib/libQt5Core.so.5+0x2f8f0d) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #16 0x7ffff2314a88  (/usr/lib/libglib-2.0.so.0+0x5ca88) (BuildId: 8880230af7e37f2edbd90b79170aead80dde617a)
    #17 0x7ffff23769b6  (/usr/lib/libglib-2.0.so.0+0xbe9b6) (BuildId: 8880230af7e37f2edbd90b79170aead80dde617a)
    #18 0x7ffff2313f94 in g_main_context_iteration (/usr/lib/libglib-2.0.so.0+0x5bf94) (BuildId: 8880230af7e37f2edbd90b79170aead80dde617a)
    #19 0x7ffff46fa27e in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (/usr/lib/libQt5Core.so.5+0x2fa27e) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #20 0x7ffff46a372b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (/usr/lib/libQt5Core.so.5+0x2a372b) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #21 0x55555667a9c9 in operator() /home/lieven/KDAB/hotspot/src/parsers/perf/perfparser.cpp:1703
    #22 0x5555566c2f6f in run /usr/include/KF5/ThreadWeaver/threadweaver/lambda.h:30
    #23 0x7ffff7f5f5ad in ThreadWeaver::Executor::run(QSharedPointer<ThreadWeaver::JobInterface> const&, ThreadWeaver::Thread*) (/usr/lib/libKF5ThreadWeaver.so.5+0x125ad) (BuildId: 200cb669eff8ffb9ace9b7b396df6403668
5aed2)
    #24 0x7ffff7f604f5 in ThreadWeaver::Job::execute(QSharedPointer<ThreadWeaver::JobInterface> const&, ThreadWeaver::Thread*) (/usr/lib/libKF5ThreadWeaver.so.5+0x134f5) (BuildId: 200cb669eff8ffb9ace9b7b396df64036685
aed2)
    #25 0x7ffff7f63f01 in ThreadWeaver::Thread::run() (/usr/lib/libKF5ThreadWeaver.so.5+0x16f01) (BuildId: 200cb669eff8ffb9ace9b7b396df64036685aed2)
    #26 0x7ffff44f258a  (/usr/lib/libQt5Core.so.5+0xf258a) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #27 0x7ffff785cc79 in asan_thread_start /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_interceptors.cpp:234
    #28 0x7ffff36a6dec  (/usr/lib/libc.so.6+0x92dec) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)
    #29 0x7ffff372a0db  (/usr/lib/libc.so.6+0x1160db) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)

0x513000001bb9 is located 313 bytes inside of 336-byte region [0x513000001a80,0x513000001bd0)
freed by thread T0 here:
    #0 0x7ffff78fe7e2 in operator delete(void*, unsigned long) /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_new_delete.cpp:164
    #1 0x555556670dca in PerfParser::~PerfParser() /home/lieven/KDAB/hotspot/src/parsers/perf/perfparser.cpp:1479
    #2 0x7ffff46d5264 in QObjectPrivate::deleteChildren() (/usr/lib/libQt5Core.so.5+0x2d5264) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #3 0x7ffff5d7abf8 in QWidget::~QWidget() (/usr/lib/libQt5Widgets.so.5+0x17abf8) (BuildId: 254b52226c3f04da1b93d83e86adb3e3cffb6f76)
    #4 0x5555567be0a6 in MainWindow::~MainWindow() /home/lieven/KDAB/hotspot/src/mainwindow.cpp:272
    #5 0x5555567be3d7 in MainWindow::~MainWindow() /home/lieven/KDAB/hotspot/src/mainwindow.cpp:272
    #6 0x7ffff46d1a7b in QObject::event(QEvent*) (/usr/lib/libQt5Core.so.5+0x2d1a7b) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #7 0x7ffff6a9803d in KXmlGuiWindow::event(QEvent*) (/usr/lib/libKF5XmlGui.so.5+0x8b03d) (BuildId: 47e6c6148b6e322993e79bc55d54257f5f570e1c)

previously allocated by thread T0 here:
    #0 0x7ffff78fd682 in operator new(unsigned long) /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_new_delete.cpp:95
    #1 0x5555567affca in MainWindow::MainWindow(QWidget*) /home/lieven/KDAB/hotspot/src/mainwindow.cpp:93
    #2 0x5555566539da in main /home/lieven/KDAB/hotspot/src/main.cpp:220
    #3 0x7ffff3639c87  (/usr/lib/libc.so.6+0x25c87) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)
    #4 0x7ffff3639d4b in __libc_start_main (/usr/lib/libc.so.6+0x25d4b) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)
    #5 0x5555565d5054 in _start (/home/lieven/KDAB/hotspot/build-dev-asan/bin/hotspot+0x1081054) (BuildId: a68032c20b67d2759bc6ace66427a8e3b02fa3e6)

Thread T25 (GlobalQueue[06]) created by T21 (GlobalQueue[02]) here:
    #0 0x7ffff78f38fb in pthread_create /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_interceptors.cpp:245
    #1 0x7ffff44ee379 in QThread::start(QThread::Priority) (/usr/lib/libQt5Core.so.5+0xee379) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #2 0x7ffff7f6749c in ThreadWeaver::Weaver::adjustInventory(int) (/usr/lib/libKF5ThreadWeaver.so.5+0x1a49c) (BuildId: 200cb669eff8ffb9ace9b7b396df64036685aed2)

Thread T21 (GlobalQueue[02]) created by T0 here:
    #0 0x7ffff78f38fb in pthread_create /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_interceptors.cpp:245
    #1 0x7ffff44ee379 in QThread::start(QThread::Priority) (/usr/lib/libQt5Core.so.5+0xee379) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #2 0x7ffff7f6749c in ThreadWeaver::Weaver::adjustInventory(int) (/usr/lib/libKF5ThreadWeaver.so.5+0x1a49c) (BuildId: 200cb669eff8ffb9ace9b7b396df64036685aed2)

fixes: #654
lievenhey added a commit that referenced this pull request Jun 7, 2024
The crash is caused because the destructor is called in one thread while
other threads still execute. This patch waits in the destructor till all
threads terminate.

Backtrace:
==91946==ERROR: AddressSanitizer: heap-use-after-free on address 0x513000001bb9 at pc 0x5555566c3173 bp 0x7fffca5fe900 sp 0x7fffca5fe8f0
READ of size 1 at 0x513000001bb9 thread T25 (GlobalQueue[06])
    #0 0x5555566c3172 in std::__atomic_base<bool>::load(std::memory_order) const /usr/include/c++/14.1.1/bits/atomic_base.h:501
    #1 0x5555566c3172 in std::atomic<bool>::operator bool() const /usr/include/c++/14.1.1/atomic:92
    #2 0x55555667846a in operator() /tmp/hotspot/src/parsers/perf/perfparser.cpp:1684
    #3 0x5555566c10bc in call /usr/include/qt/QtCore/qobjectdefs_impl.h:146
    #4 0x5555566b9353 in call<QtPrivate::List<QProcess::ProcessError>, void> /usr/include/qt/QtCore/qobjectdefs_impl.h:256
    #5 0x5555566b1239 in impl /usr/include/qt/QtCore/qobjectdefs_impl.h:443
    #6 0x7ffff46df99d  (/usr/lib/libQt5Core.so.5+0x2df99d) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #7 0x7ffff4630793 in QProcess::errorOccurred(QProcess::ProcessError) (/usr/lib/libQt5Core.so.5+0x230793) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #8 0x7ffff462c846  (/usr/lib/libQt5Core.so.5+0x22c846) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #9 0x7ffff4630f6c  (/usr/lib/libQt5Core.so.5+0x230f6c) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #10 0x7ffff46df961  (/usr/lib/libQt5Core.so.5+0x2df961) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #11 0x7ffff46e096d in QSocketNotifier::activated(QSocketDescriptor, QSocketNotifier::Type, QSocketNotifier::QPrivateSignal) (/usr/lib/libQt5Core.so.5+0x2e096d) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #12 0x7ffff46e0aa4 in QSocketNotifier::event(QEvent*) (/usr/lib/libQt5Core.so.5+0x2e0aa4) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #13 0x7ffff5d56330 in QApplicationPrivate::notify_helper(QObject*, QEvent*) (/usr/lib/libQt5Widgets.so.5+0x156330) (BuildId: 254b52226c3f04da1b93d83e86adb3e3cffb6f76)
    #14 0x7ffff46ab967 in QCoreApplication::notifyInternal2(QObject*, QEvent*) (/usr/lib/libQt5Core.so.5+0x2ab967) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #15 0x7ffff46f8f0d  (/usr/lib/libQt5Core.so.5+0x2f8f0d) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #16 0x7ffff2314a88  (/usr/lib/libglib-2.0.so.0+0x5ca88) (BuildId: 8880230af7e37f2edbd90b79170aead80dde617a)
    #17 0x7ffff23769b6  (/usr/lib/libglib-2.0.so.0+0xbe9b6) (BuildId: 8880230af7e37f2edbd90b79170aead80dde617a)
    #18 0x7ffff2313f94 in g_main_context_iteration (/usr/lib/libglib-2.0.so.0+0x5bf94) (BuildId: 8880230af7e37f2edbd90b79170aead80dde617a)
    #19 0x7ffff46fa27e in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (/usr/lib/libQt5Core.so.5+0x2fa27e) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #20 0x7ffff46a372b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (/usr/lib/libQt5Core.so.5+0x2a372b) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #21 0x55555667a9c9 in operator() /tmp/hotspot/src/parsers/perf/perfparser.cpp:1703
    #22 0x5555566c2f6f in run /usr/include/KF5/ThreadWeaver/threadweaver/lambda.h:30
    #23 0x7ffff7f5f5ad in ThreadWeaver::Executor::run(QSharedPointer<ThreadWeaver::JobInterface> const&, ThreadWeaver::Thread*) (/usr/lib/libKF5ThreadWeaver.so.5+0x125ad) (BuildId: 200cb669eff8ffb9ace9b7b396df6403668
5aed2)
    #24 0x7ffff7f604f5 in ThreadWeaver::Job::execute(QSharedPointer<ThreadWeaver::JobInterface> const&, ThreadWeaver::Thread*) (/usr/lib/libKF5ThreadWeaver.so.5+0x134f5) (BuildId: 200cb669eff8ffb9ace9b7b396df64036685
aed2)
    #25 0x7ffff7f63f01 in ThreadWeaver::Thread::run() (/usr/lib/libKF5ThreadWeaver.so.5+0x16f01) (BuildId: 200cb669eff8ffb9ace9b7b396df64036685aed2)
    #26 0x7ffff44f258a  (/usr/lib/libQt5Core.so.5+0xf258a) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #27 0x7ffff785cc79 in asan_thread_start /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_interceptors.cpp:234
    #28 0x7ffff36a6dec  (/usr/lib/libc.so.6+0x92dec) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)
    #29 0x7ffff372a0db  (/usr/lib/libc.so.6+0x1160db) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)

0x513000001bb9 is located 313 bytes inside of 336-byte region [0x513000001a80,0x513000001bd0)
freed by thread T0 here:
    #0 0x7ffff78fe7e2 in operator delete(void*, unsigned long) /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_new_delete.cpp:164
    #1 0x555556670dca in PerfParser::~PerfParser() /tmp/hotspot/src/parsers/perf/perfparser.cpp:1479
    #2 0x7ffff46d5264 in QObjectPrivate::deleteChildren() (/usr/lib/libQt5Core.so.5+0x2d5264) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #3 0x7ffff5d7abf8 in QWidget::~QWidget() (/usr/lib/libQt5Widgets.so.5+0x17abf8) (BuildId: 254b52226c3f04da1b93d83e86adb3e3cffb6f76)
    #4 0x5555567be0a6 in MainWindow::~MainWindow() /tmp/hotspot/src/mainwindow.cpp:272
    #5 0x5555567be3d7 in MainWindow::~MainWindow() /tmp/hotspot/src/mainwindow.cpp:272
    #6 0x7ffff46d1a7b in QObject::event(QEvent*) (/usr/lib/libQt5Core.so.5+0x2d1a7b) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #7 0x7ffff6a9803d in KXmlGuiWindow::event(QEvent*) (/usr/lib/libKF5XmlGui.so.5+0x8b03d) (BuildId: 47e6c6148b6e322993e79bc55d54257f5f570e1c)

previously allocated by thread T0 here:
    #0 0x7ffff78fd682 in operator new(unsigned long) /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_new_delete.cpp:95
    #1 0x5555567affca in MainWindow::MainWindow(QWidget*) /tmp/hotspot/src/mainwindow.cpp:93
    #2 0x5555566539da in main /tmp/hotspot/src/main.cpp:220
    #3 0x7ffff3639c87  (/usr/lib/libc.so.6+0x25c87) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)
    #4 0x7ffff3639d4b in __libc_start_main (/usr/lib/libc.so.6+0x25d4b) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)
    #5 0x5555565d5054 in _start (/tmp/hotspot/build-dev-asan/bin/hotspot+0x1081054) (BuildId: a68032c20b67d2759bc6ace66427a8e3b02fa3e6)

Thread T25 (GlobalQueue[06]) created by T21 (GlobalQueue[02]) here:
    #0 0x7ffff78f38fb in pthread_create /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_interceptors.cpp:245
    #1 0x7ffff44ee379 in QThread::start(QThread::Priority) (/usr/lib/libQt5Core.so.5+0xee379) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #2 0x7ffff7f6749c in ThreadWeaver::Weaver::adjustInventory(int) (/usr/lib/libKF5ThreadWeaver.so.5+0x1a49c) (BuildId: 200cb669eff8ffb9ace9b7b396df64036685aed2)

Thread T21 (GlobalQueue[02]) created by T0 here:
    #0 0x7ffff78f38fb in pthread_create /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_interceptors.cpp:245
    #1 0x7ffff44ee379 in QThread::start(QThread::Priority) (/usr/lib/libQt5Core.so.5+0xee379) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #2 0x7ffff7f6749c in ThreadWeaver::Weaver::adjustInventory(int) (/usr/lib/libKF5ThreadWeaver.so.5+0x1a49c) (BuildId: 200cb669eff8ffb9ace9b7b396df64036685aed2)

fixes: #654
milianw pushed a commit that referenced this pull request Jun 17, 2024
The crash is caused because the destructor is called in one thread while
other threads still execute. This patch waits in the destructor till all
threads terminate.

Backtrace:
==91946==ERROR: AddressSanitizer: heap-use-after-free on address 0x513000001bb9 at pc 0x5555566c3173 bp 0x7fffca5fe900 sp 0x7fffca5fe8f0
READ of size 1 at 0x513000001bb9 thread T25 (GlobalQueue[06])
    #0 0x5555566c3172 in std::__atomic_base<bool>::load(std::memory_order) const /usr/include/c++/14.1.1/bits/atomic_base.h:501
    #1 0x5555566c3172 in std::atomic<bool>::operator bool() const /usr/include/c++/14.1.1/atomic:92
    #2 0x55555667846a in operator() /tmp/hotspot/src/parsers/perf/perfparser.cpp:1684
    #3 0x5555566c10bc in call /usr/include/qt/QtCore/qobjectdefs_impl.h:146
    #4 0x5555566b9353 in call<QtPrivate::List<QProcess::ProcessError>, void> /usr/include/qt/QtCore/qobjectdefs_impl.h:256
    #5 0x5555566b1239 in impl /usr/include/qt/QtCore/qobjectdefs_impl.h:443
    #6 0x7ffff46df99d  (/usr/lib/libQt5Core.so.5+0x2df99d) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #7 0x7ffff4630793 in QProcess::errorOccurred(QProcess::ProcessError) (/usr/lib/libQt5Core.so.5+0x230793) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #8 0x7ffff462c846  (/usr/lib/libQt5Core.so.5+0x22c846) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #9 0x7ffff4630f6c  (/usr/lib/libQt5Core.so.5+0x230f6c) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #10 0x7ffff46df961  (/usr/lib/libQt5Core.so.5+0x2df961) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #11 0x7ffff46e096d in QSocketNotifier::activated(QSocketDescriptor, QSocketNotifier::Type, QSocketNotifier::QPrivateSignal) (/usr/lib/libQt5Core.so.5+0x2e096d) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #12 0x7ffff46e0aa4 in QSocketNotifier::event(QEvent*) (/usr/lib/libQt5Core.so.5+0x2e0aa4) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #13 0x7ffff5d56330 in QApplicationPrivate::notify_helper(QObject*, QEvent*) (/usr/lib/libQt5Widgets.so.5+0x156330) (BuildId: 254b52226c3f04da1b93d83e86adb3e3cffb6f76)
    #14 0x7ffff46ab967 in QCoreApplication::notifyInternal2(QObject*, QEvent*) (/usr/lib/libQt5Core.so.5+0x2ab967) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #15 0x7ffff46f8f0d  (/usr/lib/libQt5Core.so.5+0x2f8f0d) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #16 0x7ffff2314a88  (/usr/lib/libglib-2.0.so.0+0x5ca88) (BuildId: 8880230af7e37f2edbd90b79170aead80dde617a)
    #17 0x7ffff23769b6  (/usr/lib/libglib-2.0.so.0+0xbe9b6) (BuildId: 8880230af7e37f2edbd90b79170aead80dde617a)
    #18 0x7ffff2313f94 in g_main_context_iteration (/usr/lib/libglib-2.0.so.0+0x5bf94) (BuildId: 8880230af7e37f2edbd90b79170aead80dde617a)
    #19 0x7ffff46fa27e in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (/usr/lib/libQt5Core.so.5+0x2fa27e) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #20 0x7ffff46a372b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (/usr/lib/libQt5Core.so.5+0x2a372b) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #21 0x55555667a9c9 in operator() /tmp/hotspot/src/parsers/perf/perfparser.cpp:1703
    #22 0x5555566c2f6f in run /usr/include/KF5/ThreadWeaver/threadweaver/lambda.h:30
    #23 0x7ffff7f5f5ad in ThreadWeaver::Executor::run(QSharedPointer<ThreadWeaver::JobInterface> const&, ThreadWeaver::Thread*) (/usr/lib/libKF5ThreadWeaver.so.5+0x125ad) (BuildId: 200cb669eff8ffb9ace9b7b396df6403668
5aed2)
    #24 0x7ffff7f604f5 in ThreadWeaver::Job::execute(QSharedPointer<ThreadWeaver::JobInterface> const&, ThreadWeaver::Thread*) (/usr/lib/libKF5ThreadWeaver.so.5+0x134f5) (BuildId: 200cb669eff8ffb9ace9b7b396df64036685
aed2)
    #25 0x7ffff7f63f01 in ThreadWeaver::Thread::run() (/usr/lib/libKF5ThreadWeaver.so.5+0x16f01) (BuildId: 200cb669eff8ffb9ace9b7b396df64036685aed2)
    #26 0x7ffff44f258a  (/usr/lib/libQt5Core.so.5+0xf258a) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #27 0x7ffff785cc79 in asan_thread_start /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_interceptors.cpp:234
    #28 0x7ffff36a6dec  (/usr/lib/libc.so.6+0x92dec) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)
    #29 0x7ffff372a0db  (/usr/lib/libc.so.6+0x1160db) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)

0x513000001bb9 is located 313 bytes inside of 336-byte region [0x513000001a80,0x513000001bd0)
freed by thread T0 here:
    #0 0x7ffff78fe7e2 in operator delete(void*, unsigned long) /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_new_delete.cpp:164
    #1 0x555556670dca in PerfParser::~PerfParser() /tmp/hotspot/src/parsers/perf/perfparser.cpp:1479
    #2 0x7ffff46d5264 in QObjectPrivate::deleteChildren() (/usr/lib/libQt5Core.so.5+0x2d5264) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #3 0x7ffff5d7abf8 in QWidget::~QWidget() (/usr/lib/libQt5Widgets.so.5+0x17abf8) (BuildId: 254b52226c3f04da1b93d83e86adb3e3cffb6f76)
    #4 0x5555567be0a6 in MainWindow::~MainWindow() /tmp/hotspot/src/mainwindow.cpp:272
    #5 0x5555567be3d7 in MainWindow::~MainWindow() /tmp/hotspot/src/mainwindow.cpp:272
    #6 0x7ffff46d1a7b in QObject::event(QEvent*) (/usr/lib/libQt5Core.so.5+0x2d1a7b) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #7 0x7ffff6a9803d in KXmlGuiWindow::event(QEvent*) (/usr/lib/libKF5XmlGui.so.5+0x8b03d) (BuildId: 47e6c6148b6e322993e79bc55d54257f5f570e1c)

previously allocated by thread T0 here:
    #0 0x7ffff78fd682 in operator new(unsigned long) /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_new_delete.cpp:95
    #1 0x5555567affca in MainWindow::MainWindow(QWidget*) /tmp/hotspot/src/mainwindow.cpp:93
    #2 0x5555566539da in main /tmp/hotspot/src/main.cpp:220
    #3 0x7ffff3639c87  (/usr/lib/libc.so.6+0x25c87) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)
    #4 0x7ffff3639d4b in __libc_start_main (/usr/lib/libc.so.6+0x25d4b) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)
    #5 0x5555565d5054 in _start (/tmp/hotspot/build-dev-asan/bin/hotspot+0x1081054) (BuildId: a68032c20b67d2759bc6ace66427a8e3b02fa3e6)

Thread T25 (GlobalQueue[06]) created by T21 (GlobalQueue[02]) here:
    #0 0x7ffff78f38fb in pthread_create /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_interceptors.cpp:245
    #1 0x7ffff44ee379 in QThread::start(QThread::Priority) (/usr/lib/libQt5Core.so.5+0xee379) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #2 0x7ffff7f6749c in ThreadWeaver::Weaver::adjustInventory(int) (/usr/lib/libKF5ThreadWeaver.so.5+0x1a49c) (BuildId: 200cb669eff8ffb9ace9b7b396df64036685aed2)

Thread T21 (GlobalQueue[02]) created by T0 here:
    #0 0x7ffff78f38fb in pthread_create /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_interceptors.cpp:245
    #1 0x7ffff44ee379 in QThread::start(QThread::Priority) (/usr/lib/libQt5Core.so.5+0xee379) (BuildId: 5ae775b980e5842fcce9c0a035de95718227fa6e)
    #2 0x7ffff7f6749c in ThreadWeaver::Weaver::adjustInventory(int) (/usr/lib/libKF5ThreadWeaver.so.5+0x1a49c) (BuildId: 200cb669eff8ffb9ace9b7b396df64036685aed2)

fixes: #654
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants