Python: CG trace: Ignore some calls for call-grahp metrics

and provide some internal metrics as well
This commit is contained in:
Rasmus Wriedt Larsen
2020-07-22 13:12:52 +02:00
parent b227a7ec90
commit ccffa7d99d
4 changed files with 75 additions and 13 deletions

View File

@@ -0,0 +1,17 @@
/**
* Metrics for evaluating how good we are at interpreting results from the cg_trace program.
* See Metrics.ql for call-graph quality metrics.
*/
import RecordedCalls
from string text, float number, float ratio
where
exists(int all_rcs | all_rcs = count(XMLRecordedCall rc) and ratio = number / all_rcs |
text = "XMLRecordedCall" and number = all_rcs
or
text = "IdentifiedRecordedCall" and number = count(IdentifiedRecordedCall rc)
or
text = "UnidentifiedRecordedCall" and number = count(UnidentifiedRecordedCall rc)
)
select text, number, ratio * 100 + "%" as percent

View File

@@ -1,22 +1,54 @@
import RecordedCalls
from string text, float number, float ratio
from string text, float number, float ratio, int i
where
exists(int all_rcs | all_rcs = count(XMLRecordedCall rc) and ratio = number / all_rcs |
text = "Number of XMLRecordedCall" and number = all_rcs
text = "XMLRecordedCall" and number = all_rcs and i = 0
or
text = "Number of IdentifiedRecordedCall" and number = count(IdentifiedRecordedCall rc)
or
text = "Number of UnidentifiedRecordedCall" and number = count(UnidentifiedRecordedCall rc)
text = "IgnoredRecordedCall" and number = count(IgnoredRecordedCall rc) and i = 1
)
or
exists(int all_identified_rcs |
all_identified_rcs = count(IdentifiedRecordedCall rc) and ratio = number / all_identified_rcs
text = "----------" and
number = 0 and
ratio = 0 and
i = 2
or
exists(int all_not_ignored_rcs |
all_not_ignored_rcs = count(XMLRecordedCall rc | not rc instanceof IgnoredRecordedCall) and
ratio = number / all_not_ignored_rcs
|
text = "Number of points-to ResolvableRecordedCall" and
number = count(PointsToBasedCallGraph::ResolvableRecordedCall rc)
text = "IdentifiedRecordedCall" and
number = count(IdentifiedRecordedCall rc | not rc instanceof IgnoredRecordedCall) and
i = 3
or
text = "Number of points-to NOT ResolvableRecordedCall" and
number = all_identified_rcs - count(PointsToBasedCallGraph::ResolvableRecordedCall rc)
text = "UnidentifiedRecordedCall" and
number = count(UnidentifiedRecordedCall rc | not rc instanceof IgnoredRecordedCall) and
i = 4
)
select text, number, ratio * 100 + "%" as percent
or
text = "----------" and
number = 0 and
ratio = 0 and
i = 5
or
exists(int all_identified_rcs |
all_identified_rcs = count(IdentifiedRecordedCall rc | not rc instanceof IgnoredRecordedCall) and
ratio = number / all_identified_rcs
|
text = "points-to ResolvableRecordedCall" and
number =
count(PointsToBasedCallGraph::ResolvableRecordedCall rc |
not rc instanceof IgnoredRecordedCall
) and
i = 6
or
text = "points-to not ResolvableRecordedCall" and
number =
all_identified_rcs -
count(PointsToBasedCallGraph::ResolvableRecordedCall rc |
not rc instanceof IgnoredRecordedCall
) and
i = 7
)
select i, text, number, ratio * 100 + "%" as percent order by i

View File

@@ -2,4 +2,4 @@ import RecordedCalls
from IdentifiedRecordedCall rc
where not rc instanceof PointsToBasedCallGraph::ResolvableRecordedCall
select rc
select rc, rc.getCall()

View File

@@ -200,6 +200,19 @@ class UnidentifiedRecordedCall extends XMLRecordedCall {
UnidentifiedRecordedCall() { not this instanceof IdentifiedRecordedCall }
}
/**
* Recorded calls made from outside project folder, that can be ignored when evaluating
* call-graph quality.
*/
class IgnoredRecordedCall extends XMLRecordedCall {
IgnoredRecordedCall() {
not exists(
any(File file | file.getAbsolutePath() = this.getXMLCall().get_filename_data())
.getRelativePath()
)
}
}
module PointsToBasedCallGraph {
class ResolvableRecordedCall extends IdentifiedRecordedCall {
Value calleeValue;