From 74643556f964337882ab4287ce4c955ca824e09f Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Thu, 17 Feb 2022 10:22:09 +0100 Subject: [PATCH] Utils: Print out QtcProcess number in result debug log That makes it easier to understand which result belongs to which process. And make the result output a 1-liner in the case of logging, which makes filtering easier. Change-Id: I6da84d28fe2269d2d6dfe6f5a1d300faf5697ca1 Reviewed-by: Jarek Kobus --- src/libs/utils/qtcprocess.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/libs/utils/qtcprocess.cpp b/src/libs/utils/qtcprocess.cpp index 3cef40e5742..20e06382b83 100644 --- a/src/libs/utils/qtcprocess.cpp +++ b/src/libs/utils/qtcprocess.cpp @@ -70,6 +70,7 @@ namespace Utils { namespace Internal { const char QTC_PROCESS_BLOCKING_TYPE[] = "__BLOCKING_TYPE__"; +const char QTC_PROCESS_NUMBER[] = "__NUMBER__"; class MeasureAndRun { @@ -582,10 +583,12 @@ static QString blockingMessage(const QVariant &variant) void ProcessInterface::defaultStart() { if (processLog().isDebugEnabled()) { - static std::atomic_int n = 0; - qCDebug(processLog) << "Starting process no." << ++n + static std::atomic_int startCounter = 0; + const int currentNumber = startCounter.fetch_add(1); + qCDebug(processLog) << "Starting process no." << currentNumber << qPrintable(blockingMessage(property(QTC_PROCESS_BLOCKING_TYPE))) << m_setup.m_commandLine.toUserOutput(); + setProperty(QTC_PROCESS_NUMBER, currentNumber); } QString program; @@ -675,6 +678,18 @@ QtcProcess::QtcProcess(QObject *parent) static int qProcessProcessErrorMeta = qRegisterMetaType(); Q_UNUSED(qProcessExitStatusMeta) Q_UNUSED(qProcessProcessErrorMeta) + + if (processLog().isDebugEnabled()) { + connect(this, &QtcProcess::finished, [this] { + if (const QVariant n = d->m_process.get()->property(QTC_PROCESS_NUMBER); n.isValid()) { + qCDebug(processLog).nospace() << "Process no. " << n.toInt() << " finished: " + << "result=" << result() + << ", ex=" << exitCode() + << ", " << stdOut().size() << " bytes stdout" + ", stderr=" << stdErr(); + } + }); + } } QtcProcess::~QtcProcess() @@ -1505,8 +1520,6 @@ void QtcProcess::runBlocking(QtcProcess::EventLoopMode eventLoopMode) setProperty(QTC_PROCESS_BLOCKING_TYPE, int(eventLoopMode)); } - ExecuteOnDestruction logResult([this] { qCDebug(processLog) << *this; }); - QtcProcess::start(); if (processLog().isDebugEnabled()) { // Remove the dynamic property so that it's not reused in subseqent start()