-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add perf query interface and untangle it from recordpage
moving the query part of the recordpage into its own class will make implementing remote recording much easier
- Loading branch information
Showing
16 changed files
with
854 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
SPDX-FileCopyrightText: Milian Wolff <[email protected]> | ||
SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected] | ||
SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <ThreadWeaver/ThreadWeaver> | ||
#include <QObject> | ||
#include <QPointer> | ||
|
||
class JobTracker | ||
{ | ||
public: | ||
explicit JobTracker(QObject* context) | ||
: m_context(context) | ||
{ | ||
} | ||
|
||
bool isJobRunning() const | ||
{ | ||
return m_context && m_isRunning; | ||
} | ||
|
||
template<typename Job, typename SetData> | ||
void startJob(Job&& job, SetData&& setData) | ||
{ | ||
using namespace ThreadWeaver; | ||
const auto jobId = ++m_currentJobId; | ||
auto jobCancelled = [context = m_context, jobId, currentJobId = &m_currentJobId]() { | ||
return !context || jobId != (*currentJobId); | ||
}; | ||
auto maybeSetData = [jobCancelled, setData = std::forward<SetData>(setData), | ||
isRunning = &m_isRunning](auto&& results) { | ||
if (!jobCancelled()) { | ||
setData(std::forward<decltype(results)>(results)); | ||
*isRunning = false; | ||
} | ||
}; | ||
|
||
m_isRunning = true; | ||
stream() << make_job([context = m_context, job = std::forward<Job>(job), maybeSetData = std::move(maybeSetData), | ||
jobCancelled = std::move(jobCancelled)]() mutable { | ||
auto results = job(jobCancelled); | ||
if (jobCancelled()) | ||
return; | ||
|
||
QMetaObject::invokeMethod( | ||
context.data(), | ||
[results = std::move(results), maybeSetData = std::move(maybeSetData)]() mutable { | ||
maybeSetData(std::move(results)); | ||
}, | ||
Qt::QueuedConnection); | ||
}); | ||
} | ||
|
||
private: | ||
QPointer<QObject> m_context; | ||
std::atomic<uint> m_currentJobId; | ||
bool m_isRunning = false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.