mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Python: CG trace: Add overall metrics query
This commit is contained in:
22
python/tools/recorded-call-graph-metrics/ql/Metrics.ql
Normal file
22
python/tools/recorded-call-graph-metrics/ql/Metrics.ql
Normal file
@@ -0,0 +1,22 @@
|
||||
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 = "Number of XMLRecordedCall" and number = all_rcs
|
||||
or
|
||||
text = "Number of IdentifiedRecordedCall" and number = count(IdentifiedRecordedCall rc)
|
||||
or
|
||||
text = "Number of UnidentifiedRecordedCall" and number = count(UnidentifiedRecordedCall rc)
|
||||
)
|
||||
or
|
||||
exists(int all_identified_rcs |
|
||||
all_identified_rcs = count(IdentifiedRecordedCall rc) and ratio = number / all_identified_rcs
|
||||
|
|
||||
text = "Number of points-to ResolvableRecordedCall" and
|
||||
number = count(PointsToBasedCallGraph::ResolvableRecordedCall rc)
|
||||
or
|
||||
text = "Number of points-to NOT ResolvableRecordedCall" and
|
||||
number = all_identified_rcs - count(PointsToBasedCallGraph::ResolvableRecordedCall rc)
|
||||
)
|
||||
select text, number, ratio * 100 + "%" as percent
|
||||
@@ -77,6 +77,14 @@ class XMLCall extends XMLElement {
|
||||
bytecode.(XMLBytecodeAttribute).get_object_data())
|
||||
or
|
||||
matchBytecodeExpr(expr.(Call).getFunc(), bytecode.(XMLBytecodeCall).get_function_data())
|
||||
// I experimented with allowing partial matches with
|
||||
// ```
|
||||
// or
|
||||
// bytecode instanceof XMLBytecodeUnknown
|
||||
// ```
|
||||
// but that only gave 1% improvement for Identified calls with approx 4200 calls
|
||||
// in total (only supporting BytecodeVariableName/BytecodeAttribute/BytecodeCall).
|
||||
// Since it's a potential performance problem, I did not enable.
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user