GUI: Separate tool statistics

This commit is contained in:
Daniel Marjamäki 2017-08-09 20:53:17 +02:00
parent 1c71c789d6
commit e675ede07d
8 changed files with 110 additions and 69 deletions

View File

@ -25,26 +25,34 @@ CheckStatistics::CheckStatistics(QObject *parent)
clear();
}
void CheckStatistics::addItem(ShowTypes::ShowType type)
static void addItem(QMap<QString,unsigned> &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<QString> 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());
}

View File

@ -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<QString, unsigned> mStyle;
QMap<QString, unsigned> mWarning;
QMap<QString, unsigned> mPerformance;
QMap<QString, unsigned> mPortability;
QMap<QString, unsigned> mInformation;
QMap<QString, unsigned> mError;
};
/// @}

View File

@ -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<ErrorItem> 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;

View File

@ -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;

View File

@ -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
{

View File

@ -79,6 +79,7 @@ public:
* @return Error item as string.
*/
QString ToString() const;
QString tool() const;
QString file0;
QString errorId;

View File

@ -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

View File

@ -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