Skip to content

Commit 11a0fb5

Browse files
committed
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.
1 parent f7caf01 commit 11a0fb5

File tree

15 files changed

+2268
-0
lines changed

15 files changed

+2268
-0
lines changed

extensions/ql-vscode/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ql-vscode/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,7 @@
19951995
"d3": "^7.9.0",
19961996
"d3-graphviz": "^5.0.2",
19971997
"fs-extra": "^11.1.1",
1998+
"immutable": "^5.0.2",
19981999
"js-yaml": "^4.1.0",
19992000
"msw": "^2.2.13",
20002001
"nanoid": "^5.0.7",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# log-insights/core
2+
3+
The core of the `log-insights` feature: provides insights from the raw logs emitted by the CodeQL CLI.
4+
5+
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.
6+
The unit tests for this directory define the interface, and there are no guarantees about external compatibility beyond that.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import { cpSync, createReadStream, mkdtempSync } from "fs";
2+
import { join } from "path";
3+
// eslint-disable-next-line import/no-namespace
4+
import * as badnessMetrics from "./log-processors/badness-metrics";
5+
// eslint-disable-next-line import/no-namespace
6+
import * as expensivePredicates from "./log-processors/expensive-predicates";
7+
// eslint-disable-next-line import/no-namespace
8+
import * as logSummary from "./log-processors/log-summary";
9+
// eslint-disable-next-line import/no-namespace
10+
import * as stageTimings from "./log-processors/stage-timings";
11+
// eslint-disable-next-line import/no-namespace
12+
import * as tupleSums from "./log-processors/tuple-sums";
13+
import { log } from "./util";
14+
15+
/**
16+
* Minimal CLI interface for running the evaluator log processing locally.
17+
*
18+
* Intended for use in development and debugging.
19+
* This is not intended to be a full-featured CLI tool, nor as a replacement for ordinary testing.
20+
*
21+
* Sample use:
22+
*
23+
* ```
24+
* $ ts-node cli.ts badness-metrics codeql ~/Downloads/codeql-evaluator-log.json
25+
* ```
26+
*/
27+
async function main(args: string[]) {
28+
const positionals = args.filter((arg) => !arg.startsWith("--"));
29+
const [operation, codeqlPath, logPath] = positionals;
30+
const options = args.filter((arg) => arg.startsWith("--"));
31+
const verbose = options.includes("--verbose");
32+
const explicitOutputFile = options
33+
.find((arg) => arg.startsWith("--output="))
34+
?.split("=")[1];
35+
const help = options.includes("--help");
36+
// dear future reader. Please consider using a proper CLI library instead of this ad hoc parsing.
37+
const usage = [
38+
"Usage: cli <badness-metrics|expensive-predicates|overall-summary|predicates-summary|stage-timings|tuple-sums> <codeql-path> <summary-log-path> [--verbose] [--output=<output-file>]",
39+
].join("\n");
40+
41+
if (help) {
42+
console.log(usage);
43+
return;
44+
}
45+
if (!operation || !codeqlPath || !logPath) {
46+
throw new Error(`Missing arguments.\n\n${usage}`);
47+
}
48+
async function makeSummaryLogFile(format: "overall" | "predicates") {
49+
const summaryLogFile = `${logPath}.${format}.log`;
50+
await logSummary.process(codeqlPath, logPath, summaryLogFile, format);
51+
return summaryLogFile;
52+
}
53+
54+
const implicitOutputFile = join(
55+
mkdtempSync("log-insights-"),
56+
"implicit-output.txt",
57+
);
58+
const actualOutputFile = explicitOutputFile || implicitOutputFile;
59+
switch (operation) {
60+
case "badness-metrics":
61+
await badnessMetrics.process(
62+
codeqlPath,
63+
await makeSummaryLogFile("predicates"),
64+
actualOutputFile,
65+
);
66+
break;
67+
case "expensive-predicates":
68+
await expensivePredicates.process(
69+
codeqlPath,
70+
await makeSummaryLogFile("overall"),
71+
actualOutputFile,
72+
);
73+
break;
74+
case "overall-summary":
75+
await logSummary.process(
76+
codeqlPath,
77+
logPath,
78+
actualOutputFile,
79+
"overall",
80+
);
81+
break;
82+
case "predicates-summary": {
83+
await logSummary.process(
84+
codeqlPath,
85+
logPath,
86+
actualOutputFile,
87+
"predicates",
88+
);
89+
break;
90+
}
91+
case "text-summary": {
92+
await logSummary.process(codeqlPath, logPath, actualOutputFile, "text");
93+
break;
94+
}
95+
case "stage-timings":
96+
await stageTimings.process(
97+
codeqlPath,
98+
await makeSummaryLogFile("predicates"),
99+
actualOutputFile,
100+
);
101+
break;
102+
case "tuple-sums":
103+
await tupleSums.process(
104+
codeqlPath,
105+
await makeSummaryLogFile("predicates"),
106+
actualOutputFile,
107+
);
108+
break;
109+
default:
110+
throw new Error(`Unknown operation: ${operation}.\n\n${usage}`);
111+
}
112+
if (verbose) {
113+
createReadStream(actualOutputFile).pipe(process.stdout);
114+
}
115+
if (explicitOutputFile) {
116+
cpSync(actualOutputFile, explicitOutputFile);
117+
}
118+
log(`Output is available in ${actualOutputFile}.`);
119+
}
120+
void main(process.argv.slice(2));
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# log-insights/core/log-processors
2+
3+
This directory contains the log top-level log processors.
4+
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.
5+
6+
The files might expose additional functions for testing purposes, as well as in-memory variations of the top-level `process` function.

0 commit comments

Comments
 (0)