mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Python: CG trace: Ignore some calls for call-grahp metrics
and provide some internal metrics as well
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
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 = "IdentifiedRecordedCall" and
|
||||
number = count(IdentifiedRecordedCall rc | not rc instanceof IgnoredRecordedCall) and
|
||||
i = 3
|
||||
or
|
||||
text = "UnidentifiedRecordedCall" and
|
||||
number = count(UnidentifiedRecordedCall rc | not rc instanceof IgnoredRecordedCall) and
|
||||
i = 4
|
||||
)
|
||||
or
|
||||
text = "----------" and
|
||||
number = 0 and
|
||||
ratio = 0 and
|
||||
i = 5
|
||||
or
|
||||
exists(int all_identified_rcs |
|
||||
all_identified_rcs = count(IdentifiedRecordedCall rc) and ratio = number / all_identified_rcs
|
||||
all_identified_rcs = count(IdentifiedRecordedCall rc | not rc instanceof IgnoredRecordedCall) and
|
||||
ratio = number / all_identified_rcs
|
||||
|
|
||||
text = "Number of points-to ResolvableRecordedCall" and
|
||||
number = count(PointsToBasedCallGraph::ResolvableRecordedCall rc)
|
||||
text = "points-to ResolvableRecordedCall" and
|
||||
number =
|
||||
count(PointsToBasedCallGraph::ResolvableRecordedCall rc |
|
||||
not rc instanceof IgnoredRecordedCall
|
||||
) and
|
||||
i = 6
|
||||
or
|
||||
text = "Number of points-to NOT ResolvableRecordedCall" and
|
||||
number = all_identified_rcs - count(PointsToBasedCallGraph::ResolvableRecordedCall rc)
|
||||
text = "points-to not ResolvableRecordedCall" and
|
||||
number =
|
||||
all_identified_rcs -
|
||||
count(PointsToBasedCallGraph::ResolvableRecordedCall rc |
|
||||
not rc instanceof IgnoredRecordedCall
|
||||
) and
|
||||
i = 7
|
||||
)
|
||||
select text, number, ratio * 100 + "%" as percent
|
||||
select i, text, number, ratio * 100 + "%" as percent order by i
|
||||
|
||||
@@ -2,4 +2,4 @@ import RecordedCalls
|
||||
|
||||
from IdentifiedRecordedCall rc
|
||||
where not rc instanceof PointsToBasedCallGraph::ResolvableRecordedCall
|
||||
select rc
|
||||
select rc, rc.getCall()
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user