Skip to content

Commit

Permalink
cov: store leaf/parent region distinction in DB
Browse files Browse the repository at this point in the history
  • Loading branch information
haxscramper committed Apr 22, 2024
1 parent e49d4c5 commit 46955d3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scripts/cxx_codegen/profdata_merger/profdata_merger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ struct queries {
"Context", // 10
"SegmentIndex", // 11
"NestedIn", // 12
"IsLeaf", // 13
}))
,
// ---
Expand Down Expand Up @@ -1088,6 +1089,7 @@ void add_file(CoverageData const& file, queries& q, db_build_ctx& ctx) {
CoverageSegment segment;
int self_id;
std::optional<int> parent;
bool is_leaf;
};

std::vector<std::pair<NestingData, CoverageSegment>> segment_pairs;
Expand All @@ -1098,10 +1100,14 @@ void add_file(CoverageData const& file, queries& q, db_build_ctx& ctx) {
std::string prefix = std::string(segment_stack.size() * 2, ' ');
if (s.IsRegionEntry) {
++ctx.segment_counter;
if (!segment_stack.empty()) {
segment_stack.top().is_leaf = false;
}
segment_stack.push({
.segment = s,
.self_id = ctx.segment_counter,
.parent = std::nullopt,
.is_leaf = true,
});
} else {
if (!segment_stack.empty()) {
Expand Down Expand Up @@ -1155,6 +1161,7 @@ void add_file(CoverageData const& file, queries& q, db_build_ctx& ctx) {
} else {
q.segment.bind(12, nullptr);
}
q.segment.bind(13, nesting.is_leaf);
q.segment.exec();
q.segment.reset();
}
Expand Down
1 change: 1 addition & 0 deletions scripts/cxx_codegen/profdata_merger/profdata_merger.sql
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ CREATE TABLE "CovSegment" (
"Context" INTEGER NOT NULL,
"SegmentIndex" INTEGER NOT NULL,
"NestedIn" INTEGER,
"IsLeaf" BOOLEAN NOT NULL,
PRIMARY KEY ("Id"),
FOREIGN KEY("File") REFERENCES "CovFile" ("Id"),
FOREIGN KEY("Context") REFERENCES "CovContext" ("Id"),
Expand Down
1 change: 1 addition & 0 deletions scripts/py_repository/py_repository/gen_coverage_cxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class CovSegment(CoverageSchema):
Context = ForeignId(CovContext.Id)
SegmentIndex = IntColumn()
NestedIn = ForeignId("CovSegment.Id", nullable=True)
IsLeaf = BoolColumn()


class CovInstantiationGroup(CoverageSchema):
Expand Down
5 changes: 5 additions & 0 deletions tests/python/repo/test_code_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,15 @@ def test_file_segmentation():
EndLine=1,
SegmentIndex=0,
Text="{}",
IsLeaf=True,
),
dict(
StartLine=3,
EndLine=5,
SegmentIndex=1,
Id=2,
Text="{ if (true || false) { action(); } }",
IsLeaf=False,
),
dict(
StartLine=4,
Expand All @@ -359,6 +361,7 @@ def test_file_segmentation():
StartCol=9,
EndCol=13,
NestedIn=2,
IsLeaf=True,
),
dict(
StartLine=4,
Expand All @@ -368,11 +371,13 @@ def test_file_segmentation():
StartCol=17,
EndCol=22,
NestedIn=2,
IsLeaf=True,
),
dict(
StartLine=4,
SegmentIndex=4,
Text="{ action(); }",
NestedIn=2,
IsLeaf=True,
),
])

0 comments on commit 46955d3

Please sign in to comment.