-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PoC: move evaluator external log processing here
This is a PoC for moving the external implementations we have for evaluator log processing into this repository. This does not yet modify the runtime of this repository, but it does add immutable.js to the package.json file.
- Loading branch information
Showing
15 changed files
with
2,268 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# log-insights/core | ||
|
||
The core of the `log-insights` feature: provides insights from the raw logs emitted by the CodeQL CLI. | ||
|
||
This is intended to be a vscode independent directory that in theory can be used in external contexts as well, or become a package of its own one day. | ||
The unit tests for this directory define the interface, and there are no guarantees about external compatibility beyond that. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { cpSync, createReadStream, mkdtempSync } from "fs"; | ||
import { join } from "path"; | ||
// eslint-disable-next-line import/no-namespace | ||
import * as badnessMetrics from "./log-processors/badness-metrics"; | ||
// eslint-disable-next-line import/no-namespace | ||
import * as expensivePredicates from "./log-processors/expensive-predicates"; | ||
// eslint-disable-next-line import/no-namespace | ||
import * as logSummary from "./log-processors/log-summary"; | ||
// eslint-disable-next-line import/no-namespace | ||
import * as stageTimings from "./log-processors/stage-timings"; | ||
// eslint-disable-next-line import/no-namespace | ||
import * as tupleSums from "./log-processors/tuple-sums"; | ||
import { log } from "./util"; | ||
|
||
/** | ||
* Minimal CLI interface for running the evaluator log processing locally. | ||
* | ||
* Intended for use in development and debugging. | ||
* This is not intended to be a full-featured CLI tool, nor as a replacement for ordinary testing. | ||
* | ||
* Sample use: | ||
* | ||
* ``` | ||
* $ ts-node cli.ts badness-metrics codeql ~/Downloads/codeql-evaluator-log.json | ||
* ``` | ||
*/ | ||
async function main(args: string[]) { | ||
const positionals = args.filter((arg) => !arg.startsWith("--")); | ||
const [operation, codeqlPath, logPath] = positionals; | ||
const options = args.filter((arg) => arg.startsWith("--")); | ||
const verbose = options.includes("--verbose"); | ||
const explicitOutputFile = options | ||
.find((arg) => arg.startsWith("--output=")) | ||
?.split("=")[1]; | ||
const help = options.includes("--help"); | ||
// dear future reader. Please consider using a proper CLI library instead of this ad hoc parsing. | ||
const usage = [ | ||
"Usage: cli <badness-metrics|expensive-predicates|overall-summary|predicates-summary|stage-timings|tuple-sums> <codeql-path> <summary-log-path> [--verbose] [--output=<output-file>]", | ||
].join("\n"); | ||
|
||
if (help) { | ||
console.log(usage); | ||
return; | ||
} | ||
if (!operation || !codeqlPath || !logPath) { | ||
throw new Error(`Missing arguments.\n\n${usage}`); | ||
} | ||
async function makeSummaryLogFile(format: "overall" | "predicates") { | ||
const summaryLogFile = `${logPath}.${format}.log`; | ||
await logSummary.process(codeqlPath, logPath, summaryLogFile, format); | ||
return summaryLogFile; | ||
} | ||
|
||
const implicitOutputFile = join( | ||
mkdtempSync("log-insights-"), | ||
"implicit-output.txt", | ||
); | ||
const actualOutputFile = explicitOutputFile || implicitOutputFile; | ||
switch (operation) { | ||
case "badness-metrics": | ||
await badnessMetrics.process( | ||
codeqlPath, | ||
await makeSummaryLogFile("predicates"), | ||
actualOutputFile, | ||
); | ||
break; | ||
case "expensive-predicates": | ||
await expensivePredicates.process( | ||
codeqlPath, | ||
await makeSummaryLogFile("overall"), | ||
actualOutputFile, | ||
); | ||
break; | ||
case "overall-summary": | ||
await logSummary.process( | ||
codeqlPath, | ||
logPath, | ||
actualOutputFile, | ||
"overall", | ||
); | ||
break; | ||
case "predicates-summary": { | ||
await logSummary.process( | ||
codeqlPath, | ||
logPath, | ||
actualOutputFile, | ||
"predicates", | ||
); | ||
break; | ||
} | ||
case "text-summary": { | ||
await logSummary.process(codeqlPath, logPath, actualOutputFile, "text"); | ||
break; | ||
} | ||
case "stage-timings": | ||
await stageTimings.process( | ||
codeqlPath, | ||
await makeSummaryLogFile("predicates"), | ||
actualOutputFile, | ||
); | ||
break; | ||
case "tuple-sums": | ||
await tupleSums.process( | ||
codeqlPath, | ||
await makeSummaryLogFile("predicates"), | ||
actualOutputFile, | ||
); | ||
break; | ||
default: | ||
throw new Error(`Unknown operation: ${operation}.\n\n${usage}`); | ||
} | ||
if (verbose) { | ||
createReadStream(actualOutputFile).pipe(process.stdout); | ||
} | ||
if (explicitOutputFile) { | ||
cpSync(actualOutputFile, explicitOutputFile); | ||
} | ||
log(`Output is available in ${actualOutputFile}.`); | ||
} | ||
void main(process.argv.slice(2)); |
6 changes: 6 additions & 0 deletions
6
extensions/ql-vscode/src/log-insights/core/log-processors/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# log-insights/core/log-processors | ||
|
||
This directory contains the log top-level log processors. | ||
They will generally read and write files on disk with their exported `process` function, possibly making use of on-disk caches to speed up processing. | ||
|
||
The files might expose additional functions for testing purposes, as well as in-memory variations of the top-level `process` function. |
Oops, something went wrong.