Merge pull request #10679 from michaelnebel/csharp/telemetryresults

C#/Java: Limit telemetry results.
This commit is contained in:
Michael Nebel
2022-10-12 14:52:20 +02:00
committed by GitHub
10 changed files with 89 additions and 90 deletions

View File

@@ -105,29 +105,40 @@ deprecated class ExternalAPI = ExternalApi;
int resultLimit() { result = 1000 }
/**
* Holds if the relevant usage count of `api` is `usages`.
* Holds if it is relevant to count usages of `api`.
*/
signature predicate relevantUsagesSig(ExternalApi api, int usages);
signature predicate relevantApi(ExternalApi api);
/**
* Given a predicate to count relevant API usages, this module provides a predicate
* for restricting the number or returned results based on a certain limit.
*/
module Results<relevantUsagesSig/2 getRelevantUsages> {
private int getOrder(ExternalApi api) {
api =
rank[result](ExternalApi a, int usages |
getRelevantUsages(a, usages)
module Results<relevantApi/1 getRelevantUsages> {
private int getUsages(string apiName) {
result =
strictcount(Call c, ExternalApi api |
c.getCallee().getSourceDeclaration() = api and
not c.getFile() instanceof GeneratedFile and
apiName = api.getApiName() and
getRelevantUsages(api)
)
}
private int getOrder(string apiInfo) {
apiInfo =
rank[result](string info, int usages |
usages = getUsages(info)
|
a order by usages desc, a.getApiName()
info order by usages desc, info
)
}
/**
* Holds if `api` is being used `usages` times and if it is
* in the top results (guarded by resultLimit).
* Holds if there exists an API with `apiName` that is being used `usages` times
* and if it is in the top results (guarded by resultLimit).
*/
predicate restrict(ExternalApi api, int usages) {
getRelevantUsages(api, usages) and getOrder(api) <= resultLimit()
predicate restrict(string apiName, int usages) {
usages = getUsages(apiName) and
getOrder(apiName) <= resultLimit()
}
}

View File

@@ -9,16 +9,11 @@
import java
import ExternalApi
private predicate getRelevantUsages(ExternalApi api, int usages) {
private predicate relevant(ExternalApi api) {
not api.isUninteresting() and
api.isSink() and
usages =
strictcount(Call c |
c.getCallee().getSourceDeclaration() = api and
not c.getFile() instanceof GeneratedFile
)
api.isSink()
}
from ExternalApi api, int usages
where Results<getRelevantUsages/2>::restrict(api, usages)
select api.getApiName() as apiname, usages order by usages desc
from string apiName, int usages
where Results<relevant/1>::restrict(apiName, usages)
select apiName, usages order by usages desc

View File

@@ -9,16 +9,11 @@
import java
import ExternalApi
private predicate getRelevantUsages(ExternalApi api, int usages) {
private predicate relevant(ExternalApi api) {
not api.isUninteresting() and
api.isSource() and
usages =
strictcount(Call c |
c.getCallee().getSourceDeclaration() = api and
not c.getFile() instanceof GeneratedFile
)
api.isSource()
}
from ExternalApi api, int usages
where Results<getRelevantUsages/2>::restrict(api, usages)
select api.getApiName() as apiname, usages order by usages desc
from string apiName, int usages
where Results<relevant/1>::restrict(apiName, usages)
select apiName, usages order by usages desc

View File

@@ -9,16 +9,11 @@
import java
import ExternalApi
private predicate getRelevantUsages(ExternalApi api, int usages) {
private predicate relevant(ExternalApi api) {
not api.isUninteresting() and
api.hasSummary() and
usages =
strictcount(Call c |
c.getCallee().getSourceDeclaration() = api and
not c.getFile() instanceof GeneratedFile
)
api.hasSummary()
}
from ExternalApi api, int usages
where Results<getRelevantUsages/2>::restrict(api, usages)
select api.getApiName() as apiname, usages order by usages desc
from string apiName, int usages
where Results<relevant/1>::restrict(apiName, usages)
select apiName, usages order by usages desc

View File

@@ -11,17 +11,12 @@ import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
import semmle.code.java.dataflow.internal.NegativeSummary
import ExternalApi
private predicate getRelevantUsages(ExternalApi api, int usages) {
private predicate relevant(ExternalApi api) {
not api.isUninteresting() and
not api.isSupported() and
not api instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable and
usages =
strictcount(Call c |
c.getCallee().getSourceDeclaration() = api and
not c.getFile() instanceof GeneratedFile
)
not api instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable
}
from ExternalApi api, int usages
where Results<getRelevantUsages/2>::restrict(api, usages)
select api.getApiName() as apiname, usages order by usages desc
from string apiName, int usages
where Results<relevant/1>::restrict(apiName, usages)
select apiName, usages order by usages desc