Merge pull request #9553 from michaelnebel/csharp/narrowtelemetry

C#/Java: Only display 1k most relevant results for ExternalApi telemetry queries.
This commit is contained in:
Michael Nebel
2022-06-22 07:35:56 +02:00
committed by GitHub
12 changed files with 136 additions and 24 deletions

View File

@@ -98,3 +98,36 @@ class ExternalApi extends Callable {
/** DEPRECATED: Alias for ExternalApi */
deprecated class ExternalAPI = ExternalApi;
/**
* Gets the limit for the number of results produced by a telemetry query.
*/
int resultLimit() { result = 1000 }
/**
* Holds if the relevant usage count of `api` is `usages`.
*/
signature predicate relevantUsagesSig(ExternalApi api, int usages);
/**
* 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)
|
a order by usages desc, a.getApiName()
)
}
/**
* Holds if `api` 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()
}
}

View File

@@ -9,8 +9,7 @@
import java
import ExternalApi
from int usages, string jarname
where
private predicate getRelevantUsages(string jarname, int usages) {
usages =
strictcount(Call c, ExternalApi a |
c.getCallee().getSourceDeclaration() = a and
@@ -18,4 +17,20 @@ where
a.jarContainer() = jarname and
not a.isUninteresting()
)
}
private int getOrder(string jarname) {
jarname =
rank[result](string jar, int usages |
getRelevantUsages(jar, usages)
|
jar order by usages desc, jar
)
}
from ExternalApi api, string jarname, int usages
where
jarname = api.jarContainer() and
getRelevantUsages(jarname, usages) and
getOrder(jarname) <= resultLimit()
select jarname, usages order by usages desc

View File

@@ -8,10 +8,8 @@
import java
import ExternalApi
import semmle.code.java.GeneratedFiles
from ExternalApi api, int usages
where
private predicate getRelevantUsages(ExternalApi api, int usages) {
not api.isUninteresting() and
api.isSink() and
usages =
@@ -19,4 +17,8 @@ where
c.getCallee().getSourceDeclaration() = api and
not c.getFile() instanceof GeneratedFile
)
}
from ExternalApi api, int usages
where Results<getRelevantUsages/2>::restrict(api, usages)
select api.getApiName() as apiname, usages order by usages desc

View File

@@ -8,10 +8,8 @@
import java
import ExternalApi
import semmle.code.java.GeneratedFiles
from ExternalApi api, int usages
where
private predicate getRelevantUsages(ExternalApi api, int usages) {
not api.isUninteresting() and
api.isSource() and
usages =
@@ -19,4 +17,8 @@ where
c.getCallee().getSourceDeclaration() = api and
not c.getFile() instanceof GeneratedFile
)
}
from ExternalApi api, int usages
where Results<getRelevantUsages/2>::restrict(api, usages)
select api.getApiName() as apiname, usages order by usages desc

View File

@@ -8,10 +8,8 @@
import java
import ExternalApi
import semmle.code.java.GeneratedFiles
from ExternalApi api, int usages
where
private predicate getRelevantUsages(ExternalApi api, int usages) {
not api.isUninteresting() and
api.hasSummary() and
usages =
@@ -19,4 +17,8 @@ where
c.getCallee().getSourceDeclaration() = api and
not c.getFile() instanceof GeneratedFile
)
}
from ExternalApi api, int usages
where Results<getRelevantUsages/2>::restrict(api, usages)
select api.getApiName() as apiname, usages order by usages desc

View File

@@ -8,10 +8,8 @@
import java
import ExternalApi
import semmle.code.java.GeneratedFiles
from ExternalApi api, int usages
where
private predicate getRelevantUsages(ExternalApi api, int usages) {
not api.isUninteresting() and
not api.isSupported() and
usages =
@@ -19,4 +17,8 @@ where
c.getCallee().getSourceDeclaration() = api and
not c.getFile() instanceof GeneratedFile
)
}
from ExternalApi api, int usages
where Results<getRelevantUsages/2>::restrict(api, usages)
select api.getApiName() as apiname, usages order by usages desc