Skip to content

Commit 39bb3f2

Browse files
committed
C#: Fix elapsed timings and add a test for it.
1 parent c67e441 commit 39bb3f2

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Extractor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public void MissingType(string type) { }
6363
public static ExitCode Run(string[] args)
6464
{
6565
var stopwatch = new Stopwatch();
66+
stopwatch.Start();
6667
var commandLineArguments = Options.CreateWithEnvironment(args);
6768
var fileLogger = new FileLogger(commandLineArguments.Verbosity, GetCSharpLogPath());
6869
var logger = commandLineArguments.Console

csharp/ql/src/semmle/code/csharp/commons/Compilation.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,10 @@ class Compilation extends @compilation {
5656

5757
/** Gets the peak working set of the extractor process in MB. */
5858
float getPeakWorkingSetMB() { result = getMetric(6) }
59+
60+
/** Gets the CPU seconds for the entire extractor process. */
61+
float getCpuSeconds() { compilation_finished(this, result, _) }
62+
63+
/** Gets the elapsed seconds for the entire extractor process. */
64+
float getElapsedSeconds() { compilation_finished(this, _, result) }
5965
}

csharp/ql/src/semmle/code/csharp/commons/Diagnostics.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ExtractorMessage extends @extractor_message {
7777
/** Gets the name of the extractor that produced this message, for example, `C# extractor`. */
7878
string getOrigin() { result = origin }
7979

80-
/** Gets the text of this diagnostic. */
80+
/** Gets the text of this message. */
8181
string getText() { result = text }
8282

8383
/** Gets the textual representation of the entity that triggered this message. */

csharp/ql/test/library-tests/compilations/Compilations.expected

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ diagnosticElements
2929
| Program.cs:9:13:9:13 | CS0219: The variable 'y' is assigned but its value is never used | Program.cs:9:13:9:13 | access to local variable y |
3030
| Program.cs:9:13:9:13 | CS0219: The variable 'y' is assigned but its value is never used | Program.cs:9:13:9:13 | y |
3131
references
32-
| compilation | 0 | System.Core.dll |
33-
| compilation | 1 | System.Console.dll |
34-
| compilation | 2 | mscorlib.dll |
35-
| compilation | 3 | System.Runtime.dll |
36-
| compilation | 4 | System.dll |
37-
| compilation | 5 | System.Private.CoreLib.dll |
32+
| compilation | System.Console.dll |
33+
| compilation | System.Core.dll |
34+
| compilation | System.Private.CoreLib.dll |
35+
| compilation | System.Runtime.dll |
36+
| compilation | System.dll |
37+
| compilation | mscorlib.dll |
38+
timings
39+
| compilation |

csharp/ql/test/library-tests/compilations/Compilations.ql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ query predicate compilationFolder(Compilation c, string folder) {
3131

3232
query predicate diagnosticElements(Diagnostic d, Element e) { e = d.getElement() }
3333

34-
query predicate references(Compilation c, int i, string reference) {
35-
reference = c.getReference(i).getBaseName()
34+
query predicate references(Compilation c, string reference) {
35+
reference = c.getAReference().getBaseName()
36+
}
37+
38+
query predicate timings(Compilation c) {
39+
c.getCpuSeconds() > 0 and
40+
c.getElapsedSeconds() > 0
3641
}

0 commit comments

Comments
 (0)