From 04bc4a0aad419ccea9b8f46f389a670f692e57ab Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Mon, 24 Apr 2017 15:40:21 +0200 Subject: qmlbench: Switch to using std::cerr for output for debug This way, we can enable it while still outputting json to stdout, which means we have feedback on what is going on. Change-Id: I1fd65464c410ed61077aa664789a86e84dc57d96 Reviewed-by: Gunnar Sletta --- src/benchmarkrunner.cpp | 7 +++---- src/main.cpp | 6 +++--- src/options.h | 4 ++-- src/resultrecorder.cpp | 40 ++++++++++++++++++---------------------- 4 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/benchmarkrunner.cpp b/src/benchmarkrunner.cpp index 79e65da..6e52949 100644 --- a/src/benchmarkrunner.cpp +++ b/src/benchmarkrunner.cpp @@ -79,8 +79,8 @@ void BenchmarkRunner::start() { Benchmark &bm = Options::instance.benchmarks.first(); - if (bm.operationsPerFrame.size() == 0 && !Options::instance.onlyPrintJson) - std::cout << "running: " << bm.fileName.toStdString() << std::endl; + if (bm.operationsPerFrame.size() == 0) + std::cerr << "running: " << bm.fileName.toStdString() << std::endl; m_component = new QQmlComponent(m_view->engine(), bm.fileName); if (m_component->status() != QQmlComponent::Ready) { @@ -102,8 +102,7 @@ void BenchmarkRunner::start() void BenchmarkRunner::finished() { - if (!Options::instance.onlyPrintJson) - std::cout << "All done..." << std::endl; + std::cerr << "All done..." << std::endl; qApp->quit(); } diff --git a/src/main.cpp b/src/main.cpp index f47bd5b..adeffd9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -147,7 +147,7 @@ QStringList processCommandLineArguments(const QCoreApplication &app) Options::instance.isSubProcess = parser.isSet(subprocessOption); if (parser.isSet(jsonOption)) { - Options::instance.onlyPrintJson = true; + Options::instance.printJsonToStdout = true; } if (parser.isSet(helpOption) || parser.positionalArguments().size() == 0) { @@ -295,7 +295,7 @@ int runHostProcess(const QCoreApplication &app, const QStringList &positionalArg QObject::connect(p, &QProcess::readyReadStandardOutput, p, [&]() { QStringList lines = QString::fromLatin1(p->readAllStandardOutput()).split("\n"); for (const QString &ln : lines) { - if (!Options::instance.onlyPrintJson) { + if (!Options::instance.printJsonToStdout) { if (!ln.isEmpty()) std::cout << "SUB: " << ln.toLocal8Bit().constData() << "\n"; } else { @@ -324,7 +324,7 @@ int runHostProcess(const QCoreApplication &app, const QStringList &positionalArg } delete p; - if (Options::instance.onlyPrintJson) { + if (Options::instance.printJsonToStdout) { // Turn stdout into a JSON object and merge our results into the // final ones. QJsonParseError jerr; diff --git a/src/options.h b/src/options.h index 27b9d20..47b83ef 100644 --- a/src/options.h +++ b/src/options.h @@ -39,7 +39,7 @@ struct Options Options() : fullscreen(false) , verbose(false) - , onlyPrintJson(false) + , printJsonToStdout(false) , isSubProcess(false) , repeat(1) , delayedStart(0) @@ -57,7 +57,7 @@ struct Options QString id; bool fullscreen; bool verbose; - bool onlyPrintJson; + bool printJsonToStdout; bool isSubProcess; int repeat; int delayedStart; diff --git a/src/resultrecorder.cpp b/src/resultrecorder.cpp index 1b9064f..e69794e 100644 --- a/src/resultrecorder.cpp +++ b/src/resultrecorder.cpp @@ -105,7 +105,7 @@ void ResultRecorder::startResults(const QString &id) const char *version = (const char *) glGetString(GL_VERSION); #endif - if (!Options::instance.onlyPrintJson) { + if (!Options::instance.printJsonToStdout) { std::cout << "ID: " << id.toStdString() << std::endl; std::cout << "OS: " << prettyProductName.toStdString() << std::endl; std::cout << "QPA: " << QGuiApplication::platformName().toStdString() << std::endl; @@ -140,12 +140,10 @@ void ResultRecorder::recordOperationsPerFrame(int ops) benchMap["results"] = benchResults; m_results[bm.fileName] = benchMap; - if (!Options::instance.onlyPrintJson) { - if (opsAreActuallyFrames) - std::cout << " " << ops << " frames" << std::endl; - else - std::cout << " " << ops << " ops/frame" << std::endl; - } + if (opsAreActuallyFrames) + std::cerr << " " << ops << " frames" << std::endl; + else + std::cerr << " " << ops << " ops/frame" << std::endl; } void ResultRecorder::recordOperationsPerFrameAverage(qreal ops, int samples, qreal stddev, qreal median) @@ -162,20 +160,18 @@ void ResultRecorder::recordOperationsPerFrameAverage(qreal ops, int samples, qre benchMap["coefficient-of-variation"] = stddev / ops; benchMap["median"] = median; - if (!Options::instance.onlyPrintJson) { - std::string opsString; - if (opsAreActuallyFrames) - opsString = " frames"; - else - opsString = " ops/frame"; - - std::cout << " Average: " << ops << " " << opsString << ";" - << " using " << " samples" - << "; MedianAll=" << median - << "; StdDev=" << stddev - << ", CoV=" << (stddev / ops) - << std::endl; - } + std::string opsString; + if (opsAreActuallyFrames) + opsString = " frames"; + else + opsString = " ops/frame"; + + std::cerr << " Average: " << ops << " " << opsString << ";" + << " using " << " samples" + << "; MedianAll=" << median + << "; StdDev=" << stddev + << ", CoV=" << (stddev / ops) + << std::endl; m_results[bm.fileName] = benchMap; } @@ -190,7 +186,7 @@ void ResultRecorder::mergeResults(const QJsonObject &o) void ResultRecorder::finish() { - if (Options::instance.onlyPrintJson) { + if (Options::instance.printJsonToStdout) { QJsonDocument results = QJsonDocument::fromVariant(m_results); std::cout << results.toJson().constData(); } -- cgit v1.2.3