Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ccffa7d

Browse files
committed
Python: CG trace: Ignore some calls for call-grahp metrics
and provide some internal metrics as well
1 parent b227a7e commit ccffa7d

4 files changed

Lines changed: 73 additions & 11 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Metrics for evaluating how good we are at interpreting results from the cg_trace program.
3+
* See Metrics.ql for call-graph quality metrics.
4+
*/
5+
6+
import RecordedCalls
7+
8+
from string text, float number, float ratio
9+
where
10+
exists(int all_rcs | all_rcs = count(XMLRecordedCall rc) and ratio = number / all_rcs |
11+
text = "XMLRecordedCall" and number = all_rcs
12+
or
13+
text = "IdentifiedRecordedCall" and number = count(IdentifiedRecordedCall rc)
14+
or
15+
text = "UnidentifiedRecordedCall" and number = count(UnidentifiedRecordedCall rc)
16+
)
17+
select text, number, ratio * 100 + "%" as percent
Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,54 @@
11
import RecordedCalls
22

3-
from string text, float number, float ratio
3+
4+
from string text, float number, float ratio, int i
45
where
56
exists(int all_rcs | all_rcs = count(XMLRecordedCall rc) and ratio = number / all_rcs |
6-
text = "Number of XMLRecordedCall" and number = all_rcs
7+
text = "XMLRecordedCall" and number = all_rcs and i = 0
78
or
8-
text = "Number of IdentifiedRecordedCall" and number = count(IdentifiedRecordedCall rc)
9+
text = "IgnoredRecordedCall" and number = count(IgnoredRecordedCall rc) and i = 1
10+
)
11+
or
12+
text = "----------" and
13+
number = 0 and
14+
ratio = 0 and
15+
i = 2
16+
or
17+
exists(int all_not_ignored_rcs |
18+
all_not_ignored_rcs = count(XMLRecordedCall rc | not rc instanceof IgnoredRecordedCall) and
19+
ratio = number / all_not_ignored_rcs
20+
|
21+
text = "IdentifiedRecordedCall" and
22+
number = count(IdentifiedRecordedCall rc | not rc instanceof IgnoredRecordedCall) and
23+
i = 3
924
or
10-
text = "Number of UnidentifiedRecordedCall" and number = count(UnidentifiedRecordedCall rc)
25+
text = "UnidentifiedRecordedCall" and
26+
number = count(UnidentifiedRecordedCall rc | not rc instanceof IgnoredRecordedCall) and
27+
i = 4
1128
)
1229
or
30+
text = "----------" and
31+
number = 0 and
32+
ratio = 0 and
33+
i = 5
34+
or
1335
exists(int all_identified_rcs |
14-
all_identified_rcs = count(IdentifiedRecordedCall rc) and ratio = number / all_identified_rcs
36+
all_identified_rcs = count(IdentifiedRecordedCall rc | not rc instanceof IgnoredRecordedCall) and
37+
ratio = number / all_identified_rcs
1538
|
16-
text = "Number of points-to ResolvableRecordedCall" and
17-
number = count(PointsToBasedCallGraph::ResolvableRecordedCall rc)
39+
text = "points-to ResolvableRecordedCall" and
40+
number =
41+
count(PointsToBasedCallGraph::ResolvableRecordedCall rc |
42+
not rc instanceof IgnoredRecordedCall
43+
) and
44+
i = 6
1845
or
19-
text = "Number of points-to NOT ResolvableRecordedCall" and
20-
number = all_identified_rcs - count(PointsToBasedCallGraph::ResolvableRecordedCall rc)
46+
text = "points-to not ResolvableRecordedCall" and
47+
number =
48+
all_identified_rcs -
49+
count(PointsToBasedCallGraph::ResolvableRecordedCall rc |
50+
not rc instanceof IgnoredRecordedCall
51+
) and
52+
i = 7
2153
)
22-
select text, number, ratio * 100 + "%" as percent
54+
select i, text, number, ratio * 100 + "%" as percent order by i

python/tools/recorded-call-graph-metrics/ql/PointsToNotFound.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import RecordedCalls
22

33
from IdentifiedRecordedCall rc
44
where not rc instanceof PointsToBasedCallGraph::ResolvableRecordedCall
5-
select rc
5+
select rc, rc.getCall()

python/tools/recorded-call-graph-metrics/ql/RecordedCalls.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,19 @@ class UnidentifiedRecordedCall extends XMLRecordedCall {
200200
UnidentifiedRecordedCall() { not this instanceof IdentifiedRecordedCall }
201201
}
202202

203+
/**
204+
* Recorded calls made from outside project folder, that can be ignored when evaluating
205+
* call-graph quality.
206+
*/
207+
class IgnoredRecordedCall extends XMLRecordedCall {
208+
IgnoredRecordedCall() {
209+
not exists(
210+
any(File file | file.getAbsolutePath() = this.getXMLCall().get_filename_data())
211+
.getRelativePath()
212+
)
213+
}
214+
}
215+
203216
module PointsToBasedCallGraph {
204217
class ResolvableRecordedCall extends IdentifiedRecordedCall {
205218
Value calleeValue;

0 commit comments

Comments
 (0)