From e675ede07dd82e349c9d6e94627957b2ae3afb83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 9 Aug 2017 20:53:17 +0200 Subject: [PATCH] GUI: Separate tool statistics --- gui/checkstatistics.cpp | 60 +++++++++++++++++++++++++++-------------- gui/checkstatistics.h | 21 +++++++++------ gui/checkthread.cpp | 8 +++--- gui/checkthread.h | 2 +- gui/erroritem.cpp | 10 +++++++ gui/erroritem.h | 1 + gui/resultsview.cpp | 17 +++++++----- gui/statsdialog.cpp | 60 +++++++++++++++++++++-------------------- 8 files changed, 110 insertions(+), 69 deletions(-) diff --git a/gui/checkstatistics.cpp b/gui/checkstatistics.cpp index 785463975..1d053a671 100644 --- a/gui/checkstatistics.cpp +++ b/gui/checkstatistics.cpp @@ -25,26 +25,34 @@ CheckStatistics::CheckStatistics(QObject *parent) clear(); } -void CheckStatistics::addItem(ShowTypes::ShowType type) +static void addItem(QMap &m, const QString &key) { + if (m.contains(key)) + m[key]++; + else + m[key] = 0; +} + +void CheckStatistics::addItem(const QString &tool, ShowTypes::ShowType type) { + const QString lower = tool.toLower(); switch (type) { case ShowTypes::ShowStyle: - mStyle++; + ::addItem(mStyle, tool); break; case ShowTypes::ShowWarnings: - mWarning++; + ::addItem(mWarning, tool); break; case ShowTypes::ShowPerformance: - mPerformance++; + ::addItem(mPerformance, tool); break; case ShowTypes::ShowPortability: - mPortability++; + ::addItem(mPortability, tool); break; case ShowTypes::ShowErrors: - mError++; + ::addItem(mError, tool); break; case ShowTypes::ShowInformation: - mInformation++; + ::addItem(mInformation, tool); break; case ShowTypes::ShowNone: default: @@ -55,32 +63,44 @@ void CheckStatistics::addItem(ShowTypes::ShowType type) void CheckStatistics::clear() { - mStyle = 0; - mWarning = 0; - mPerformance = 0; - mPortability = 0; - mInformation = 0; - mError = 0; + mStyle.clear(); + mWarning.clear(); + mPerformance.clear(); + mPortability.clear(); + mInformation.clear(); + mError.clear(); } -unsigned CheckStatistics::getCount(ShowTypes::ShowType type) const +unsigned CheckStatistics::getCount(const QString &tool, ShowTypes::ShowType type) const { + const QString lower = tool.toLower(); switch (type) { case ShowTypes::ShowStyle: - return mStyle; + return mStyle.value(lower,0); case ShowTypes::ShowWarnings: - return mWarning; + return mWarning.value(lower,0); case ShowTypes::ShowPerformance: - return mPerformance; + return mPerformance.value(lower,0); case ShowTypes::ShowPortability: - return mPortability; + return mPortability.value(lower,0); case ShowTypes::ShowErrors: - return mError; + return mError.value(lower,0); case ShowTypes::ShowInformation: - return mInformation; + return mInformation.value(lower,0); case ShowTypes::ShowNone: default: qDebug() << "Unknown error type - returning zero statistics."; return 0; } } + +QStringList CheckStatistics::getTools() const +{ + QSet ret; + foreach (QString tool, mStyle.keys()) ret.insert(tool); + foreach (QString tool, mWarning.keys()) ret.insert(tool); + foreach (QString tool, mPerformance.keys()) ret.insert(tool); + foreach (QString tool, mPortability.keys()) ret.insert(tool); + foreach (QString tool, mError.keys()) ret.insert(tool); + return QStringList(ret.toList()); +} diff --git a/gui/checkstatistics.h b/gui/checkstatistics.h index 7cc55193f..5b0b59f7e 100644 --- a/gui/checkstatistics.h +++ b/gui/checkstatistics.h @@ -35,9 +35,10 @@ public: /** * @brief Add new checked item to statistics. * + * @param tool Tool. * @param type Type of the item to add. */ - void addItem(ShowTypes::ShowType type); + void addItem(const QString &tool, ShowTypes::ShowType type); /** * @brief Clear the statistics. @@ -48,18 +49,22 @@ public: /** * @brief Return statistics for given type. * + * @param tool Tool. * @param type Type for which the statistics are returned. * @return Number of items of given type. */ - unsigned getCount(ShowTypes::ShowType type) const; + unsigned getCount(const QString &tool, ShowTypes::ShowType type) const; + + /** Get tools with results */ + QStringList getTools() const; private: - unsigned mStyle; - unsigned mWarning; - unsigned mPerformance; - unsigned mPortability; - unsigned mInformation; - unsigned mError; + QMap mStyle; + QMap mWarning; + QMap mPerformance; + QMap mPortability; + QMap mInformation; + QMap mError; }; /// @} diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp index 0a33a954e..e991b8458 100644 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -184,7 +184,7 @@ void CheckThread::runAddons(const QString &addonPath, const ImportProject::FileS QFile f2(analyzerInfoFile + '.' + addon + "-results"); if (f2.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in2(&f2); - parseClangErrors(fileName, in2.readAll()); + parseClangErrors(addon, fileName, in2.readAll()); continue; } } @@ -239,7 +239,7 @@ void CheckThread::runAddons(const QString &addonPath, const ImportProject::FileS out << errout; } } - parseClangErrors(fileName, errout); + parseClangErrors(addon, fileName, errout); } else { QString a; if (QFileInfo(addonPath + '/' + addon + ".py").exists()) @@ -324,7 +324,7 @@ void CheckThread::parseAddonErrors(QString err, QString tool) } } -void CheckThread::parseClangErrors(const QString &file0, QString err) +void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QString err) { QList errorItems; ErrorItem errorItem; @@ -351,7 +351,7 @@ void CheckThread::parseClangErrors(const QString &file0, QString err) QString message,id; if (r2.exactMatch(r1.cap(4))) { message = r2.cap(1); - id = r2.cap(2); + id = tool + '-' + r2.cap(2); } else { message = r1.cap(4); id = CLANG; diff --git a/gui/checkthread.h b/gui/checkthread.h index 7728fde86..5cfa68019 100644 --- a/gui/checkthread.h +++ b/gui/checkthread.h @@ -119,7 +119,7 @@ private: void runAddons(const QString &addonPath, const ImportProject::FileSettings *fileSettings, const QString &fileName); void parseAddonErrors(QString err, QString tool); - void parseClangErrors(const QString &file0, QString err); + void parseClangErrors(const QString &tool, const QString &file0, QString err); QStringList mFiles; bool mAnalyseWholeProgram; diff --git a/gui/erroritem.cpp b/gui/erroritem.cpp index 235667c8d..778bab122 100644 --- a/gui/erroritem.cpp +++ b/gui/erroritem.cpp @@ -55,6 +55,16 @@ ErrorItem::ErrorItem(const ErrorLogger::ErrorMessage &errmsg) } } +QString ErrorItem::tool() const +{ + if (errorId == "clang") + return "clang"; + if (errorId.startsWith("clang-tidy")) + return "clang-tidy"; + if (errorId.startsWith("clang-")) + return "clang"; + return "cppcheck"; +} QString ErrorItem::ToString() const { diff --git a/gui/erroritem.h b/gui/erroritem.h index 3066ed33a..e0403f205 100644 --- a/gui/erroritem.h +++ b/gui/erroritem.h @@ -79,6 +79,7 @@ public: * @return Error item as string. */ QString ToString() const; + QString tool() const; QString file0; QString errorId; diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 54d2c8240..31e7a8ede 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -107,7 +107,7 @@ void ResultsView::error(const ErrorItem &item) { if (mUI.mTree->addErrorItem(item)) { emit gotResults(); - mStatistics->addItem(ShowTypes::SeverityToShowType(item.severity)); + mStatistics->addItem(item.tool(), ShowTypes::SeverityToShowType(item.severity)); } } @@ -142,12 +142,15 @@ void ResultsView::saveStatistics(const QString &filename) const if (!f.open(QIODevice::Text | QIODevice::Append)) return; QTextStream ts(&f); - ts << '[' << QDate::currentDate().toString("dd.MM.yyyy") << "]\n"; - ts << "error:" << mStatistics->getCount(ShowTypes::ShowErrors) << '\n'; - ts << "warning:" << mStatistics->getCount(ShowTypes::ShowWarnings) << '\n'; - ts << "style:" << mStatistics->getCount(ShowTypes::ShowStyle) << '\n'; - ts << "performance:" << mStatistics->getCount(ShowTypes::ShowPerformance) << '\n'; - ts << "portability:" << mStatistics->getCount(ShowTypes::ShowPortability) << '\n'; + ts << '[' << QDate::currentDate().toString("dd.MM.yyyy") << "]\n"; + ts << QDateTime::currentMSecsSinceEpoch() + '\n'; + foreach (QString tool, mStatistics->getTools()) { + ts << tool << "-error:" << mStatistics->getCount(tool, ShowTypes::ShowErrors) << '\n'; + ts << tool << "-warning:" << mStatistics->getCount(tool, ShowTypes::ShowWarnings) << '\n'; + ts << tool << "-style:" << mStatistics->getCount(tool, ShowTypes::ShowStyle) << '\n'; + ts << tool << "-performance:" << mStatistics->getCount(tool, ShowTypes::ShowPerformance) << '\n'; + ts << tool << "-portability:" << mStatistics->getCount(tool, ShowTypes::ShowPortability) << '\n'; + } } void ResultsView::updateFromOldReport(const QString &filename) const diff --git a/gui/statsdialog.cpp b/gui/statsdialog.cpp index bcd0a4edf..c372f3f8f 100644 --- a/gui/statsdialog.cpp +++ b/gui/statsdialog.cpp @@ -29,6 +29,8 @@ #include "statsdialog.h" #include "checkstatistics.h" +static const QString CPPCHECK("cppcheck"); + StatsDialog::StatsDialog(QWidget *parent) : QDialog(parent), mStatistics(nullptr) @@ -54,11 +56,11 @@ void StatsDialog::setProject(const ProjectFile* projectFile) const QString buildDir = prjpath + '/' + projectFile->getBuildDir(); if (QDir(buildDir).exists()) { QChart *chart = new QChart(); - chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "error")); - chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "warning")); - chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "style")); - chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "performance")); - chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "portability")); + chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "cppcheck-error")); + chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "cppcheck-warning")); + chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "cppcheck-style")); + chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "cppcheck-performance")); + chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "cppcheck-portability")); QDateTimeAxis *axisX = new QDateTimeAxis; axisX->setFormat("MMM yyyy"); @@ -154,17 +156,17 @@ void StatsDialog::pdfExport() .arg(tr("Statistics")) .arg(QDate::currentDate().toString("dd.MM.yyyy")) .arg(tr("Errors")) - .arg(mStatistics->getCount(ShowTypes::ShowErrors)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowErrors)) .arg(tr("Warnings")) - .arg(mStatistics->getCount(ShowTypes::ShowWarnings)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowWarnings)) .arg(tr("Style warnings")) - .arg(mStatistics->getCount(ShowTypes::ShowStyle)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowStyle)) .arg(tr("Portability warnings")) - .arg(mStatistics->getCount(ShowTypes::ShowPortability)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowPortability)) .arg(tr("Performance warnings")) - .arg(mStatistics->getCount(ShowTypes::ShowPerformance)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowPerformance)) .arg(tr("Information messages")) - .arg(mStatistics->getCount(ShowTypes::ShowInformation)); + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowInformation)); QString fileName = QFileDialog::getSaveFileName((QWidget*)0, tr("Export PDF"), QString(), "*.pdf"); if (QFileInfo(fileName).suffix().isEmpty()) { @@ -248,17 +250,17 @@ void StatsDialog::copyToClipboard() ) .arg(stats) .arg(errors) - .arg(mStatistics->getCount(ShowTypes::ShowErrors)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowErrors)) .arg(warnings) - .arg(mStatistics->getCount(ShowTypes::ShowWarnings)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowWarnings)) .arg(style) - .arg(mStatistics->getCount(ShowTypes::ShowStyle)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowStyle)) .arg(portability) - .arg(mStatistics->getCount(ShowTypes::ShowPortability)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowPortability)) .arg(performance) - .arg(mStatistics->getCount(ShowTypes::ShowPerformance)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowPerformance)) .arg(information) - .arg(mStatistics->getCount(ShowTypes::ShowInformation)); + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowInformation)); const QString textSummary = settings + previous + statistics; @@ -310,17 +312,17 @@ void StatsDialog::copyToClipboard() ) .arg(stats) .arg(errors) - .arg(mStatistics->getCount(ShowTypes::ShowErrors)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowErrors)) .arg(warnings) - .arg(mStatistics->getCount(ShowTypes::ShowWarnings)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowWarnings)) .arg(style) - .arg(mStatistics->getCount(ShowTypes::ShowStyle)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowStyle)) .arg(portability) - .arg(mStatistics->getCount(ShowTypes::ShowPortability)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowPortability)) .arg(performance) - .arg(mStatistics->getCount(ShowTypes::ShowPerformance)) + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowPerformance)) .arg(information) - .arg(mStatistics->getCount(ShowTypes::ShowInformation)); + .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowInformation)); const QString htmlSummary = htmlSettings + htmlPrevious + htmlStatistics; @@ -333,12 +335,12 @@ void StatsDialog::copyToClipboard() void StatsDialog::setStatistics(const CheckStatistics *stats) { mStatistics = stats; - mUI.mLblErrors->setText(QString("%1").arg(stats->getCount(ShowTypes::ShowErrors))); - mUI.mLblWarnings->setText(QString("%1").arg(stats->getCount(ShowTypes::ShowWarnings))); - mUI.mLblStyle->setText(QString("%1").arg(stats->getCount(ShowTypes::ShowStyle))); - mUI.mLblPortability->setText(QString("%1").arg(stats->getCount(ShowTypes::ShowPortability))); - mUI.mLblPerformance->setText(QString("%1").arg(stats->getCount(ShowTypes::ShowPerformance))); - mUI.mLblInformation->setText(QString("%1").arg(stats->getCount(ShowTypes::ShowInformation))); + mUI.mLblErrors->setText(QString("%1").arg(stats->getCount(CPPCHECK,ShowTypes::ShowErrors))); + mUI.mLblWarnings->setText(QString("%1").arg(stats->getCount(CPPCHECK,ShowTypes::ShowWarnings))); + mUI.mLblStyle->setText(QString("%1").arg(stats->getCount(CPPCHECK,ShowTypes::ShowStyle))); + mUI.mLblPortability->setText(QString("%1").arg(stats->getCount(CPPCHECK,ShowTypes::ShowPortability))); + mUI.mLblPerformance->setText(QString("%1").arg(stats->getCount(CPPCHECK,ShowTypes::ShowPerformance))); + mUI.mLblInformation->setText(QString("%1").arg(stats->getCount(CPPCHECK,ShowTypes::ShowInformation))); } #ifdef HAVE_QCHART