Skip to content

Commit f0b5058

Browse files
committed
C#: Remove filename from telemetry output.
1 parent 924f999 commit f0b5058

File tree

2 files changed

+24
-34
lines changed

2 files changed

+24
-34
lines changed

csharp/ql/src/Telemetry/ExternalApi.qll

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,12 @@ class ExternalApi extends DotNet::Callable {
4242
/**
4343
* Gets the namespace of this API.
4444
*/
45-
private string getNamespace() { this.getDeclaringType().hasQualifiedName(result, _) }
45+
string getNamespace() { this.getDeclaringType().hasQualifiedName(result, _) }
4646

4747
/**
48-
* Gets the assembly file name containing this API.
48+
* Gets the namespace and signature of this API.
4949
*/
50-
private string getAssembly() { result = this.getFile().getBaseName() }
51-
52-
/**
53-
* Gets the assembly file name and namespace of this API.
54-
*/
55-
string getInfoPrefix() { result = this.getAssembly() + "#" + this.getNamespace() }
56-
57-
/**
58-
* Gets the assembly file name, namespace and signature of this API.
59-
*/
60-
string getInfo() { result = this.getInfoPrefix() + "#" + this.getSignature() }
50+
string getApiName() { result = this.getNamespace() + "#" + this.getSignature() }
6151

6252
/** Gets a call to this API callable. */
6353
DispatchCall getACall() {
@@ -125,30 +115,30 @@ signature predicate relevantApi(ExternalApi api);
125115
* for restricting the number or returned results based on a certain limit.
126116
*/
127117
module Results<relevantApi/1 getRelevantUsages> {
128-
private int getUsages(string apiInfo) {
118+
private int getUsages(string apiName) {
129119
result =
130120
strictcount(DispatchCall c, ExternalApi api |
131121
c = api.getACall() and
132-
apiInfo = api.getInfo() and
122+
apiName = api.getApiName() and
133123
getRelevantUsages(api)
134124
)
135125
}
136126

137-
private int getOrder(string apiInfo) {
138-
apiInfo =
139-
rank[result](string info, int usages |
140-
usages = getUsages(info)
127+
private int getOrder(string apiName) {
128+
apiName =
129+
rank[result](string name, int usages |
130+
usages = getUsages(name)
141131
|
142-
info order by usages desc, info
132+
name order by usages desc, name
143133
)
144134
}
145135

146136
/**
147-
* Holds if there exists an API with `apiInfo` that is being used `usages` times
137+
* Holds if there exists an API with `apiName` that is being used `usages` times
148138
* and if it is in the top results (guarded by resultLimit).
149139
*/
150-
predicate restrict(string apiInfo, int usages) {
151-
usages = getUsages(apiInfo) and
152-
getOrder(apiInfo) <= resultLimit()
140+
predicate restrict(string apiName, int usages) {
141+
usages = getUsages(apiName) and
142+
getOrder(apiName) <= resultLimit()
153143
}
154144
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @name External libraries
3-
* @description A list of external libraries used in the code
3+
* @description A list of external libraries used in the code given by their namespace.
44
* @kind metric
55
* @tags summary telemetry
66
* @id csharp/telemetry/external-libs
@@ -10,23 +10,23 @@ private import csharp
1010
private import semmle.code.csharp.dispatch.Dispatch
1111
private import ExternalApi
1212

13-
private predicate getRelevantUsages(string info, int usages) {
13+
private predicate getRelevantUsages(string namespace, int usages) {
1414
usages =
1515
strictcount(DispatchCall c, ExternalApi api |
1616
c = api.getACall() and
17-
api.getInfoPrefix() = info and
17+
api.getNamespace() = namespace and
1818
not api.isUninteresting()
1919
)
2020
}
2121

22-
private int getOrder(string info) {
23-
info =
22+
private int getOrder(string namespace) {
23+
namespace =
2424
rank[result](string i, int usages | getRelevantUsages(i, usages) | i order by usages desc, i)
2525
}
2626

27-
from ExternalApi api, string info, int usages
27+
from ExternalApi api, string namespace, int usages
2828
where
29-
info = api.getInfoPrefix() and
30-
getRelevantUsages(info, usages) and
31-
getOrder(info) <= resultLimit()
32-
select info, usages order by usages desc
29+
namespace = api.getNamespace() and
30+
getRelevantUsages(namespace, usages) and
31+
getOrder(namespace) <= resultLimit()
32+
select namespace, usages order by usages desc

0 commit comments

Comments
 (0)