Skip to content

Commit

Permalink
Made the metric calculation parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
kmkristof committed Jul 7, 2024
1 parent 73f8e72 commit d3bec52
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class CppMetricsParser : public AbstractParser
static const int functionMcCabePartitionMultiplier = 5;
static const int functionBumpyRoadPartitionMultiplier = 5;
static const int lackOfCohesionPartitionMultiplier = 25;
static const int afferentCouplingPartitionMultiplier = 25;
};

} // parser
Expand Down
71 changes: 40 additions & 31 deletions plugins/cpp_metrics/parser/src/cppmetricsparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,46 +103,55 @@ bool CppMetricsParser::cleanupDatabase()

void CppMetricsParser::afferentCouplingTypeLevel()
{
util::OdbTransaction{_ctx.db}([&,this]
{
std::set<std::uint64_t> typesFound;
std::unordered_map<std::uint64_t, int> typeFoundCnt;
std::unordered_map<std::uint64_t,std::uint64_t> astNodeIdOfType;

for (const model::AfferentRecordView& type
: _ctx.db->query<model::AfferentRecordView>())
// Calculate the cohesion metric for all types on parallel threads.
parallelCalcMetric<model::AfferentRecordView>(
"Afferent coupling",
_threadCount * afferentCouplingPartitionMultiplier, // number of jobs; adjust for granularity
getFilterPathsQuery<model::AfferentRecordView>(),
[&, this](const MetricsTasks<model::AfferentRecordView>& tasks)
{
util::OdbTransaction{_ctx.db}([&,this]
{
if (!cc::util::isRootedUnderAnyOf(_inputPaths, type.filePath))
{
continue;
}
std::set<std::uint64_t> typesFound;
std::unordered_map<std::uint64_t, int> typeFoundCnt;
std::unordered_map<std::uint64_t,std::uint64_t> astNodeIdOfType;

typesFound.clear();
for (const model::CppMemberType& member : _ctx.db->query<model::CppMemberType>(
odb::query<cc::model::CppMemberType>::typeHash == type.entityHash &&
odb::query<cc::model::CppMemberType>::kind == model::CppMemberType::Kind::Field))
for (const model::AfferentRecordView& type
: _ctx.db->query<model::AfferentRecordView>())
{
typesFound.insert(member.memberTypeHash);
if (!cc::util::isRootedUnderAnyOf(_inputPaths, type.filePath))
{
continue;
}

typesFound.clear();
for (const model::CppMemberType& member : _ctx.db->query<model::CppMemberType>(
odb::query<cc::model::CppMemberType>::typeHash == type.entityHash &&
odb::query<cc::model::CppMemberType>::kind == model::CppMemberType::Kind::Field))
{
typesFound.insert(member.memberTypeHash);
}

astNodeIdOfType[type.typeHash] = type.astNodeId;

for (const auto& t : typesFound)
{
typeFoundCnt[t]++;
}
}

astNodeIdOfType[type.typeHash] = type.astNodeId;

for (const auto& t : typesFound)
for (const auto& pair : typeFoundCnt)
{
typeFoundCnt[t]++;
model::CppAstNodeMetrics metric;
metric.astNodeId = astNodeIdOfType[pair.first];
metric.type = model::CppAstNodeMetrics::Type::AFFERENT_COUPLING;
metric.value = pair.second;
_ctx.db->persist(metric);
}
}

for (const auto& pair : typeFoundCnt)
{
model::CppAstNodeMetrics metric;
metric.astNodeId = astNodeIdOfType[pair.first];
metric.type = model::CppAstNodeMetrics::Type::AFFERENT_COUPLING;
metric.value = pair.second;
_ctx.db->persist(metric);
}



});
});
}

Expand Down

0 comments on commit d3bec52

Please sign in to comment.