Skip to content

Commit

Permalink
Revert "Made the metric calculation parallel"
Browse files Browse the repository at this point in the history
This reverts commit bc01a10.
  • Loading branch information
kmkristof committed Jul 7, 2024
1 parent bc01a10 commit 73f8e72
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ 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: 31 additions & 40 deletions plugins/cpp_metrics/parser/src/cppmetricsparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,55 +103,46 @@ bool CppMetricsParser::cleanupDatabase()

void CppMetricsParser::afferentCouplingTypeLevel()
{

// Calculate the cohesion metric for all types on parallel threads.
parallelCalcMetric<model::AfferentRecordView>(
"Afferent coupling",
_threadCount * lackOfCohesionPartitionMultiplier, // number of jobs; adjust for granularity
getFilterPathsQuery<model::AfferentRecordView>(),
[&, this](const MetricsTasks<model::AfferentRecordView>& tasks)
util::OdbTransaction{_ctx.db}([&,this]
{
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;
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>())
for (const model::AfferentRecordView& type
: _ctx.db->query<model::AfferentRecordView>())
{
if (!cc::util::isRootedUnderAnyOf(_inputPaths, type.filePath))
{
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;
continue;
}

for (const auto& t : typesFound)
{
typeFoundCnt[t]++;
}
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);
}

for (const auto& pair : typeFoundCnt)
astNodeIdOfType[type.typeHash] = type.astNodeId;

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

}

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 73f8e72

Please sign in to comment.