Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ namespace {
reportOut(msg.toXML());
}

void reportMetric(const std::string &metric) override
{
/* Not used here */
(void) metric;
}

void reportProgress(const std::string & /*filename*/, const char /*stage*/[], const std::size_t /*value*/) override
{}
};
Expand Down
24 changes: 24 additions & 0 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,23 @@ namespace {
*/
void reportErr(const std::string &errmsg);

void reportMetric(const std::string &metric) override
{
mFileMetrics.push_back(metric);
}

void reportMetrics()
{
if (!mFileMetrics.empty()) {
auto &out = mErrorOutput ? *mErrorOutput : std::cerr;
out << " <metrics>" << std::endl;
for (const auto &metric : mFileMetrics) {
out << " " << metric << std::endl;
}
out << " </metrics>" << std::endl;
}
}

/**
* @brief Write the checkers report
*/
Expand Down Expand Up @@ -353,6 +370,11 @@ namespace {
* Coding standard guideline mapping
*/
std::map<std::string, std::string> mGuidelineMapping;

/**
* File metrics
*/
std::vector<std::string> mFileMetrics;
};
}

Expand Down Expand Up @@ -487,6 +509,8 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup
stdLogger.writeCheckersReport(supprs);

if (settings.outputFormat == Settings::OutputFormat::xml) {
if (settings.xml_version == 3)
stdLogger.reportMetrics();
stdLogger.reportErr(ErrorMessage::getXMLFooter(settings.xml_version));
}

Expand Down
11 changes: 9 additions & 2 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ProcessExecutor::ProcessExecutor(const std::list<FileWithDetails> &files, const
namespace {
class PipeWriter : public ErrorLogger {
public:
enum PipeSignal : std::uint8_t {REPORT_OUT='1',REPORT_ERROR='2',REPORT_SUPPR_INLINE='3',REPORT_SUPPR='4',CHILD_END='5'};
enum PipeSignal : std::uint8_t {REPORT_OUT='1',REPORT_ERROR='2',REPORT_SUPPR_INLINE='3',REPORT_SUPPR='4',CHILD_END='5',REPORT_METRIC='6'};

explicit PipeWriter(int pipe) : mWpipe(pipe) {}

Expand All @@ -100,6 +100,10 @@ namespace {
}
}

void reportMetric(const std::string &metric) override {
writeToPipe(REPORT_METRIC, metric);
}

void writeEnd(const std::string& str) const {
writeToPipe(CHILD_END, str);
}
Expand Down Expand Up @@ -179,7 +183,8 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
type != PipeWriter::REPORT_ERROR &&
type != PipeWriter::REPORT_SUPPR_INLINE &&
type != PipeWriter::REPORT_SUPPR &&
type != PipeWriter::CHILD_END) {
type != PipeWriter::CHILD_END &&
type != PipeWriter::REPORT_METRIC) {
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") invalid type " << int(type) << std::endl;
std::exit(EXIT_FAILURE);
}
Expand Down Expand Up @@ -256,6 +261,8 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
} else if (type == PipeWriter::CHILD_END) {
result += std::stoi(buf);
res = false;
} else if (type == PipeWriter::REPORT_METRIC) {
mErrorLogger.reportMetric(buf);
}

return res;
Expand Down
5 changes: 5 additions & 0 deletions cli/threadexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class SyncLogForwarder : public ErrorLogger
mErrorLogger.reportErr(msg);
}

void reportMetric(const std::string &metric) override {
std::lock_guard<std::mutex> lg(mReportSync);
mErrorLogger.reportMetric(metric);
}

void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal) {
std::lock_guard<std::mutex> lg(mReportSync);
mThreadExecutor.reportStatus(fileindex, filecount, sizedone, sizetotal);
Expand Down
1 change: 1 addition & 0 deletions democlient/democlient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class CppcheckExecutor : public ErrorLogger {
if (logfile != nullptr)
std::fprintf(logfile, "%s\n", s.c_str());
}
void reportMetric(const std::string & /*metric*/) override {}

void reportProgress(const std::string& /*filename*/,
const char /*stage*/[],
Expand Down
Loading
Loading