forked from qt-creator/qt-creator
ProgressManager: Use std::chrono for timed tasks
It is more descriptive than an int. Change-Id: I129dc931b7dd137846eb97747a5277911b94e06f Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -100,8 +100,10 @@ ProcessProgress::ProcessProgress(Process *process)
|
|||||||
if (d->m_parser) {
|
if (d->m_parser) {
|
||||||
d->m_futureProgress = ProgressManager::addTask(d->m_futureInterface.future(), name, id);
|
d->m_futureProgress = ProgressManager::addTask(d->m_futureInterface.future(), name, id);
|
||||||
} else {
|
} else {
|
||||||
d->m_futureProgress = ProgressManager::addTimedTask(d->m_futureInterface, name, id,
|
d->m_futureProgress = ProgressManager::addTimedTask(d->m_futureInterface,
|
||||||
d->m_expectedDuration.count());
|
name,
|
||||||
|
id,
|
||||||
|
d->m_expectedDuration);
|
||||||
}
|
}
|
||||||
d->m_futureProgress->setKeepOnFinish(d->m_keep);
|
d->m_futureProgress->setKeepOnFinish(d->m_keep);
|
||||||
});
|
});
|
||||||
|
@@ -37,7 +37,7 @@
|
|||||||
static const char kSettingsGroup[] = "Progress";
|
static const char kSettingsGroup[] = "Progress";
|
||||||
static const char kDetailsPinned[] = "DetailsPinned";
|
static const char kDetailsPinned[] = "DetailsPinned";
|
||||||
static const bool kDetailsPinnedDefault = true;
|
static const bool kDetailsPinnedDefault = true;
|
||||||
static const int TimerInterval = 100; // 100 ms
|
static const std::chrono::milliseconds TimerInterval{100};
|
||||||
|
|
||||||
using namespace Core::Internal;
|
using namespace Core::Internal;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
@@ -47,10 +47,12 @@ namespace Core {
|
|||||||
class ProgressTimer : public QObject
|
class ProgressTimer : public QObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ProgressTimer(const QFutureInterfaceBase &futureInterface, int expectedSeconds, QObject *parent)
|
ProgressTimer(const QFutureInterfaceBase &futureInterface,
|
||||||
: QObject(parent),
|
std::chrono::seconds expectedDuration,
|
||||||
m_futureInterface(futureInterface),
|
QObject *parent)
|
||||||
m_expectedTime(expectedSeconds)
|
: QObject(parent)
|
||||||
|
, m_futureInterface(futureInterface)
|
||||||
|
, m_expectedDuration(expectedDuration)
|
||||||
{
|
{
|
||||||
m_futureInterface.setProgressRange(0, 100);
|
m_futureInterface.setProgressRange(0, 100);
|
||||||
m_futureInterface.setProgressValue(0);
|
m_futureInterface.setProgressValue(0);
|
||||||
@@ -64,13 +66,13 @@ private:
|
|||||||
void handleTimeout()
|
void handleTimeout()
|
||||||
{
|
{
|
||||||
++m_currentTime;
|
++m_currentTime;
|
||||||
const int halfLife = qRound(1000.0 * m_expectedTime / TimerInterval);
|
const int halfLife = m_expectedDuration / TimerInterval;
|
||||||
const int progress = MathUtils::interpolateTangential(m_currentTime, halfLife, 0, 100);
|
const int progress = MathUtils::interpolateTangential(m_currentTime, halfLife, 0, 100);
|
||||||
m_futureInterface.setProgressValue(progress);
|
m_futureInterface.setProgressValue(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFutureInterfaceBase m_futureInterface;
|
QFutureInterfaceBase m_futureInterface;
|
||||||
int m_expectedTime;
|
std::chrono::seconds m_expectedDuration;
|
||||||
int m_currentTime = 0;
|
int m_currentTime = 0;
|
||||||
QTimer m_timer;
|
QTimer m_timer;
|
||||||
};
|
};
|
||||||
@@ -774,22 +776,28 @@ FutureProgress *ProgressManager::addTask(const QFuture<void> &future, const QStr
|
|||||||
\sa addTask
|
\sa addTask
|
||||||
*/
|
*/
|
||||||
|
|
||||||
FutureProgress *ProgressManager::addTimedTask(const QFutureInterface<void> &futureInterface, const QString &title,
|
FutureProgress *ProgressManager::addTimedTask(const QFutureInterface<void> &futureInterface,
|
||||||
Id type, int expectedSeconds, ProgressFlags flags)
|
const QString &title,
|
||||||
|
Id type,
|
||||||
|
std::chrono::seconds expectedDuration,
|
||||||
|
ProgressFlags flags)
|
||||||
{
|
{
|
||||||
QFutureInterface<void> dummy(futureInterface); // Need mutable to access .future()
|
QFutureInterface<void> dummy(futureInterface); // Need mutable to access .future()
|
||||||
FutureProgress *fp = m_instance->doAddTask(dummy.future(), title, type, flags);
|
FutureProgress *fp = m_instance->doAddTask(dummy.future(), title, type, flags);
|
||||||
(void) new ProgressTimer(futureInterface, expectedSeconds, fp);
|
(void) new ProgressTimer(futureInterface, expectedDuration, fp);
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureProgress *ProgressManager::addTimedTask(const QFuture<void> &future, const QString &title,
|
FutureProgress *ProgressManager::addTimedTask(const QFuture<void> &future,
|
||||||
Id type, int expectedSeconds, ProgressFlags flags)
|
const QString &title,
|
||||||
|
Id type,
|
||||||
|
std::chrono::seconds expectedDuration,
|
||||||
|
ProgressFlags flags)
|
||||||
{
|
{
|
||||||
QFutureInterface<void> dummyFutureInterface;
|
QFutureInterface<void> dummyFutureInterface;
|
||||||
QFuture<void> dummyFuture = dummyFutureInterface.future();
|
QFuture<void> dummyFuture = dummyFutureInterface.future();
|
||||||
FutureProgress *fp = m_instance->doAddTask(dummyFuture, title, type, flags);
|
FutureProgress *fp = m_instance->doAddTask(dummyFuture, title, type, flags);
|
||||||
(void) new ProgressTimer(dummyFutureInterface, expectedSeconds, fp);
|
(void) new ProgressTimer(dummyFutureInterface, expectedDuration, fp);
|
||||||
|
|
||||||
QFutureWatcher<void> *dummyWatcher = new QFutureWatcher<void>(fp);
|
QFutureWatcher<void> *dummyWatcher = new QFutureWatcher<void>(fp);
|
||||||
connect(dummyWatcher, &QFutureWatcher<void>::canceled, dummyWatcher, [future] {
|
connect(dummyWatcher, &QFutureWatcher<void>::canceled, dummyWatcher, [future] {
|
||||||
|
@@ -11,6 +11,8 @@
|
|||||||
#include <QFutureInterfaceBase>
|
#include <QFutureInterfaceBase>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
class FutureProgress;
|
class FutureProgress;
|
||||||
|
|
||||||
@@ -36,10 +38,16 @@ public:
|
|||||||
|
|
||||||
static FutureProgress *addTask(const QFuture<void> &future, const QString &title,
|
static FutureProgress *addTask(const QFuture<void> &future, const QString &title,
|
||||||
Utils::Id type, ProgressFlags flags = {});
|
Utils::Id type, ProgressFlags flags = {});
|
||||||
static FutureProgress *addTimedTask(const QFutureInterface<void> &fi, const QString &title,
|
static FutureProgress *addTimedTask(const QFutureInterface<void> &fi,
|
||||||
Utils::Id type, int expectedSeconds, ProgressFlags flags = {});
|
const QString &title,
|
||||||
static FutureProgress *addTimedTask(const QFuture<void> &future, const QString &title,
|
Utils::Id type,
|
||||||
Utils::Id type, int expectedSeconds, ProgressFlags flags = {});
|
std::chrono::seconds expectedDuration,
|
||||||
|
ProgressFlags flags = {});
|
||||||
|
static FutureProgress *addTimedTask(const QFuture<void> &future,
|
||||||
|
const QString &title,
|
||||||
|
Utils::Id type,
|
||||||
|
std::chrono::seconds expectedDuration,
|
||||||
|
ProgressFlags flags = {});
|
||||||
static void setApplicationLabel(const QString &text);
|
static void setApplicationLabel(const QString &text);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@@ -226,8 +226,11 @@ void CppTypeHierarchyWidget::perform()
|
|||||||
m_futureWatcher.setFuture(QFuture<void>(m_future));
|
m_futureWatcher.setFuture(QFuture<void>(m_future));
|
||||||
m_synchronizer.addFuture(m_future);
|
m_synchronizer.addFuture(m_future);
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
Core::ProgressManager::addTimedTask(m_futureWatcher.future(),
|
Core::ProgressManager::addTimedTask(m_futureWatcher.future(),
|
||||||
Tr::tr("Evaluating Type Hierarchy"), "TypeHierarchy", 2);
|
Tr::tr("Evaluating Type Hierarchy"),
|
||||||
|
"TypeHierarchy",
|
||||||
|
2s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppTypeHierarchyWidget::performFromExpression(const QString &expression, const FilePath &filePath)
|
void CppTypeHierarchyWidget::performFromExpression(const QString &expression, const FilePath &filePath)
|
||||||
|
@@ -188,9 +188,11 @@ void PerfDataReader::triggerRecordingStateChange(bool recording)
|
|||||||
qMin(delay(currentTime) / (1000ll * million),
|
qMin(delay(currentTime) / (1000ll * million),
|
||||||
static_cast<qint64>(std::numeric_limits<int>::max())));
|
static_cast<qint64>(std::numeric_limits<int>::max())));
|
||||||
|
|
||||||
Core::FutureProgress *fp = Core::ProgressManager::addTimedTask(
|
Core::FutureProgress *fp
|
||||||
future(), Tr::tr("Skipping Processing Delay"),
|
= Core::ProgressManager::addTimedTask(future(),
|
||||||
Constants::PerfProfilerTaskSkipDelay, seconds);
|
Tr::tr("Skipping Processing Delay"),
|
||||||
|
Constants::PerfProfilerTaskSkipDelay,
|
||||||
|
std::chrono::seconds(seconds));
|
||||||
fp->setToolTip(recording ?
|
fp->setToolTip(recording ?
|
||||||
Tr::tr("Cancel this to ignore the processing delay and immediately "
|
Tr::tr("Cancel this to ignore the processing delay and immediately "
|
||||||
"start recording.") :
|
"start recording.") :
|
||||||
|
@@ -605,9 +605,11 @@ void PerfProfilerTraceManager::loadFromPerfData(const FilePath &filePath,
|
|||||||
const int fileMegabytes = static_cast<int>(
|
const int fileMegabytes = static_cast<int>(
|
||||||
qMin(filePath.fileSize() >> 20,
|
qMin(filePath.fileSize() >> 20,
|
||||||
static_cast<qint64>(std::numeric_limits<int>::max())));
|
static_cast<qint64>(std::numeric_limits<int>::max())));
|
||||||
Core::FutureProgress *fp = Core::ProgressManager::addTimedTask(
|
Core::FutureProgress *fp
|
||||||
reader->future(), Tr::tr("Loading Trace Data"), Constants::PerfProfilerTaskLoadPerf,
|
= Core::ProgressManager::addTimedTask(reader->future(),
|
||||||
fileMegabytes);
|
Tr::tr("Loading Trace Data"),
|
||||||
|
Constants::PerfProfilerTaskLoadPerf,
|
||||||
|
std::chrono::seconds(fileMegabytes));
|
||||||
|
|
||||||
connect(fp, &Core::FutureProgress::canceled, reader, [reader]() {
|
connect(fp, &Core::FutureProgress::canceled, reader, [reader]() {
|
||||||
reader->stopParser();
|
reader->stopParser();
|
||||||
|
@@ -482,10 +482,11 @@ void KitManager::showLoadingProgress()
|
|||||||
if (futureInterface.isRunning())
|
if (futureInterface.isRunning())
|
||||||
return;
|
return;
|
||||||
futureInterface.reportStarted();
|
futureInterface.reportStarted();
|
||||||
|
using namespace std::chrono_literals;
|
||||||
Core::ProgressManager::addTimedTask(futureInterface.future(),
|
Core::ProgressManager::addTimedTask(futureInterface.future(),
|
||||||
Tr::tr("Loading Kits"),
|
Tr::tr("Loading Kits"),
|
||||||
"LoadingKitsProgress",
|
"LoadingKitsProgress",
|
||||||
5);
|
5s);
|
||||||
connect(instance(), &KitManager::kitsLoaded, []() { futureInterface.reportFinished(); });
|
connect(instance(), &KitManager::kitsLoaded, []() { futureInterface.reportFinished(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -56,7 +56,9 @@ void ValgrindToolRunner::start()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureProgress *fp = ProgressManager::addTimedTask(m_progress, progressTitle(), "valgrind", 100);
|
using namespace std::chrono_literals;
|
||||||
|
FutureProgress *fp
|
||||||
|
= ProgressManager::addTimedTask(m_progress, progressTitle(), "valgrind", 100s);
|
||||||
connect(fp, &FutureProgress::canceled,
|
connect(fp, &FutureProgress::canceled,
|
||||||
this, &ValgrindToolRunner::handleProgressCanceled);
|
this, &ValgrindToolRunner::handleProgressCanceled);
|
||||||
connect(fp, &FutureProgress::finished,
|
connect(fp, &FutureProgress::finished,
|
||||||
|
Reference in New Issue
Block a user