From e23dcafe4dc805f0ad69156c15a5566572b683e3 Mon Sep 17 00:00:00 2001 From: Anett Fekete Date: Fri, 8 Mar 2024 23:25:42 +0100 Subject: [PATCH 01/11] Get all module-level metric types and all metrics for one module. --- plugins/cpp_metrics/service/cxxmetrics.thrift | 43 +++++++++++++--- .../include/service/cppmetricsservice.h | 15 ++++-- .../service/src/cppmetricsservice.cpp | 49 +++++++++++++++---- 3 files changed, 88 insertions(+), 19 deletions(-) diff --git a/plugins/cpp_metrics/service/cxxmetrics.thrift b/plugins/cpp_metrics/service/cxxmetrics.thrift index 0762ac534..83c8c93a0 100644 --- a/plugins/cpp_metrics/service/cxxmetrics.thrift +++ b/plugins/cpp_metrics/service/cxxmetrics.thrift @@ -4,7 +4,7 @@ include "project/project.thrift" namespace cpp cc.service.cppmetrics namespace java cc.service.cppmetrics -enum CppMetricsType +enum CppAstNodeMetricsType { ParameterCount = 1, McCabe = 2, @@ -12,15 +12,32 @@ enum CppMetricsType LackOfCohesionHS = 4 } -struct CppMetricsTypeName +enum CppModuleMetricsType { - 1:CppMetricsType type, + Placeholder = 1 +} + +struct CppAstNodeMetricsTypeName +{ + 1:CppAstNodeMetricsType type, + 2:string name +} + +struct CppModuleMetricsTypeName +{ + 1:CppModuleMetricsType type, 2:string name } struct CppMetricsAstNode { - 1:CppMetricsType type, + 1:CppAstNodeMetricsType type, + 2:double value +} + +struct CppMetricsModule +{ + 1:CppModuleMetricsType type, 2:double value } @@ -32,7 +49,7 @@ service CppMetricsService */ double getSingleCppMetricForAstNode( 1:common.AstNodeId astNodeId, - 2:CppMetricsType metric) + 2:CppAstNodeMetricsType metric) /** * This function returns all available C++ metrics @@ -42,7 +59,19 @@ service CppMetricsService 1:common.AstNodeId astNodeId) /** - * This function returns the names of metrics. + * This function returns all available C++ metrics + * for a particular module. + */ + list getCppMetricsForModule( + 1:common.FileId fileId) + + /** + * This function returns the names of AST node metrics. + */ + list getCppAstNodeMetricsTypeNames() + + /** + * This function returns the names of module-level metrics. */ - list getCppMetricsTypeNames() + list getCppModuleMetricsTypeNames() } \ No newline at end of file diff --git a/plugins/cpp_metrics/service/include/service/cppmetricsservice.h b/plugins/cpp_metrics/service/include/service/cppmetricsservice.h index 4a65bd306..8c5bdd7a7 100644 --- a/plugins/cpp_metrics/service/include/service/cppmetricsservice.h +++ b/plugins/cpp_metrics/service/include/service/cppmetricsservice.h @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include @@ -36,14 +38,21 @@ class CppMetricsServiceHandler : virtual public CppMetricsServiceIf double getSingleCppMetricForAstNode( const core::AstNodeId& astNodeId_, - CppMetricsType::type metric_) override; + CppAstNodeMetricsType::type metric_) override; void getCppMetricsForAstNode( std::vector& _return, const core::AstNodeId& astNodeId_) override; - void getCppMetricsTypeNames( - std::vector& _return) override; + void getCppMetricsForModule( + std::vector& _return, + const core::FileId& fileId_) override; + + void getCppAstNodeMetricsTypeNames( + std::vector& _return) override; + + void getCppModuleMetricsTypeNames( + std::vector& _return) override; private: std::shared_ptr _db; diff --git a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp index d1b7c5556..510794a1e 100644 --- a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp +++ b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp @@ -16,28 +16,38 @@ CppMetricsServiceHandler::CppMetricsServiceHandler( { } -void CppMetricsServiceHandler::getCppMetricsTypeNames( - std::vector& _return) +void CppMetricsServiceHandler::getCppAstNodeMetricsTypeNames( + std::vector& _return) { - CppMetricsTypeName typeName; + CppAstNodeMetricsTypeName typeName; - typeName.type = CppMetricsType::ParameterCount; + typeName.type = CppAstNodeMetricsType::ParameterCount; typeName.name = "Number of function parameters"; _return.push_back(typeName); - typeName.type = CppMetricsType::McCabe; + typeName.type = CppAstNodeMetricsType::McCabe; typeName.name = "McCabe metric"; _return.push_back(typeName); - typeName.type = CppMetricsType::LackOfCohesion; + typeName.type = CppAstNodeMetricsType::LackOfCohesion; typeName.name = "Lack of cohesion of function"; _return.push_back(typeName); - typeName.type = CppMetricsType::LackOfCohesionHS; + typeName.type = CppAstNodeMetricsType::LackOfCohesionHS; typeName.name = "Lack of cohesion of function (Henderson-Sellers variant)"; _return.push_back(typeName); } +void CppMetricsServiceHandler::getCppModuleMetricsTypeNames( + std::vector& _return) +{ + CppModuleMetricsTypeName typeName; + + typeName.type = CppModuleMetricsType::Placeholder; + typeName.name = "Placeholder"; + _return.push_back(typeName); +} + void CppMetricsServiceHandler::getCppMetricsForAstNode( std::vector& _return, const core::AstNodeId& astNodeId_) @@ -52,7 +62,7 @@ void CppMetricsServiceHandler::getCppMetricsForAstNode( for (const auto& nodeMetric : nodeMetrics) { - metric.type = static_cast(nodeMetric.type); + metric.type = static_cast(nodeMetric.type); metric.value = nodeMetric.value; _return.push_back(metric); } @@ -61,7 +71,7 @@ void CppMetricsServiceHandler::getCppMetricsForAstNode( double CppMetricsServiceHandler::getSingleCppMetricForAstNode( const core::AstNodeId& astNodeId_, - CppMetricsType::type metric_) + CppAstNodeMetricsType::type metric_) { return _transaction([&, this]() -> std::double_t { typedef odb::query CppAstNodeMetricsQuery; @@ -81,6 +91,27 @@ double CppMetricsServiceHandler::getSingleCppMetricForAstNode( }); } +void CppMetricsServiceHandler::getCppMetricsForModule( + std::vector& _return, + const core::FileId& fileId_) +{ + CppMetricsModule metric; + + _transaction([&, this](){ + typedef odb::query CppModuleMetricsQuery; + + auto moduleMetrics = _db->query( + CppModuleMetricsQuery::file == std::stoull(fileId_)); + + for (const auto& moduleMetric : moduleMetrics) + { + metric.type = static_cast(moduleMetric.type); + metric.value = moduleMetric.value; + _return.push_back(metric); + } + }); +} + } // cppmetrics } // service } // cc From e9f8c4c22551bccd5c4bd8a101d213c333ac4858 Mon Sep 17 00:00:00 2001 From: Anett Fekete Date: Sun, 24 Mar 2024 01:42:32 +0100 Subject: [PATCH 02/11] Endpoints to query all metrics for AST nodes and modules WIP --- plugins/cpp/model/include/model/cppastnode.h | 12 +++ plugins/cpp_metrics/service/cxxmetrics.thrift | 43 +++++++++ .../include/service/cppmetricsservice.h | 8 ++ .../service/src/cppmetricsservice.cpp | 96 +++++++++++++++++++ 4 files changed, 159 insertions(+) diff --git a/plugins/cpp/model/include/model/cppastnode.h b/plugins/cpp/model/include/model/cppastnode.h index 67f93507b..717437e27 100644 --- a/plugins/cpp/model/include/model/cppastnode.h +++ b/plugins/cpp/model/include/model/cppastnode.h @@ -230,6 +230,18 @@ struct AstCountGroupByFiles std::size_t count; }; +#pragma db view \ + object(CppAstNode) \ + object(File = LocFile : CppAstNode::location.file) +struct CppAstNodeFilePath +{ + #pragma db column(CppAstNode::id) + CppAstNodeId id; + + #pragma db column(LocFile::path) + std::string path; +}; + #pragma db view object(CppAstNode) struct CppAstCount { diff --git a/plugins/cpp_metrics/service/cxxmetrics.thrift b/plugins/cpp_metrics/service/cxxmetrics.thrift index 83c8c93a0..ce0758da6 100644 --- a/plugins/cpp_metrics/service/cxxmetrics.thrift +++ b/plugins/cpp_metrics/service/cxxmetrics.thrift @@ -4,6 +4,12 @@ include "project/project.thrift" namespace cpp cc.service.cppmetrics namespace java cc.service.cppmetrics +enum CppUnitType +{ + AstNodeUnit = 1, + FileUnit = 2 +} + enum CppAstNodeMetricsType { ParameterCount = 1, @@ -35,12 +41,35 @@ struct CppMetricsAstNode 2:double value } +struct CppAllMetricsAstNode +{ + 1:common.AstNodeId id, + 2:list metrics +} + struct CppMetricsModule { 1:CppModuleMetricsType type, 2:double value } +struct CppAllMetricsModule +{ + 1:common.FileId id, + 2:list metrics +} + +// Thrift does not provide a union type, +// the ids can remain empty. +struct CppMetricsPath +{ + 1:CppUnitType type + 2:common.AstNodeId astNodeId + 3:list astNodeIdMetrics + 4:common.FileId fileId + 5:list fileMetrics +} + service CppMetricsService { /** @@ -65,6 +94,20 @@ service CppMetricsService list getCppMetricsForModule( 1:common.FileId fileId) + /** + * This function returns all available C++ metrics + * (AST node-level) for a particular path. + */ + list getCppAstNodeMetricsForPath( + 1:string path) + + /** + * This function returns all available C++ metrics + * (file-level) for a particular path. + */ + list getCppFileMetricsForPath( + 1:string path) + /** * This function returns the names of AST node metrics. */ diff --git a/plugins/cpp_metrics/service/include/service/cppmetricsservice.h b/plugins/cpp_metrics/service/include/service/cppmetricsservice.h index 8c5bdd7a7..a0a173eb3 100644 --- a/plugins/cpp_metrics/service/include/service/cppmetricsservice.h +++ b/plugins/cpp_metrics/service/include/service/cppmetricsservice.h @@ -48,6 +48,14 @@ class CppMetricsServiceHandler : virtual public CppMetricsServiceIf std::vector& _return, const core::FileId& fileId_) override; + void getCppAstNodeMetricsForPath( + std::vector& _return, + const std::string& path_) override; + + void getCppFileMetricsForPath( + std::vector& _return, + const std::string& path_) override; + void getCppAstNodeMetricsTypeNames( std::vector& _return) override; diff --git a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp index 510794a1e..432264413 100644 --- a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp +++ b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp @@ -8,12 +8,23 @@ namespace service namespace cppmetrics { +typedef odb::query AstQuery; +typedef odb::result AstResult; + CppMetricsServiceHandler::CppMetricsServiceHandler( std::shared_ptr db_, std::shared_ptr datadir_, const cc::webserver::ServerContext& context_) : _db(db_), _transaction(db_), _config(context_.options) { + LOG(info) << "test"; + std::vector metrics; + getCppAstNodeMetricsForPath(metrics, "/home/efekane/repos/tinyxml2/tinyxml2.cpp"); + + for (const auto& metric : metrics) + { + LOG(info) << metric.id << ": " << metric.metrics.size(); + } } void CppMetricsServiceHandler::getCppAstNodeMetricsTypeNames( @@ -112,6 +123,91 @@ void CppMetricsServiceHandler::getCppMetricsForModule( }); } +void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( + std::vector& _return, + const std::string& path) +{ + _transaction([&, this](){ + typedef odb::query CppAstNodeQuery; + typedef odb::query CppAstNodeMetricsQuery; + + // ez így még nagyon todo + // a kapott path legyen prefixe az ast node path-ának + auto nodes = _db->query(); + + if (nodes.empty()) + { + core::InvalidInput ex; + ex.__set_msg("Invalid metric type for path: " + path); + throw ex; + } + else + { + LOG(warning) << nodes.size(); + } + + for (const auto& node : nodes) + { + LOG(info) << node.id << " " << node.path; + auto metricsQuery = _db->query( + CppAstNodeMetricsQuery::astNodeId == node.id); + std::vector metrics; + + CppMetricsAstNode metricsAstNode; + for (auto& metric : metricsQuery) + { + metricsAstNode.type = static_cast(metric.type); + metricsAstNode.value = metric.value; + } + + CppAllMetricsAstNode nodeMetric; + nodeMetric.id = node.id; + nodeMetric.metrics = metrics; + _return.push_back(nodeMetric); + } + }); +} + +void CppMetricsServiceHandler::getCppFileMetricsForPath( + std::vector& _return, + const std::string& path_) +{ + _transaction([&, this](){ + typedef odb::query FileQuery; + typedef odb::query CppFileMetricsQuery; + + // ez így még nagyon todo + // a kapott path legyen prefixe a file path-ának + auto nodes = _db->query(); + + if (nodes.empty()) + { + core::InvalidInput ex; + ex.__set_msg("Invalid metric type for path: " + path_); + throw ex; + } + + for (const auto& node : nodes) + { + auto metricsQuery = _db->query( + CppFileMetricsQuery::id == node.id); + std::vector metrics; + + CppMetricsModule metricsModule; + for (auto& metric : metricsQuery) + { + metricsModule.type = static_cast(metric.type); + metricsModule.value = metric.value; + } + + CppAllMetricsModule nodeMetric; + nodeMetric.id = node.id; + nodeMetric.metrics = metrics; + _return.push_back(nodeMetric); + } + }); +} + } // cppmetrics } // service } // cc From dfa32c2a8f4c470459c7a49caa455d7d227314d7 Mon Sep 17 00:00:00 2001 From: Anett Fekete Date: Mon, 25 Mar 2024 08:52:44 +0100 Subject: [PATCH 03/11] Experimenting with endpoint query. --- .../cpp_metrics/service/src/cppmetricsservice.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp index 432264413..ca5cee4a6 100644 --- a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp +++ b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp @@ -1,6 +1,8 @@ #include #include +#include + namespace cc { namespace service @@ -19,7 +21,7 @@ CppMetricsServiceHandler::CppMetricsServiceHandler( { LOG(info) << "test"; std::vector metrics; - getCppAstNodeMetricsForPath(metrics, "/home/efekane/repos/tinyxml2/tinyxml2.cpp"); + getCppAstNodeMetricsForPath(metrics, "/home/efekane/repos/tinyxml2"); for (const auto& metric : metrics) { @@ -125,20 +127,22 @@ void CppMetricsServiceHandler::getCppMetricsForModule( void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( std::vector& _return, - const std::string& path) + const std::string& path_) { _transaction([&, this](){ typedef odb::query CppAstNodeQuery; typedef odb::query CppAstNodeMetricsQuery; + typedef odb::query CppAstNodeFilePathQuery; // ez így még nagyon todo // a kapott path legyen prefixe az ast node path-ának - auto nodes = _db->query(); + auto nodes = _db->query( + CppAstNodeFilePathQuery::LocFile::path.like(path_ + '%')); if (nodes.empty()) { core::InvalidInput ex; - ex.__set_msg("Invalid metric type for path: " + path); + ex.__set_msg("Invalid metric type for path: " + path_); throw ex; } else From f923e113e3b963519b3116ef0929419046d1b633 Mon Sep 17 00:00:00 2001 From: Anett Fekete Date: Mon, 25 Mar 2024 16:30:22 +0100 Subject: [PATCH 04/11] File-level and AST node-level endpoint queries are corrected. --- .../service/src/cppmetricsservice.cpp | 49 +++++++------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp index ca5cee4a6..929435995 100644 --- a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp +++ b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp @@ -19,14 +19,6 @@ CppMetricsServiceHandler::CppMetricsServiceHandler( const cc::webserver::ServerContext& context_) : _db(db_), _transaction(db_), _config(context_.options) { - LOG(info) << "test"; - std::vector metrics; - getCppAstNodeMetricsForPath(metrics, "/home/efekane/repos/tinyxml2"); - - for (const auto& metric : metrics) - { - LOG(info) << metric.id << ": " << metric.metrics.size(); - } } void CppMetricsServiceHandler::getCppAstNodeMetricsTypeNames( @@ -129,14 +121,14 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( std::vector& _return, const std::string& path_) { - _transaction([&, this](){ - typedef odb::query CppAstNodeQuery; + _transaction([&, this]() + { typedef odb::query CppAstNodeMetricsQuery; + typedef odb::result CppAstNodeMetricsResult; typedef odb::query CppAstNodeFilePathQuery; + typedef odb::result CppAstNodeFilePathResult; - // ez így még nagyon todo - // a kapott path legyen prefixe az ast node path-ának - auto nodes = _db->query( + CppAstNodeFilePathResult nodes = _db->query( CppAstNodeFilePathQuery::LocFile::path.like(path_ + '%')); if (nodes.empty()) @@ -145,27 +137,22 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( ex.__set_msg("Invalid metric type for path: " + path_); throw ex; } - else - { - LOG(warning) << nodes.size(); - } for (const auto& node : nodes) { - LOG(info) << node.id << " " << node.path; auto metricsQuery = _db->query( CppAstNodeMetricsQuery::astNodeId == node.id); std::vector metrics; CppMetricsAstNode metricsAstNode; - for (auto& metric : metricsQuery) + for (const auto& metric : metricsQuery) { metricsAstNode.type = static_cast(metric.type); metricsAstNode.value = metric.value; } CppAllMetricsAstNode nodeMetric; - nodeMetric.id = node.id; + nodeMetric.id = std::to_string(node.id); nodeMetric.metrics = metrics; _return.push_back(nodeMetric); } @@ -176,36 +163,38 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath( std::vector& _return, const std::string& path_) { - _transaction([&, this](){ + _transaction([&, this]() + { typedef odb::query FileQuery; + typedef odb::result FileResult; typedef odb::query CppFileMetricsQuery; + typedef odb::result CppFileMetricsResult; - // ez így még nagyon todo - // a kapott path legyen prefixe a file path-ának - auto nodes = _db->query(); + FileResult descendants = _db->query( + FileQuery::path.like(path_ + '%')); - if (nodes.empty()) + if (descendants.empty()) { core::InvalidInput ex; ex.__set_msg("Invalid metric type for path: " + path_); throw ex; } - for (const auto& node : nodes) + for (const auto& file : descendants) { - auto metricsQuery = _db->query( - CppFileMetricsQuery::id == node.id); + CppFileMetricsResult metricsQuery = _db->query( + CppFileMetricsQuery::file == file.id); std::vector metrics; CppMetricsModule metricsModule; - for (auto& metric : metricsQuery) + for (const auto& metric : metricsQuery) { metricsModule.type = static_cast(metric.type); metricsModule.value = metric.value; } CppAllMetricsModule nodeMetric; - nodeMetric.id = node.id; + nodeMetric.id = std::to_string(file.id); nodeMetric.metrics = metrics; _return.push_back(nodeMetric); } From 0936a195ad87688138a03977d8fcafa5ab62eef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Cser=C3=A9p?= Date: Tue, 26 Mar 2024 08:09:14 +0100 Subject: [PATCH 05/11] Include metrics in the returned result for path based C++ metrics endpoints. --- plugins/cpp_metrics/service/src/cppmetricsservice.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp index 929435995..4aa9b5c4c 100644 --- a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp +++ b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp @@ -149,8 +149,12 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( { metricsAstNode.type = static_cast(metric.type); metricsAstNode.value = metric.value; + metrics.push_back(metricsAstNode); } + if (metrics.empty()) + continue; + CppAllMetricsAstNode nodeMetric; nodeMetric.id = std::to_string(node.id); nodeMetric.metrics = metrics; @@ -191,8 +195,12 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath( { metricsModule.type = static_cast(metric.type); metricsModule.value = metric.value; + metrics.push_back(metricsModule); } + if (metrics.empty()) + continue; + CppAllMetricsModule nodeMetric; nodeMetric.id = std::to_string(file.id); nodeMetric.metrics = metrics; From e09e8ff80ab891cd8da090bdd74b5fe870ab6c1c Mon Sep 17 00:00:00 2001 From: Anett Fekete Date: Sun, 7 Apr 2024 20:40:28 +0200 Subject: [PATCH 06/11] Variable renaming and other small refactorings. --- plugins/cpp_metrics/service/cxxmetrics.thrift | 33 +++++++------------ .../include/service/cppmetricsservice.h | 8 ++--- .../service/src/cppmetricsservice.cpp | 24 +++++++------- 3 files changed, 27 insertions(+), 38 deletions(-) diff --git a/plugins/cpp_metrics/service/cxxmetrics.thrift b/plugins/cpp_metrics/service/cxxmetrics.thrift index ce0758da6..c3789c554 100644 --- a/plugins/cpp_metrics/service/cxxmetrics.thrift +++ b/plugins/cpp_metrics/service/cxxmetrics.thrift @@ -35,39 +35,28 @@ struct CppModuleMetricsTypeName 2:string name } -struct CppMetricsAstNode +struct CppMetricsAstNodeSingle { 1:CppAstNodeMetricsType type, 2:double value } -struct CppAllMetricsAstNode +struct CppMetricsAstNodeAll { 1:common.AstNodeId id, - 2:list metrics + 2:list metrics } -struct CppMetricsModule +struct CppMetricsModuleSingle { 1:CppModuleMetricsType type, 2:double value } -struct CppAllMetricsModule +struct CppMetricsModuleAll { 1:common.FileId id, - 2:list metrics -} - -// Thrift does not provide a union type, -// the ids can remain empty. -struct CppMetricsPath -{ - 1:CppUnitType type - 2:common.AstNodeId astNodeId - 3:list astNodeIdMetrics - 4:common.FileId fileId - 5:list fileMetrics + 2:list metrics } service CppMetricsService @@ -84,28 +73,28 @@ service CppMetricsService * This function returns all available C++ metrics * for a particular AST node. */ - list getCppMetricsForAstNode( + list getCppMetricsForAstNode( 1:common.AstNodeId astNodeId) /** * This function returns all available C++ metrics * for a particular module. */ - list getCppMetricsForModule( + list getCppMetricsForModule( 1:common.FileId fileId) /** * This function returns all available C++ metrics * (AST node-level) for a particular path. */ - list getCppAstNodeMetricsForPath( + list getCppAstNodeMetricsForPath( 1:string path) /** * This function returns all available C++ metrics * (file-level) for a particular path. */ - list getCppFileMetricsForPath( + list getCppFileMetricsForPath( 1:string path) /** @@ -116,5 +105,5 @@ service CppMetricsService /** * This function returns the names of module-level metrics. */ - list getCppModuleMetricsTypeNames() + list getCppModuleMetricsTypeNames() } \ No newline at end of file diff --git a/plugins/cpp_metrics/service/include/service/cppmetricsservice.h b/plugins/cpp_metrics/service/include/service/cppmetricsservice.h index a0a173eb3..24a39f4af 100644 --- a/plugins/cpp_metrics/service/include/service/cppmetricsservice.h +++ b/plugins/cpp_metrics/service/include/service/cppmetricsservice.h @@ -41,19 +41,19 @@ class CppMetricsServiceHandler : virtual public CppMetricsServiceIf CppAstNodeMetricsType::type metric_) override; void getCppMetricsForAstNode( - std::vector& _return, + std::vector& _return, const core::AstNodeId& astNodeId_) override; void getCppMetricsForModule( - std::vector& _return, + std::vector& _return, const core::FileId& fileId_) override; void getCppAstNodeMetricsForPath( - std::vector& _return, + std::vector& _return, const std::string& path_) override; void getCppFileMetricsForPath( - std::vector& _return, + std::vector& _return, const std::string& path_) override; void getCppAstNodeMetricsTypeNames( diff --git a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp index 4aa9b5c4c..21bf7a21c 100644 --- a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp +++ b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp @@ -54,10 +54,10 @@ void CppMetricsServiceHandler::getCppModuleMetricsTypeNames( } void CppMetricsServiceHandler::getCppMetricsForAstNode( - std::vector& _return, + std::vector& _return, const core::AstNodeId& astNodeId_) { - CppMetricsAstNode metric; + CppMetricsAstNodeSingle metric; _transaction([&, this](){ typedef odb::query CppAstNodeMetricsQuery; @@ -97,10 +97,10 @@ double CppMetricsServiceHandler::getSingleCppMetricForAstNode( } void CppMetricsServiceHandler::getCppMetricsForModule( - std::vector& _return, + std::vector& _return, const core::FileId& fileId_) { - CppMetricsModule metric; + CppMetricsModuleSingle metric; _transaction([&, this](){ typedef odb::query CppModuleMetricsQuery; @@ -118,7 +118,7 @@ void CppMetricsServiceHandler::getCppMetricsForModule( } void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( - std::vector& _return, + std::vector& _return, const std::string& path_) { _transaction([&, this]() @@ -142,9 +142,9 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( { auto metricsQuery = _db->query( CppAstNodeMetricsQuery::astNodeId == node.id); - std::vector metrics; + std::vector metrics; - CppMetricsAstNode metricsAstNode; + CppMetricsAstNodeSingle metricsAstNode; for (const auto& metric : metricsQuery) { metricsAstNode.type = static_cast(metric.type); @@ -155,7 +155,7 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( if (metrics.empty()) continue; - CppAllMetricsAstNode nodeMetric; + CppMetricsAstNodeAll nodeMetric; nodeMetric.id = std::to_string(node.id); nodeMetric.metrics = metrics; _return.push_back(nodeMetric); @@ -164,7 +164,7 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( } void CppMetricsServiceHandler::getCppFileMetricsForPath( - std::vector& _return, + std::vector& _return, const std::string& path_) { _transaction([&, this]() @@ -188,9 +188,9 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath( { CppFileMetricsResult metricsQuery = _db->query( CppFileMetricsQuery::file == file.id); - std::vector metrics; + std::vector metrics; - CppMetricsModule metricsModule; + CppMetricsModuleSingle metricsModule; for (const auto& metric : metricsQuery) { metricsModule.type = static_cast(metric.type); @@ -201,7 +201,7 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath( if (metrics.empty()) continue; - CppAllMetricsModule nodeMetric; + CppMetricsModuleAll nodeMetric; nodeMetric.id = std::to_string(file.id); nodeMetric.metrics = metrics; _return.push_back(nodeMetric); From eb36b1b2b60fbf6e7909cbba169bc16ba37719ff Mon Sep 17 00:00:00 2001 From: Anett Fekete Date: Mon, 8 Apr 2024 21:32:02 +0200 Subject: [PATCH 07/11] Query refactoring. --- model/include/model/file.h | 10 +++++ .../service/src/cppmetricsservice.cpp | 44 +++++++++++-------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/model/include/model/file.h b/model/include/model/file.h index f03c88571..1c308bd85 100644 --- a/model/include/model/file.h +++ b/model/include/model/file.h @@ -87,6 +87,16 @@ struct FileIdView { FileId id; }; + +#pragma db view object(File) +struct FilePathView +{ + #pragma db column(File::id) + FileId id; + + #pragma db column(File::path) + std::string path; +}; #pragma db view object(File) query((?) + " GROUP BY " + File::type) struct FileTypeView diff --git a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp index 21bf7a21c..31921625b 100644 --- a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp +++ b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp @@ -2,6 +2,8 @@ #include #include +#include +#include namespace cc { @@ -121,22 +123,24 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( std::vector& _return, const std::string& path_) { - _transaction([&, this]() - { + _transaction([&, this](){ typedef odb::query CppAstNodeMetricsQuery; typedef odb::result CppAstNodeMetricsResult; typedef odb::query CppAstNodeFilePathQuery; typedef odb::result CppAstNodeFilePathResult; + auto nodesRes = _db->query(); + std::set nodesWithMetrics; + for (const auto& node : nodesRes) + nodesWithMetrics.insert(node.astNodeId); + CppAstNodeFilePathResult nodes = _db->query( - CppAstNodeFilePathQuery::LocFile::path.like(path_ + '%')); + CppAstNodeFilePathQuery::LocFile::path.like(path_ + '%') && + CppAstNodeFilePathQuery::CppAstNode::id.in_range( + nodesWithMetrics.begin(), nodesWithMetrics.end())); if (nodes.empty()) - { - core::InvalidInput ex; - ex.__set_msg("Invalid metric type for path: " + path_); - throw ex; - } + return; for (const auto& node : nodes) { @@ -167,22 +171,24 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath( std::vector& _return, const std::string& path_) { - _transaction([&, this]() - { - typedef odb::query FileQuery; - typedef odb::result FileResult; + _transaction([&, this](){ + typedef odb::query FileQuery; + typedef odb::result FileResult; typedef odb::query CppFileMetricsQuery; typedef odb::result CppFileMetricsResult; - FileResult descendants = _db->query( - FileQuery::path.like(path_ + '%')); + auto filesRes = _db->query(); + std::set filesWithMetrics; + for (const auto& file : filesRes) + filesWithMetrics.insert(file.file); + + FileResult descendants = _db->query( + FileQuery::path.like(path_ + '%') && + CppFileMetricsQuery::file.in_range( + filesWithMetrics.begin(), filesWithMetrics.end())); if (descendants.empty()) - { - core::InvalidInput ex; - ex.__set_msg("Invalid metric type for path: " + path_); - throw ex; - } + return; for (const auto& file : descendants) { From 0640e5da93b56226006ae13a61ebb770c22c58fa Mon Sep 17 00:00:00 2001 From: Anett Fekete Date: Tue, 23 Apr 2024 02:26:21 +0200 Subject: [PATCH 08/11] Fixing all AST node (by path) querying endpoint. --- .../model/include/model/cppastnodemetrics.h | 16 +++++++ plugins/cpp_metrics/service/cxxmetrics.thrift | 2 +- .../include/service/cppmetricsservice.h | 3 +- .../service/src/cppmetricsservice.cpp | 46 +++++++------------ 4 files changed, 36 insertions(+), 31 deletions(-) diff --git a/plugins/cpp_metrics/model/include/model/cppastnodemetrics.h b/plugins/cpp_metrics/model/include/model/cppastnodemetrics.h index eb17cdf3d..5d5c35b29 100644 --- a/plugins/cpp_metrics/model/include/model/cppastnodemetrics.h +++ b/plugins/cpp_metrics/model/include/model/cppastnodemetrics.h @@ -44,6 +44,22 @@ struct CppRecordMetricsView double value; }; +#pragma db view \ + object(CppAstNode) \ + object(File = LocFile : CppAstNode::location.file) \ + object(CppAstNodeMetrics : CppAstNode::id == CppAstNodeMetrics::astNodeId) +struct CppAstNodeMetricsForPathView +{ + #pragma db column(CppAstNode::id) + CppAstNodeId astNodeId; + + #pragma db column(CppAstNodeMetrics::type) + CppAstNodeMetrics::Type type; + + #pragma db column(CppAstNodeMetrics::value) + double value; +}; + } //model } //cc diff --git a/plugins/cpp_metrics/service/cxxmetrics.thrift b/plugins/cpp_metrics/service/cxxmetrics.thrift index c3789c554..a1b0af840 100644 --- a/plugins/cpp_metrics/service/cxxmetrics.thrift +++ b/plugins/cpp_metrics/service/cxxmetrics.thrift @@ -87,7 +87,7 @@ service CppMetricsService * This function returns all available C++ metrics * (AST node-level) for a particular path. */ - list getCppAstNodeMetricsForPath( + map> getCppAstNodeMetricsForPath( 1:string path) /** diff --git a/plugins/cpp_metrics/service/include/service/cppmetricsservice.h b/plugins/cpp_metrics/service/include/service/cppmetricsservice.h index 24a39f4af..c010fd4b9 100644 --- a/plugins/cpp_metrics/service/include/service/cppmetricsservice.h +++ b/plugins/cpp_metrics/service/include/service/cppmetricsservice.h @@ -3,6 +3,7 @@ #include #include +#include #include @@ -49,7 +50,7 @@ class CppMetricsServiceHandler : virtual public CppMetricsServiceIf const core::FileId& fileId_) override; void getCppAstNodeMetricsForPath( - std::vector& _return, + std::map>& _return, const std::string& path_) override; void getCppFileMetricsForPath( diff --git a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp index 31921625b..932b4a80e 100644 --- a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp +++ b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp @@ -120,7 +120,7 @@ void CppMetricsServiceHandler::getCppMetricsForModule( } void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( - std::vector& _return, + std::map>& _return, const std::string& path_) { _transaction([&, this](){ @@ -128,41 +128,29 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( typedef odb::result CppAstNodeMetricsResult; typedef odb::query CppAstNodeFilePathQuery; typedef odb::result CppAstNodeFilePathResult; + typedef odb::query CppAstNodeMetricsForPathViewQuery; + typedef odb::result CppAstNodeMetricsForPathViewResult; - auto nodesRes = _db->query(); - std::set nodesWithMetrics; - for (const auto& node : nodesRes) - nodesWithMetrics.insert(node.astNodeId); - - CppAstNodeFilePathResult nodes = _db->query( - CppAstNodeFilePathQuery::LocFile::path.like(path_ + '%') && - CppAstNodeFilePathQuery::CppAstNode::id.in_range( - nodesWithMetrics.begin(), nodesWithMetrics.end())); - - if (nodes.empty()) - return; + auto nodes = _db->query( + CppAstNodeFilePathQuery::LocFile::path.like(path_ + '%')); for (const auto& node : nodes) { - auto metricsQuery = _db->query( - CppAstNodeMetricsQuery::astNodeId == node.id); - std::vector metrics; + CppMetricsAstNodeSingle metric; + metric.type = static_cast(node.type); + metric.value = node.value; - CppMetricsAstNodeSingle metricsAstNode; - for (const auto& metric : metricsQuery) + if (_return.count(std::to_string(node.astNodeId))) { - metricsAstNode.type = static_cast(metric.type); - metricsAstNode.value = metric.value; - metrics.push_back(metricsAstNode); + _return[std::to_string(node.astNodeId)].push_back(metric); + } + else + { + CppMetricsAstNodeAll nodeMetric; + std::vector metricsList; + metricsList.push_back(metric); + _return.insert(std::make_pair(std::to_string(node.astNodeId), metricsList)); } - - if (metrics.empty()) - continue; - - CppMetricsAstNodeAll nodeMetric; - nodeMetric.id = std::to_string(node.id); - nodeMetric.metrics = metrics; - _return.push_back(nodeMetric); } }); } From b61827b485109a48a942c217d4100758dabe28e9 Mon Sep 17 00:00:00 2001 From: Anett Fekete Date: Tue, 23 Apr 2024 23:38:43 +0200 Subject: [PATCH 09/11] Endpoint experimenting. Both are there, still not working. --- .../model/include/model/cppastnodemetrics.h | 8 ++--- .../model/include/model/cppfilemetrics.h | 15 ++++++++ plugins/cpp_metrics/service/cxxmetrics.thrift | 2 +- .../include/service/cppmetricsservice.h | 2 +- .../service/src/cppmetricsservice.cpp | 35 +++++++++++++++---- 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/plugins/cpp_metrics/model/include/model/cppastnodemetrics.h b/plugins/cpp_metrics/model/include/model/cppastnodemetrics.h index 5d5c35b29..070869a09 100644 --- a/plugins/cpp_metrics/model/include/model/cppastnodemetrics.h +++ b/plugins/cpp_metrics/model/include/model/cppastnodemetrics.h @@ -45,12 +45,12 @@ struct CppRecordMetricsView }; #pragma db view \ - object(CppAstNode) \ - object(File = LocFile : CppAstNode::location.file) \ - object(CppAstNodeMetrics : CppAstNode::id == CppAstNodeMetrics::astNodeId) + object(CppAstNodeMetrics) \ + object(CppAstNode : CppAstNodeMetrics::astNodeId == CppAstNode::id) \ + object(File = LocFile : CppAstNode::location.file) struct CppAstNodeMetricsForPathView { - #pragma db column(CppAstNode::id) + #pragma db column(CppAstNodeMetrics::astNodeId) CppAstNodeId astNodeId; #pragma db column(CppAstNodeMetrics::type) diff --git a/plugins/cpp_metrics/model/include/model/cppfilemetrics.h b/plugins/cpp_metrics/model/include/model/cppfilemetrics.h index 357eb5cb5..67264fd83 100644 --- a/plugins/cpp_metrics/model/include/model/cppfilemetrics.h +++ b/plugins/cpp_metrics/model/include/model/cppfilemetrics.h @@ -29,6 +29,21 @@ struct CppFileMetrics unsigned value; }; +#pragma db view \ + object(File) \ + object(CppFileMetrics : File::id == CppFileMetrics::file) +struct CppModuleMetricsForPathView +{ + #pragma db column(File::id) + FileId fileId; + + #pragma db column(CppFileMetrics::type) + CppFileMetrics::Type type; + + #pragma db column(CppFileMetrics::value) + unsigned value; +}; + } //model } //cc diff --git a/plugins/cpp_metrics/service/cxxmetrics.thrift b/plugins/cpp_metrics/service/cxxmetrics.thrift index a1b0af840..fbce47f25 100644 --- a/plugins/cpp_metrics/service/cxxmetrics.thrift +++ b/plugins/cpp_metrics/service/cxxmetrics.thrift @@ -94,7 +94,7 @@ service CppMetricsService * This function returns all available C++ metrics * (file-level) for a particular path. */ - list getCppFileMetricsForPath( + map> getCppFileMetricsForPath( 1:string path) /** diff --git a/plugins/cpp_metrics/service/include/service/cppmetricsservice.h b/plugins/cpp_metrics/service/include/service/cppmetricsservice.h index c010fd4b9..6257e95a1 100644 --- a/plugins/cpp_metrics/service/include/service/cppmetricsservice.h +++ b/plugins/cpp_metrics/service/include/service/cppmetricsservice.h @@ -54,7 +54,7 @@ class CppMetricsServiceHandler : virtual public CppMetricsServiceIf const std::string& path_) override; void getCppFileMetricsForPath( - std::vector& _return, + std::map>& _return, const std::string& path_) override; void getCppAstNodeMetricsTypeNames( diff --git a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp index 932b4a80e..e52dc6275 100644 --- a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp +++ b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp @@ -136,9 +136,12 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( for (const auto& node : nodes) { + LOG(info) << node.astNodeId; CppMetricsAstNodeSingle metric; metric.type = static_cast(node.type); + LOG(info) << node.type; metric.value = node.value; + LOG(info) << metric.value; if (_return.count(std::to_string(node.astNodeId))) { @@ -146,7 +149,6 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( } else { - CppMetricsAstNodeAll nodeMetric; std::vector metricsList; metricsList.push_back(metric); _return.insert(std::make_pair(std::to_string(node.astNodeId), metricsList)); @@ -156,7 +158,7 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( } void CppMetricsServiceHandler::getCppFileMetricsForPath( - std::vector& _return, + std::map>& _return, const std::string& path_) { _transaction([&, this](){ @@ -164,8 +166,13 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath( typedef odb::result FileResult; typedef odb::query CppFileMetricsQuery; typedef odb::result CppFileMetricsResult; + typedef odb::query CppModuleMetricsQuery; + typedef odb::result CppModuleMetricsResult; - auto filesRes = _db->query(); + auto files = _db->query( + CppModuleMetricsQuery::File::path.like(path_ + '%')); + + /*auto filesRes = _db->query(); std::set filesWithMetrics; for (const auto& file : filesRes) filesWithMetrics.insert(file.file); @@ -176,11 +183,25 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath( filesWithMetrics.begin(), filesWithMetrics.end())); if (descendants.empty()) - return; + return;*/ - for (const auto& file : descendants) + for (const auto& file : files) { - CppFileMetricsResult metricsQuery = _db->query( + CppMetricsModuleSingle metric; + metric.type = static_cast(file.type); + metric.value = file.value; + + if (_return.count(std::to_string(file.fileId))) + { + _return[std::to_string(file.fileId)].push_back(metric); + } + else + { + std::vector metricsList; + metricsList.push_back(metric); + _return.insert(std::make_pair(std::to_string(file.fileId), metricsList)); + } + /*CppFileMetricsResult metricsQuery = _db->query( CppFileMetricsQuery::file == file.id); std::vector metrics; @@ -198,7 +219,7 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath( CppMetricsModuleAll nodeMetric; nodeMetric.id = std::to_string(file.id); nodeMetric.metrics = metrics; - _return.push_back(nodeMetric); + _return.push_back(nodeMetric);*/ } }); } From bd6554764cd9baee2c0efcd16f56ac4c1ea52034 Mon Sep 17 00:00:00 2001 From: Anett Fekete Date: Sun, 28 Apr 2024 16:03:19 +0200 Subject: [PATCH 10/11] Endpoints done, paths are displayed along with metrics in response. --- .../model/include/model/cppastnodemetrics.h | 3 ++ .../model/include/model/cppfilemetrics.h | 9 ++-- plugins/cpp_metrics/service/cxxmetrics.thrift | 10 +++-- .../service/src/cppmetricsservice.cpp | 43 +------------------ 4 files changed, 17 insertions(+), 48 deletions(-) diff --git a/plugins/cpp_metrics/model/include/model/cppastnodemetrics.h b/plugins/cpp_metrics/model/include/model/cppastnodemetrics.h index 070869a09..18c1a6017 100644 --- a/plugins/cpp_metrics/model/include/model/cppastnodemetrics.h +++ b/plugins/cpp_metrics/model/include/model/cppastnodemetrics.h @@ -53,6 +53,9 @@ struct CppAstNodeMetricsForPathView #pragma db column(CppAstNodeMetrics::astNodeId) CppAstNodeId astNodeId; + #pragma db column(LocFile::path) + std::string path; + #pragma db column(CppAstNodeMetrics::type) CppAstNodeMetrics::Type type; diff --git a/plugins/cpp_metrics/model/include/model/cppfilemetrics.h b/plugins/cpp_metrics/model/include/model/cppfilemetrics.h index 67264fd83..eebedbc46 100644 --- a/plugins/cpp_metrics/model/include/model/cppfilemetrics.h +++ b/plugins/cpp_metrics/model/include/model/cppfilemetrics.h @@ -30,13 +30,16 @@ struct CppFileMetrics }; #pragma db view \ - object(File) \ - object(CppFileMetrics : File::id == CppFileMetrics::file) + object(CppFileMetrics) \ + object(File : CppFileMetrics::file == File::id) struct CppModuleMetricsForPathView { - #pragma db column(File::id) + #pragma db column(CppFileMetrics::file) FileId fileId; + #pragma db column(File::path) + std::string path; + #pragma db column(CppFileMetrics::type) CppFileMetrics::Type type; diff --git a/plugins/cpp_metrics/service/cxxmetrics.thrift b/plugins/cpp_metrics/service/cxxmetrics.thrift index fbce47f25..4c8538f96 100644 --- a/plugins/cpp_metrics/service/cxxmetrics.thrift +++ b/plugins/cpp_metrics/service/cxxmetrics.thrift @@ -37,8 +37,9 @@ struct CppModuleMetricsTypeName struct CppMetricsAstNodeSingle { - 1:CppAstNodeMetricsType type, - 2:double value + 1:string path, + 2:CppAstNodeMetricsType type, + 3:double value } struct CppMetricsAstNodeAll @@ -49,8 +50,9 @@ struct CppMetricsAstNodeAll struct CppMetricsModuleSingle { - 1:CppModuleMetricsType type, - 2:double value + 1:string path, + 2:CppModuleMetricsType type, + 3:double value } struct CppMetricsModuleAll diff --git a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp index e52dc6275..6089133e4 100644 --- a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp +++ b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp @@ -124,8 +124,6 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( const std::string& path_) { _transaction([&, this](){ - typedef odb::query CppAstNodeMetricsQuery; - typedef odb::result CppAstNodeMetricsResult; typedef odb::query CppAstNodeFilePathQuery; typedef odb::result CppAstNodeFilePathResult; typedef odb::query CppAstNodeMetricsForPathViewQuery; @@ -136,12 +134,10 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( for (const auto& node : nodes) { - LOG(info) << node.astNodeId; CppMetricsAstNodeSingle metric; + metric.path = node.path; metric.type = static_cast(node.type); - LOG(info) << node.type; metric.value = node.value; - LOG(info) << metric.value; if (_return.count(std::to_string(node.astNodeId))) { @@ -162,32 +158,16 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath( const std::string& path_) { _transaction([&, this](){ - typedef odb::query FileQuery; - typedef odb::result FileResult; - typedef odb::query CppFileMetricsQuery; - typedef odb::result CppFileMetricsResult; typedef odb::query CppModuleMetricsQuery; typedef odb::result CppModuleMetricsResult; auto files = _db->query( CppModuleMetricsQuery::File::path.like(path_ + '%')); - /*auto filesRes = _db->query(); - std::set filesWithMetrics; - for (const auto& file : filesRes) - filesWithMetrics.insert(file.file); - - FileResult descendants = _db->query( - FileQuery::path.like(path_ + '%') && - CppFileMetricsQuery::file.in_range( - filesWithMetrics.begin(), filesWithMetrics.end())); - - if (descendants.empty()) - return;*/ - for (const auto& file : files) { CppMetricsModuleSingle metric; + metric.path = file.path; metric.type = static_cast(file.type); metric.value = file.value; @@ -201,25 +181,6 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath( metricsList.push_back(metric); _return.insert(std::make_pair(std::to_string(file.fileId), metricsList)); } - /*CppFileMetricsResult metricsQuery = _db->query( - CppFileMetricsQuery::file == file.id); - std::vector metrics; - - CppMetricsModuleSingle metricsModule; - for (const auto& metric : metricsQuery) - { - metricsModule.type = static_cast(metric.type); - metricsModule.value = metric.value; - metrics.push_back(metricsModule); - } - - if (metrics.empty()) - continue; - - CppMetricsModuleAll nodeMetric; - nodeMetric.id = std::to_string(file.id); - nodeMetric.metrics = metrics; - _return.push_back(nodeMetric);*/ } }); } From d74281d1cfabc75054d919252bb84431a2dbd8c3 Mon Sep 17 00:00:00 2001 From: Anett Fekete Date: Sun, 28 Apr 2024 16:30:00 +0200 Subject: [PATCH 11/11] Yes, should be removed. --- plugins/cpp_metrics/service/cxxmetrics.thrift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/plugins/cpp_metrics/service/cxxmetrics.thrift b/plugins/cpp_metrics/service/cxxmetrics.thrift index 4c8538f96..c3c7ab54b 100644 --- a/plugins/cpp_metrics/service/cxxmetrics.thrift +++ b/plugins/cpp_metrics/service/cxxmetrics.thrift @@ -4,12 +4,6 @@ include "project/project.thrift" namespace cpp cc.service.cppmetrics namespace java cc.service.cppmetrics -enum CppUnitType -{ - AstNodeUnit = 1, - FileUnit = 2 -} - enum CppAstNodeMetricsType { ParameterCount = 1,