|
| 1 | +/** |
| 2 | + * Provides a class representing individual compiler invocations that occurred during the build. |
| 3 | + */ |
| 4 | + |
| 5 | +import semmle.code.FileSystem |
| 6 | + |
| 7 | +/** |
| 8 | + * An invocation of the compiler. Note that more than one file may be |
| 9 | + * compiled per invocation. For example, this command compiles three |
| 10 | + * source files: |
| 11 | + * |
| 12 | + * javac Foo.java Bar.java Baz.java |
| 13 | + * |
| 14 | + * Two things happen to each file during a compilation: |
| 15 | + * |
| 16 | + * 1. The file is compiled by a real compiler, such as javac or kotlinc. |
| 17 | + * 2. The file is parsed by the CodeQL front-end. |
| 18 | + * 3. The parsed representation is converted to database tables by |
| 19 | + * the CodeQL extractor. |
| 20 | + * |
| 21 | + * This class provides CPU and elapsed time information for steps 2 and 3, |
| 22 | + * but not for step 1. |
| 23 | + */ |
| 24 | +class Compilation extends @compilation { |
| 25 | + /** Gets a textual representation of this element. */ |
| 26 | + string toString() { |
| 27 | + exists(string name | |
| 28 | + compilations(this, _, _, name) and |
| 29 | + result = "<compilation " + name + ">" |
| 30 | + ) |
| 31 | + } |
| 32 | + |
| 33 | + /** Gets a file compiled during this invocation. */ |
| 34 | + File getAFileCompiled() { result = getFileCompiled(_) } |
| 35 | + |
| 36 | + /** Gets the `i`th file compiled during this invocation */ |
| 37 | + File getFileCompiled(int i) { compilation_compiling_files(this, i, result) } |
| 38 | + |
| 39 | + /** |
| 40 | + * Gets the amount of CPU time spent processing file number `i` in the |
| 41 | + * front-end. |
| 42 | + */ |
| 43 | + float getFrontendCpuSeconds(int i) { compilation_time(this, i, 1, result) } |
| 44 | + |
| 45 | + /** |
| 46 | + * Gets the amount of elapsed time while processing file number `i` in the |
| 47 | + * front-end. |
| 48 | + */ |
| 49 | + float getFrontendElapsedSeconds(int i) { compilation_time(this, i, 2, result) } |
| 50 | + |
| 51 | + /** |
| 52 | + * Gets the amount of CPU time spent processing file number `i` in the |
| 53 | + * extractor. |
| 54 | + */ |
| 55 | + float getExtractorCpuSeconds(int i) { compilation_time(this, i, 3, result) } |
| 56 | + |
| 57 | + /** |
| 58 | + * Gets the amount of elapsed time while processing file number `i` in the |
| 59 | + * extractor. |
| 60 | + */ |
| 61 | + float getExtractorElapsedSeconds(int i) { compilation_time(this, i, 4, result) } |
| 62 | + |
| 63 | + /** |
| 64 | + * Gets an argument passed to the extractor on this invocation. |
| 65 | + */ |
| 66 | + string getAnArgument() { result = getArgument(_) } |
| 67 | + |
| 68 | + /** |
| 69 | + * Gets the `i`th argument passed to the extractor on this invocation. |
| 70 | + */ |
| 71 | + string getArgument(int i) { compilation_args(this, i, result) } |
| 72 | + |
| 73 | + /** |
| 74 | + * Gets the total amount of CPU time spent processing all the files in the |
| 75 | + * front-end and extractor. |
| 76 | + */ |
| 77 | + float getTotalCpuSeconds() { compilation_finished(this, result, _) } |
| 78 | + |
| 79 | + /** |
| 80 | + * Gets the total amount of elapsed time while processing all the files in |
| 81 | + * the front-end and extractor. |
| 82 | + */ |
| 83 | + float getTotalElapsedSeconds() { compilation_finished(this, _, result) } |
| 84 | + |
| 85 | + /** |
| 86 | + * Holds if this is a compilation of Java code. |
| 87 | + */ |
| 88 | + predicate isJava() { this instanceof @javacompilation } |
| 89 | + |
| 90 | + /** |
| 91 | + * Holds if this is a compilation of Kotlin code. |
| 92 | + */ |
| 93 | + predicate isKotlin() { this instanceof @kotlincompilation } |
| 94 | + |
| 95 | + /** |
| 96 | + * Holds if extraction for the compilation started. |
| 97 | + */ |
| 98 | + predicate extractionStarted() { compilation_started(this) } |
| 99 | + |
| 100 | + /** |
| 101 | + * Holds if the extractor terminated normally. Terminating with an exit |
| 102 | + * code indicating that an error occurred is considered normal |
| 103 | + * termination, but crashing due to something like a segfault is not. |
| 104 | + */ |
| 105 | + predicate normalTermination() { compilation_finished(this, _, _) } |
| 106 | +} |
0 commit comments