Skip to content

Commit

Permalink
Endpoints for module-level C++ metric types (#739)
Browse files Browse the repository at this point in the history
Co-authored-by: Anett Fekete <anett.fekete@ericsson.com>
  • Loading branch information
mcserep and intjftw authored Apr 29, 2024
1 parent 5bfc159 commit e681750
Show file tree
Hide file tree
Showing 7 changed files with 267 additions and 25 deletions.
10 changes: 10 additions & 0 deletions model/include/model/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions plugins/cpp/model/include/model/cppastnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
19 changes: 19 additions & 0 deletions plugins/cpp_metrics/model/include/model/cppastnodemetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ struct CppRecordMetricsView
double value;
};

#pragma db view \
object(CppAstNodeMetrics) \
object(CppAstNode : CppAstNodeMetrics::astNodeId == CppAstNode::id) \
object(File = LocFile : CppAstNode::location.file)
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;

#pragma db column(CppAstNodeMetrics::value)
double value;
};

} //model
} //cc

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

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

#pragma db column(File::path)
std::string path;

#pragma db column(CppFileMetrics::type)
CppFileMetrics::Type type;

#pragma db column(CppFileMetrics::value)
unsigned value;
};

} //model
} //cc

Expand Down
81 changes: 71 additions & 10 deletions plugins/cpp_metrics/service/cxxmetrics.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,55 @@ include "project/project.thrift"
namespace cpp cc.service.cppmetrics
namespace java cc.service.cppmetrics

enum CppMetricsType
enum CppAstNodeMetricsType
{
ParameterCount = 1,
McCabe = 2,
LackOfCohesion = 3,
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
struct CppMetricsAstNodeSingle
{
1:string path,
2:CppAstNodeMetricsType type,
3:double value
}

struct CppMetricsAstNodeAll
{
1:common.AstNodeId id,
2:list<CppMetricsAstNodeSingle> metrics
}

struct CppMetricsModuleSingle
{
1:string path,
2:CppModuleMetricsType type,
3:double value
}

struct CppMetricsModuleAll
{
1:CppMetricsType type,
2:double value
1:common.FileId id,
2:list<CppMetricsModuleSingle> metrics
}

service CppMetricsService
Expand All @@ -32,17 +63,47 @@ service CppMetricsService
*/
double getSingleCppMetricForAstNode(
1:common.AstNodeId astNodeId,
2:CppMetricsType metric)
2:CppAstNodeMetricsType metric)

/**
* This function returns all available C++ metrics
* for a particular AST node.
*/
list<CppMetricsAstNode> getCppMetricsForAstNode(
list<CppMetricsAstNodeSingle> getCppMetricsForAstNode(
1:common.AstNodeId astNodeId)

/**
* This function returns the names of metrics.
* This function returns all available C++ metrics
* for a particular module (file or directory).
*/
list<CppMetricsModuleSingle> getCppMetricsForModule(
1:common.FileId fileId)

/**
* This function 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>> getCppAstNodeMetricsForPath(
1:string path)

/**
* This function 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>> getCppFileMetricsForPath(
1:string path)

/**
* This function returns the names of the AST node-level C++ metrics.
*/
list<CppAstNodeMetricsTypeName> getCppAstNodeMetricsTypeNames()

/**
* This function returns the names of module-level C++ metrics.
*/
list<CppMetricsTypeName> getCppMetricsTypeNames()
list<CppModuleMetricsTypeName> getCppModuleMetricsTypeNames()
}
26 changes: 22 additions & 4 deletions plugins/cpp_metrics/service/include/service/cppmetricsservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <memory>
#include <vector>
#include <map>

#include <boost/program_options/variables_map.hpp>

Expand All @@ -12,6 +13,8 @@
#include <model/cppastnodemetrics-odb.hxx>
#include <model/cppastnode.h>
#include <model/cppastnode-odb.hxx>
#include <model/cppfilemetrics.h>
#include <model/cppfilemetrics-odb.hxx>

#include <odb/database.hxx>
#include <util/odbtransaction.h>
Expand All @@ -36,14 +39,29 @@ class CppMetricsServiceHandler : virtual public CppMetricsServiceIf

double getSingleCppMetricForAstNode(
const core::AstNodeId& astNodeId_,
CppMetricsType::type metric_) override;
CppAstNodeMetricsType::type metric_) override;

void getCppMetricsForAstNode(
std::vector<CppMetricsAstNode>& _return,
std::vector<CppMetricsAstNodeSingle>& _return,
const core::AstNodeId& astNodeId_) override;

void getCppMetricsTypeNames(
std::vector<CppMetricsTypeName>& _return) override;
void getCppMetricsForModule(
std::vector<CppMetricsModuleSingle>& _return,
const core::FileId& fileId_) override;

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

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

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

void getCppModuleMetricsTypeNames(
std::vector<CppModuleMetricsTypeName>& _return) override;

private:
std::shared_ptr<odb::database> _db;
Expand Down
Loading

0 comments on commit e681750

Please sign in to comment.