diff options
Diffstat (limited to 'src/core/qscheduler.cpp')
-rw-r--r-- | src/core/qscheduler.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/core/qscheduler.cpp b/src/core/qscheduler.cpp index 9ff8a54f3..872b3ccd6 100644 --- a/src/core/qscheduler.cpp +++ b/src/core/qscheduler.cpp @@ -46,8 +46,42 @@ #include <Qt3DCore/private/qaspectjob_p.h> #include <Qt3DCore/private/qabstractaspectjobmanager_p.h> +#include <QtCore/QCoreApplication> +#include <QtCore/QDateTime> +#include <QtCore/QRegularExpression> + QT_BEGIN_NAMESPACE +namespace { + +// Creates a graphviz dot file. To view online: https://dreampuf.github.io/GraphvizOnline/ +void dumpJobs(QVector<Qt3DCore::QAspectJobPtr> jobs) { + const QString fileName = QStringLiteral("qt3djobs_") + QCoreApplication::applicationName() + + QDateTime::currentDateTime().toString(QStringLiteral("_yyMMdd-hhmmss")) + QStringLiteral(".dot"); + + QFile f(fileName); + if (!f.open(QFile::WriteOnly)) + return; + + auto formatJob = [](Qt3DCore::QAspectJob *job) -> QString { + auto jobId = Qt3DCore::QAspectJobPrivate::get(job)->m_jobId; + auto type = Qt3DCore::QAspectJobPrivate::get(job)->m_jobName.replace(QRegularExpression(QLatin1String("(^.*::)")), QLatin1String("")); + return QString(QLatin1String("\"%1_%2\"")).arg(type).arg(jobId.typeAndInstance[1]); + }; + + QTextStream stream(&f); + stream << "digraph qt3d_jobs {" << Qt::endl; + for (const auto &job: jobs) { + auto dependencies = job->dependencies(); + for (const auto &dependency: dependencies) + stream << QLatin1String("\t") << formatJob(job.data()) << QLatin1String(" -> ") << formatJob(dependency.toStrongRef().data()) << Qt::endl; + } + + stream << "}" << Qt::endl; +} + +} + namespace Qt3DCore { QScheduler::QScheduler(QObject *parent) @@ -70,7 +104,7 @@ QAspectManager *QScheduler::aspectManager() const return m_aspectManager; } -int QScheduler::scheduleAndWaitForFrameAspectJobs(qint64 time) +int QScheduler::scheduleAndWaitForFrameAspectJobs(qint64 time, bool dumpJobs) { QVector<QAspectJobPtr> jobQueue; @@ -86,6 +120,9 @@ int QScheduler::scheduleAndWaitForFrameAspectJobs(qint64 time) jobQueue << aspectJobs; } + if (dumpJobs) + ::dumpJobs(jobQueue); + m_aspectManager->jobManager()->enqueueJobs(jobQueue); // Do any other work here that the aspect thread can usefully be doing |