Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ set(ODBFLAGS
--default-pointer "std::shared_ptr")

# Set CXX standard
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down
11 changes: 11 additions & 0 deletions plugins/cpp_metrics/model/include/model/cppastnodemetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ struct CppAstNodeMetricsAndDataForPathView
double value;
};

#pragma db view \
object(CppAstNodeMetrics) \
object(CppAstNode : CppAstNodeMetrics::astNodeId == CppAstNode::id) \
object(File : CppAstNode::location.file) \
query(distinct)
struct CppAstNodeMetricsDistinctView
{
#pragma db column(CppAstNodeMetrics::astNodeId)
CppAstNodeId astNodeId;
};

} //model
} //cc

Expand Down
10 changes: 10 additions & 0 deletions plugins/cpp_metrics/model/include/model/cppfilemetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ struct CppModuleMetricsForPathView
unsigned value;
};

#pragma db view \
object(CppFileMetrics) \
object(File : CppFileMetrics::file == File::id) \
query(distinct)
struct CppModuleMetricsDistinctView
{
#pragma db column(CppFileMetrics::file)
FileId fileId;
};

} //model
} //cc

Expand Down
3 changes: 2 additions & 1 deletion plugins/cpp_metrics/service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ add_custom_command(
${CMAKE_CURRENT_BINARY_DIR}/gen-cpp/CppMetricsService.cpp
${CMAKE_CURRENT_BINARY_DIR}/gen-cpp/CppMetricsService.h
${CMAKE_CURRENT_BINARY_DIR}/gen-cpp
${CMAKE_CURRENT_BINARY_DIR}/gen-js
COMMAND
${THRIFT_EXECUTABLE} --gen cpp
${THRIFT_EXECUTABLE} --gen cpp --gen js
-o ${CMAKE_CURRENT_BINARY_DIR}
-I ${PROJECT_SOURCE_DIR}/service
${CMAKE_CURRENT_SOURCE_DIR}/cxxmetrics.thrift
Expand Down
33 changes: 33 additions & 0 deletions plugins/cpp_metrics/service/cxxmetrics.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ service CppMetricsService
map<common.AstNodeId, list<CppMetricsAstNodeSingle>> getCppAstNodeMetricsForPath(
1:string path)

/**
* This is a paged function which returns all available C++ metrics
* (AST node-level) for a particular path.
*
* The given path is a handled as a prefix.
*/
map<common.AstNodeId, list<CppMetricsAstNodeSingle>> getPagedCppAstNodeMetricsForPath(
1:string path
2:i32 pageSize,
3:i32 pageNumber)

/**
* This function returns all available C++ metrics
* (AST node-level) and miscellaneous data for a particular path.
Expand All @@ -107,6 +118,17 @@ service CppMetricsService
map<common.AstNodeId, CppMetricsAstNodeDetailed> getCppAstNodeMetricsDetailedForPath(
1:string path)

/**
* This is a paged function which returns all available C++ metrics
* (AST node-level) and miscellaneous data for a particular path.
*
* The given path is a handled as a prefix.
*/
map<common.AstNodeId, CppMetricsAstNodeDetailed> getPagedCppAstNodeMetricsDetailedForPath(
1:string path,
2:i32 pageSize,
3:i32 pageNumber)

/**
* This function returns all available C++ metrics
* (file-level) for a particular path.
Expand All @@ -116,6 +138,17 @@ service CppMetricsService
map<common.FileId, list<CppMetricsModuleSingle>> getCppFileMetricsForPath(
1:string path)

/**
* This is a paged function which returns all available C++ metrics
* (file-level) for a particular path.
*
* The given path is a handled as a prefix.
*/
map<common.FileId, list<CppMetricsModuleSingle>> getPagedCppFileMetricsForPath(
1:string path,
2:i32 pageSize,
3:i32 pageNumber)

/**
* This function returns the names of the AST node-level C++ metrics.
*/
Expand Down
58 changes: 58 additions & 0 deletions plugins/cpp_metrics/service/include/service/cppmetricsservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,32 @@ class CppMetricsServiceHandler : virtual public CppMetricsServiceIf
std::map<core::AstNodeId, std::vector<CppMetricsAstNodeSingle>>& _return,
const std::string& path_) override;

void getPagedCppAstNodeMetricsForPath(
std::map<core::AstNodeId, std::vector<CppMetricsAstNodeSingle>>& _return,
const std::string& path_,
const std::int32_t pageSize_,
const std::int32_t pageNumber_) override;

void getCppAstNodeMetricsDetailedForPath(
std::map<core::AstNodeId, CppMetricsAstNodeDetailed>& _return,
const std::string& path_) override;

void getPagedCppAstNodeMetricsDetailedForPath(
std::map<core::AstNodeId, CppMetricsAstNodeDetailed>& _return,
const std::string& path_,
const std::int32_t pageSize_,
const std::int32_t pageNumber_) override;

void getCppFileMetricsForPath(
std::map<core::FileId, std::vector<CppMetricsModuleSingle>>& _return,
const std::string& path_) override;

void getPagedCppFileMetricsForPath(
std::map<core::FileId, std::vector<CppMetricsModuleSingle>>& _return,
const std::string& path_,
const std::int32_t pageSize_,
const std::int32_t pageNumber_) override;

void getCppAstNodeMetricsTypeNames(
std::vector<CppAstNodeMetricsTypeName>& _return) override;

Expand All @@ -72,6 +90,46 @@ class CppMetricsServiceHandler : virtual public CppMetricsServiceIf
util::OdbTransaction _transaction;

const boost::program_options::variables_map& _config;

std::string getPagingQuery(
const std::int32_t pageSize_,
const std::int32_t pageNumber_);

template <typename TID, typename TView>
std::vector<TID> pageMetrics(
const std::string& path_,
const std::int32_t pageSize_,
const std::int32_t pageNumber_)
{
return _transaction([&, this](){
odb::result<TView> paged_nodes = _db->query<TView>(
odb::query<TView>::File::path.like(path_ + '%') + getPagingQuery(pageSize_, pageNumber_));

std::vector<TID> paged_ids(paged_nodes.size());
std::transform(paged_nodes.begin(), paged_nodes.end(), paged_ids.begin(),
[](const TView& e){
if constexpr (std::is_same<TView, model::CppAstNodeMetricsDistinctView>::value) {
return e.astNodeId;
} else if constexpr (std::is_same<TView, model::CppModuleMetricsDistinctView>::value) {
return e.fileId;
}
});

return paged_ids;
});
}

void queryCppAstNodeMetricsForPath(
std::map<core::AstNodeId, std::vector<CppMetricsAstNodeSingle>>& _return,
const odb::query<model::CppAstNodeMetricsForPathView>& query_);

void queryCppAstNodeMetricsDetailedForPath(
std::map<core::AstNodeId, CppMetricsAstNodeDetailed>& _return,
const odb::query<model::CppAstNodeMetricsAndDataForPathView>& query_);

void queryCppFileMetricsForPath(
std::map<core::FileId, std::vector<CppMetricsModuleSingle>>& _return,
const odb::query<model::CppModuleMetricsForPathView>& query_);
};

} // cppmetrics
Expand Down
123 changes: 96 additions & 27 deletions plugins/cpp_metrics/service/src/cppmetricsservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ namespace service
namespace cppmetrics
{

typedef odb::query<cc::model::CppAstNode> AstQuery;
typedef odb::result<cc::model::CppAstNode> AstResult;
typedef odb::query<model::CppAstNodeMetricsForPathView> CppNodeMetricsQuery;
typedef odb::result<model::CppAstNodeMetricsForPathView> CppNodeMetricsResult;
typedef odb::query<model::CppModuleMetricsForPathView> CppModuleMetricsQuery;
typedef odb::result<model::CppModuleMetricsForPathView> CppModuleMetricsResult;

CppMetricsServiceHandler::CppMetricsServiceHandler(
std::shared_ptr<odb::database> db_,
Expand Down Expand Up @@ -137,18 +139,12 @@ void CppMetricsServiceHandler::getCppMetricsForModule(
});
}

void CppMetricsServiceHandler::getCppAstNodeMetricsForPath(
void CppMetricsServiceHandler::queryCppAstNodeMetricsForPath(
std::map<core::AstNodeId, std::vector<CppMetricsAstNodeSingle>>& _return,
const std::string& path_)
const odb::query<model::CppAstNodeMetricsForPathView>& query_)
{
_transaction([&, this](){
typedef odb::query<model::CppAstNodeFilePath> CppAstNodeFilePathQuery;
typedef odb::result<model::CppAstNodeFilePath> CppAstNodeFilePathResult;
typedef odb::query<model::CppAstNodeMetricsForPathView> CppAstNodeMetricsForPathViewQuery;
typedef odb::result<model::CppAstNodeMetricsForPathView> CppAstNodeMetricsForPathViewResult;

auto nodes = _db->query<model::CppAstNodeMetricsForPathView>(
CppAstNodeFilePathQuery::LocFile::path.like(path_ + '%'));
auto nodes = _db->query<model::CppAstNodeMetricsForPathView>(query_);

for (const auto& node : nodes)
{
Expand All @@ -171,18 +167,33 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath(
});
}

void CppMetricsServiceHandler::getCppAstNodeMetricsDetailedForPath(
std::map<core::AstNodeId, CppMetricsAstNodeDetailed>& _return,
void CppMetricsServiceHandler::getCppAstNodeMetricsForPath(
std::map<core::AstNodeId, std::vector<CppMetricsAstNodeSingle>>& _return,
const std::string& path_)
{
_transaction([&, this](){
typedef odb::query<model::CppAstNodeFilePath> CppAstNodeFilePathQuery;
typedef odb::result<model::CppAstNodeFilePath> CppAstNodeFilePathResult;
typedef odb::query<model::CppAstNodeMetricsAndDataForPathView> CppAstNodeMetricsAndDataForPathViewQuery;
typedef odb::result<model::CppAstNodeMetricsAndDataForPathView> CppAstNodeMetricsAndDataForPathViewResult;
queryCppAstNodeMetricsForPath(_return,
CppNodeMetricsQuery::LocFile::path.like(path_ + '%'));
}

void CppMetricsServiceHandler::getPagedCppAstNodeMetricsForPath(
std::map<core::AstNodeId, std::vector<CppMetricsAstNodeSingle>>& _return,
const std::string& path_,
const std::int32_t pageSize_,
const std::int32_t pageNumber_)
{
std::vector<model::CppAstNodeId> paged_nodes = pageMetrics<model::CppAstNodeId, model::CppAstNodeMetricsDistinctView>(
path_, pageSize_, pageNumber_);

queryCppAstNodeMetricsForPath(_return,
CppNodeMetricsQuery::CppAstNodeMetrics::astNodeId.in_range(paged_nodes.begin(), paged_nodes.end()));
}

auto nodes = _db->query<model::CppAstNodeMetricsAndDataForPathView>(
CppAstNodeFilePathQuery::LocFile::path.like(path_ + '%'));
void CppMetricsServiceHandler::queryCppAstNodeMetricsDetailedForPath(
std::map<core::AstNodeId, CppMetricsAstNodeDetailed>& _return,
const odb::query<model::CppAstNodeMetricsAndDataForPathView>& query_)
{
_transaction([&, this](){
auto nodes = _db->query<model::CppAstNodeMetricsAndDataForPathView>(query_);

for (const auto& node : nodes)
{
Expand Down Expand Up @@ -210,16 +221,33 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsDetailedForPath(
});
}

void CppMetricsServiceHandler::getCppFileMetricsForPath(
std::map<core::FileId, std::vector<CppMetricsModuleSingle>>& _return,
void CppMetricsServiceHandler::getCppAstNodeMetricsDetailedForPath(
std::map<core::AstNodeId, CppMetricsAstNodeDetailed>& _return,
const std::string& path_)
{
_transaction([&, this](){
typedef odb::query<model::CppModuleMetricsForPathView> CppModuleMetricsQuery;
typedef odb::result<model::CppModuleMetricsForPathView> CppModuleMetricsResult;
queryCppAstNodeMetricsDetailedForPath(_return,
CppNodeMetricsQuery::LocFile::path.like(path_ + '%'));
}

void CppMetricsServiceHandler::getPagedCppAstNodeMetricsDetailedForPath(
std::map<core::AstNodeId, CppMetricsAstNodeDetailed>& _return,
const std::string& path_,
const std::int32_t pageSize_,
const std::int32_t pageNumber_)
{
std::vector<model::CppAstNodeId> paged_nodes = pageMetrics<model::CppAstNodeId, model::CppAstNodeMetricsDistinctView>(
path_, pageSize_, pageNumber_);

auto files = _db->query<model::CppModuleMetricsForPathView>(
CppModuleMetricsQuery::File::path.like(path_ + '%'));
queryCppAstNodeMetricsDetailedForPath(_return,
CppNodeMetricsQuery::CppAstNodeMetrics::astNodeId.in_range(paged_nodes.begin(), paged_nodes.end()));
}

void CppMetricsServiceHandler::queryCppFileMetricsForPath(
std::map<core::FileId, std::vector<CppMetricsModuleSingle>>& _return,
const odb::query<model::CppModuleMetricsForPathView>& query_)
{
_transaction([&, this](){
auto files = _db->query<model::CppModuleMetricsForPathView>(query_);

for (const auto& file : files)
{
Expand All @@ -242,6 +270,47 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath(
});
}

void CppMetricsServiceHandler::getCppFileMetricsForPath(
std::map<core::FileId, std::vector<CppMetricsModuleSingle>>& _return,
const std::string& path_)
{
queryCppFileMetricsForPath(_return,
CppModuleMetricsQuery::File::path.like(path_ + '%'));
}

void CppMetricsServiceHandler::getPagedCppFileMetricsForPath(
std::map<core::FileId, std::vector<CppMetricsModuleSingle>>& _return,
const std::string& path_,
const std::int32_t pageSize_,
const std::int32_t pageNumber_)
{
std::vector<model::FileId> paged_files = pageMetrics<model::FileId, model::CppModuleMetricsDistinctView>(path_, pageSize_, pageNumber_);
queryCppFileMetricsForPath(_return,
CppModuleMetricsQuery::CppFileMetrics::file.in_range(paged_files.begin(), paged_files.end()));
}

std::string CppMetricsServiceHandler::getPagingQuery(
const std::int32_t pageSize_,
const std::int32_t pageNumber_)
{
if (pageSize_ <= 0)
{
core::InvalidInput ex;
ex.__set_msg("Invalid page size: " + std::to_string(pageSize_));
throw ex;
}

if (pageNumber_ <= 0)
{
core::InvalidInput ex;
ex.__set_msg("Invalid page number: " + std::to_string(pageNumber_));
throw ex;
}

const std::int32_t offset = (pageNumber_ - 1) * pageSize_;
return " LIMIT " + std::to_string(pageSize_) + " OFFSET " + std::to_string(offset);
}

} // cppmetrics
} // service
} // cc
Loading