Commit d89bd9ff authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Add file name to qtc.clangbackend.jobs output

This helps to overview debug output in case several files are involved.

Change-Id: I12ee23bd7cec4cd344746ef1323afb3f0ab54d4b
Reviewed-by: Marco Bubke's avatarMarco Bubke <marco.bubke@qt.io>
parent e0bbb0a0
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QFileInfo>
namespace ClangBackEnd { namespace ClangBackEnd {
class DocumentProcessorData class DocumentProcessorData
...@@ -47,7 +49,7 @@ public: ...@@ -47,7 +49,7 @@ public:
ClangCodeModelClientInterface &client) ClangCodeModelClientInterface &client)
: document(document) : document(document)
, documents(documents) , documents(documents)
, jobs(documents, unsavedFiles, projects, client) , jobs(documents, unsavedFiles, projects, client, QFileInfo(document.filePath()).fileName())
, supportiveTranslationUnitInitializer(document, jobs) , supportiveTranslationUnitInitializer(document, jobs)
{ {
const auto isDocumentClosedChecker = [this](const Utf8String &filePath, const auto isDocumentClosedChecker = [this](const Utf8String &filePath,
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <functional> #include <functional>
Q_DECLARE_LOGGING_CATEGORY(jobsLog); Q_DECLARE_LOGGING_CATEGORY(jobsLog);
#define qCDebugJobs() qCDebug(jobsLog) << "[" << m_logTag << "]"
namespace ClangBackEnd { namespace ClangBackEnd {
......
...@@ -35,9 +35,10 @@ ...@@ -35,9 +35,10 @@
namespace ClangBackEnd { namespace ClangBackEnd {
JobQueue::JobQueue(Documents &documents, ProjectParts &projectParts) JobQueue::JobQueue(Documents &documents, ProjectParts &projectParts, const Utf8String &logTag)
: m_documents(documents) : m_documents(documents)
, m_projectParts(projectParts) , m_projectParts(projectParts)
, m_logTag(logTag)
{ {
} }
...@@ -45,11 +46,11 @@ bool JobQueue::add(const JobRequest &job) ...@@ -45,11 +46,11 @@ bool JobQueue::add(const JobRequest &job)
{ {
QString notAddableReason; QString notAddableReason;
if (isJobRequestAddable(job, notAddableReason)) { if (isJobRequestAddable(job, notAddableReason)) {
qCDebug(jobsLog) << "Adding" << job; qCDebugJobs() << "Adding" << job;
m_queue.append(job); m_queue.append(job);
return true; return true;
} else { } else {
qCDebug(jobsLog) << "Not adding" << job << notAddableReason; qCDebugJobs() << "Not adding" << job << notAddableReason;
cancelJobRequest(job); cancelJobRequest(job);
return false; return false;
} }
...@@ -77,7 +78,7 @@ void JobQueue::removeExpiredRequests() ...@@ -77,7 +78,7 @@ void JobQueue::removeExpiredRequests()
try { try {
QString expirationReason; QString expirationReason;
if (isJobRequestExpired(jobRequest, expirationReason)) { if (isJobRequestExpired(jobRequest, expirationReason)) {
qCDebug(jobsLog) << "Expired:" << jobRequest << expirationReason; qCDebugJobs() << "Expired:" << jobRequest << expirationReason;
cancelJobRequest(jobRequest); cancelJobRequest(jobRequest);
} else { } else {
cleanedRequests.append(jobRequest); cleanedRequests.append(jobRequest);
...@@ -207,28 +208,28 @@ void JobQueue::cancelJobRequest(const JobRequest &jobRequest) ...@@ -207,28 +208,28 @@ void JobQueue::cancelJobRequest(const JobRequest &jobRequest)
m_cancelJobRequest(jobRequest); m_cancelJobRequest(jobRequest);
} }
static bool areRunConditionsMet(const JobRequest &request, const Document &document) bool JobQueue::areRunConditionsMet(const JobRequest &request, const Document &document) const
{ {
using Condition = JobRequest::RunCondition; using Condition = JobRequest::RunCondition;
const JobRequest::RunConditions conditions = request.runConditions; const JobRequest::RunConditions conditions = request.runConditions;
if (conditions.testFlag(Condition::DocumentSuspended) && !document.isSuspended()) { if (conditions.testFlag(Condition::DocumentSuspended) && !document.isSuspended()) {
qCDebug(jobsLog) << "Not choosing due to unsuspended document:" << request; qCDebugJobs() << "Not choosing due to unsuspended document:" << request;
return false; return false;
} }
if (conditions.testFlag(Condition::DocumentUnsuspended) && document.isSuspended()) { if (conditions.testFlag(Condition::DocumentUnsuspended) && document.isSuspended()) {
qCDebug(jobsLog) << "Not choosing due to suspended document:" << request; qCDebugJobs() << "Not choosing due to suspended document:" << request;
return false; return false;
} }
if (conditions.testFlag(Condition::DocumentVisible) && !document.isVisibleInEditor()) { if (conditions.testFlag(Condition::DocumentVisible) && !document.isVisibleInEditor()) {
qCDebug(jobsLog) << "Not choosing due to invisble document:" << request; qCDebugJobs() << "Not choosing due to invisble document:" << request;
return false; return false;
} }
if (conditions.testFlag(Condition::DocumentNotVisible) && document.isVisibleInEditor()) { if (conditions.testFlag(Condition::DocumentNotVisible) && document.isVisibleInEditor()) {
qCDebug(jobsLog) << "Not choosing due to visble document:" << request; qCDebugJobs() << "Not choosing due to visble document:" << request;
return false; return false;
} }
...@@ -236,12 +237,12 @@ static bool areRunConditionsMet(const JobRequest &request, const Document &docum ...@@ -236,12 +237,12 @@ static bool areRunConditionsMet(const JobRequest &request, const Document &docum
if (document.isDirty()) { if (document.isDirty()) {
// TODO: If the document is dirty due to a project update, // TODO: If the document is dirty due to a project update,
// references are processes later than ideal. // references are processes later than ideal.
qCDebug(jobsLog) << "Not choosing due to dirty document:" << request; qCDebugJobs() << "Not choosing due to dirty document:" << request;
return false; return false;
} }
if (request.documentRevision != document.documentRevision()) { if (request.documentRevision != document.documentRevision()) {
qCDebug(jobsLog) << "Not choosing due to revision mismatch:" << request; qCDebugJobs() << "Not choosing due to revision mismatch:" << request;
return false; return false;
} }
} }
......
...@@ -37,7 +37,7 @@ class Documents; ...@@ -37,7 +37,7 @@ class Documents;
class JobQueue class JobQueue
{ {
public: public:
JobQueue(Documents &documents, ProjectParts &projects); JobQueue(Documents &documents, ProjectParts &projects, const Utf8String &logTag = Utf8String());
bool add(const JobRequest &job); bool add(const JobRequest &job);
...@@ -61,6 +61,7 @@ public: // for tests ...@@ -61,6 +61,7 @@ public: // for tests
void prioritizeRequests(); void prioritizeRequests();
private: private:
bool areRunConditionsMet(const JobRequest &request, const Document &document) const;
void cancelJobRequest(const JobRequest &jobRequest); void cancelJobRequest(const JobRequest &jobRequest);
bool isJobRunningForTranslationUnit(const Utf8String &translationUnitId); bool isJobRunningForTranslationUnit(const Utf8String &translationUnitId);
bool isJobRunningForJobRequest(const JobRequest &jobRequest); bool isJobRunningForJobRequest(const JobRequest &jobRequest);
...@@ -72,6 +73,7 @@ private: ...@@ -72,6 +73,7 @@ private:
private: private:
Documents &m_documents; Documents &m_documents;
ProjectParts &m_projectParts; ProjectParts &m_projectParts;
Utf8String m_logTag;
IsJobRunningForTranslationUnitHandler m_isJobRunningForTranslationUnitHandler; IsJobRunningForTranslationUnitHandler m_isJobRunningForTranslationUnitHandler;
IsJobRunningForJobRequestHandler m_isJobRunningForJobRequestHandler; IsJobRunningForJobRequestHandler m_isJobRunningForJobRequestHandler;
......
...@@ -41,12 +41,14 @@ namespace ClangBackEnd { ...@@ -41,12 +41,14 @@ namespace ClangBackEnd {
Jobs::Jobs(Documents &documents, Jobs::Jobs(Documents &documents,
UnsavedFiles &unsavedFiles, UnsavedFiles &unsavedFiles,
ProjectParts &projectParts, ProjectParts &projectParts,
ClangCodeModelClientInterface &client) ClangCodeModelClientInterface &client,
const Utf8String &logTag)
: m_documents(documents) : m_documents(documents)
, m_unsavedFiles(unsavedFiles) , m_unsavedFiles(unsavedFiles)
, m_projectParts(projectParts) , m_projectParts(projectParts)
, m_client(client) , m_client(client)
, m_queue(documents, projectParts) , m_logTag(logTag)
, m_queue(documents, projectParts, logTag)
{ {
m_queue.setIsJobRunningForTranslationUnitHandler([this](const Utf8String &translationUnitId) { m_queue.setIsJobRunningForTranslationUnitHandler([this](const Utf8String &translationUnitId) {
return isJobRunningForTranslationUnit(translationUnitId); return isJobRunningForTranslationUnit(translationUnitId);
...@@ -132,8 +134,8 @@ bool Jobs::runJob(const JobRequest &jobRequest) ...@@ -132,8 +134,8 @@ bool Jobs::runJob(const JobRequest &jobRequest)
asyncJob->setContext(context); asyncJob->setContext(context);
if (const IAsyncJob::AsyncPrepareResult prepareResult = asyncJob->prepareAsyncRun()) { if (const IAsyncJob::AsyncPrepareResult prepareResult = asyncJob->prepareAsyncRun()) {
qCDebug(jobsLog) << "Running" << jobRequest qCDebugJobs() << "Running" << jobRequest
<< "with TranslationUnit" << prepareResult.translationUnitId; << "with TranslationUnit" << prepareResult.translationUnitId;
asyncJob->setFinishedHandler([this](IAsyncJob *asyncJob){ onJobFinished(asyncJob); }); asyncJob->setFinishedHandler([this](IAsyncJob *asyncJob){ onJobFinished(asyncJob); });
const QFuture<void> future = asyncJob->runAsync(); const QFuture<void> future = asyncJob->runAsync();
...@@ -142,7 +144,7 @@ bool Jobs::runJob(const JobRequest &jobRequest) ...@@ -142,7 +144,7 @@ bool Jobs::runJob(const JobRequest &jobRequest)
m_running.insert(asyncJob, runningJob); m_running.insert(asyncJob, runningJob);
return true; return true;
} else { } else {
qCDebug(jobsLog) << "Preparation failed for " << jobRequest; qCDebugJobs() << "Preparation failed for " << jobRequest;
delete asyncJob; delete asyncJob;
} }
...@@ -151,7 +153,7 @@ bool Jobs::runJob(const JobRequest &jobRequest) ...@@ -151,7 +153,7 @@ bool Jobs::runJob(const JobRequest &jobRequest)
void Jobs::onJobFinished(IAsyncJob *asyncJob) void Jobs::onJobFinished(IAsyncJob *asyncJob)
{ {
qCDebug(jobsLog) << "Finishing" << asyncJob->context().jobRequest; qCDebugJobs() << "Finishing" << asyncJob->context().jobRequest;
if (m_jobFinishedCallback) { if (m_jobFinishedCallback) {
const RunningJob runningJob = m_running.value(asyncJob); const RunningJob runningJob = m_running.value(asyncJob);
......
...@@ -56,7 +56,8 @@ public: ...@@ -56,7 +56,8 @@ public:
Jobs(Documents &documents, Jobs(Documents &documents,
UnsavedFiles &unsavedFiles, UnsavedFiles &unsavedFiles,
ProjectParts &projects, ProjectParts &projects,
ClangCodeModelClientInterface &client); ClangCodeModelClientInterface &client,
const Utf8String &logTag = Utf8String());
~Jobs(); ~Jobs();
JobRequest createJobRequest(const Document &document, JobRequest::Type type, JobRequest createJobRequest(const Document &document, JobRequest::Type type,
...@@ -90,6 +91,7 @@ private: ...@@ -90,6 +91,7 @@ private:
UnsavedFiles &m_unsavedFiles; UnsavedFiles &m_unsavedFiles;
ProjectParts &m_projectParts; ProjectParts &m_projectParts;
ClangCodeModelClientInterface &m_client; ClangCodeModelClientInterface &m_client;
Utf8String m_logTag;
JobQueue m_queue; JobQueue m_queue;
RunningJobs m_running; RunningJobs m_running;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment