Skip to content

Commit

Permalink
Added multithreaded calculation to efferent coupling.
Browse files Browse the repository at this point in the history
  • Loading branch information
intjftw committed Jul 14, 2024
1 parent d559bf7 commit a8f8897
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class CppMetricsParser : public AbstractParser
static const int functionMcCabePartitionMultiplier = 5;
static const int functionBumpyRoadPartitionMultiplier = 5;
static const int lackOfCohesionPartitionMultiplier = 25;
static const int efferentCouplingTypesPartitionMultiplier = 5;
};

} // parser
Expand Down
120 changes: 63 additions & 57 deletions plugins/cpp_metrics/parser/src/cppmetricsparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,71 +368,77 @@ void CppMetricsParser::lackOfCohesion()

void CppMetricsParser::efferentTypeLevel()
{
typedef odb::query<cc::model::CppMemberType> MemTypeQuery;
typedef odb::query<cc::model::CppInheritanceCount> InheritanceQuery;
typedef odb::query<cc::model::CppFunctionParamTypeView> ParamQuery;
typedef odb::query<cc::model::CppFunctionLocalTypeView> LocalQuery;
typedef odb::query<cc::model::CppFunction> FuncQuery;

util::OdbTransaction{_ctx.db}([&, this]
{
/*parallelCalcMetric<model::CppFunctionParamCountWithId>(
"Efferent coupling of types",
_threadCount * functionParamsPartitionMultiplier,// number of jobs; adjust for granularity
getFilterPathsQuery<model::CppFunctionParamCountWithId>(),
[&, this](const MetricsTasks<model::CppFunctionParamCountWithId>& tasks)
{*/
std::set<std::uint64_t> dependentTypes;
for (const model::CohesionCppRecordView& type
: _ctx.db->query<model::CohesionCppRecordView>())
parallelCalcMetric<model::CohesionCppRecordView>(
"Efferent coupling of types",
_threadCount * efferentCouplingTypesPartitionMultiplier,// number of jobs; adjust for granularity
getFilterPathsQuery<model::CohesionCppRecordView>(),
[&, this](const MetricsTasks<model::CohesionCppRecordView>& tasks)
{
// Skip types that were included from external libraries.
/*type.location.file.load();
const auto typeFile = _ctx.db->query_one<model::File>(
odb::query<model::File>::id == type.location.file->id);
if (!typeFile || !cc::util::isRootedUnderAnyOf(_inputPaths, typeFile->path))
continue;*/
//if (!cc::util::isRootedUnderAnyOf(_inputPaths, type.filePath))
//continue;
typedef odb::query<cc::model::CppMemberType> MemTypeQuery;
typedef odb::query<cc::model::CppInheritanceCount> InheritanceQuery;
typedef odb::query<cc::model::CppFunctionParamTypeView> ParamQuery;
typedef odb::query<cc::model::CppFunctionLocalTypeView> LocalQuery;
typedef odb::query<cc::model::CppFunction> FuncQuery;

dependentTypes.clear();

// Count parent types
auto inheritanceView = _ctx.db->query<model::CppInheritanceCount>(
InheritanceQuery::derived == type.entityHash);

// Count unique type attributes
for (const model::CppMemberType& mem : _ctx.db->query<model::CppMemberType>(
MemTypeQuery::typeHash == type.entityHash))
util::OdbTransaction{_ctx.db}([&, this]
{
auto funcAstNodeId = mem.memberAstNode.load()->id;

if (mem.kind == cc::model::CppMemberType::Field)
std::set<std::uint64_t> dependentTypes;
for (const model::CohesionCppRecordView& type
: _ctx.db->query<model::CohesionCppRecordView>())
{
dependentTypes.insert(mem.memberTypeHash);
}
else
{
for (const auto& param : _ctx.db->query<model::CppFunctionParamTypeView>(
FuncQuery::astNodeId == funcAstNodeId))
// Skip types that were included from external libraries.

//const auto typeFile = _ctx.db->query_one<model::File>(
//odb::query<model::File>::id == type.location.file->id);
//if (!cc::util::isRootedUnderAnyOf(_inputPaths, type.file.path))
//continue;
/*type.location.file.load();
const auto typeFile = _ctx.db->query_one<model::File>(
odb::query<model::File>::id == type.location.file->id);
if (!typeFile || !cc::util::isRootedUnderAnyOf(_inputPaths, typeFile->path))
continue;*/
//if (!cc::util::isRootedUnderAnyOf(_inputPaths, type.filePath))
//continue;

dependentTypes.clear();

// Count parent types
auto inheritanceView = _ctx.db->query<model::CppInheritanceCount>(
InheritanceQuery::derived == type.entityHash);

// Count unique type attributes
for (const model::CppMemberType& mem: _ctx.db->query<model::CppMemberType>(
MemTypeQuery::typeHash == type.entityHash))
{
dependentTypes.insert(param.paramTypeHash);
}
auto funcAstNodeId = mem.memberAstNode.load()->id;

for (const auto& local : _ctx.db->query<model::CppFunctionLocalTypeView>(
FuncQuery::astNodeId == funcAstNodeId))
{
dependentTypes.insert(local.paramTypeHash);
if (mem.kind == cc::model::CppMemberType::Field)
{
dependentTypes.insert(mem.memberTypeHash);
}
else
{
for (const auto& param: _ctx.db->query<model::CppFunctionParamTypeView>(
FuncQuery::astNodeId == funcAstNodeId))
{
dependentTypes.insert(param.paramTypeHash);
}

for (const auto& local: _ctx.db->query<model::CppFunctionLocalTypeView>(
FuncQuery::astNodeId == funcAstNodeId))
{
dependentTypes.insert(local.paramTypeHash);
}
}
}
}
}

model::CppAstNodeMetrics metric;
metric.astNodeId = type.astNodeId;
metric.type = model::CppAstNodeMetrics::Type::EFFERENT_TYPE;
metric.value = inheritanceView.begin()->count + dependentTypes.size();
_ctx.db->persist(metric);
}
model::CppAstNodeMetrics metric;
metric.astNodeId = type.astNodeId;
metric.type = model::CppAstNodeMetrics::Type::EFFERENT_TYPE;
metric.value = inheritanceView.begin()->count + dependentTypes.size();
_ctx.db->persist(metric);
}
});
});
}

Expand Down

0 comments on commit a8f8897

Please sign in to comment.