-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathintrospection.ts
More file actions
60 lines (53 loc) · 1.55 KB
/
introspection.ts
File metadata and controls
60 lines (53 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { writeFileSync } from "fs";
import { getCodspeedRunnerMode } from ".";
const CUSTOM_INTROSPECTION_EXIT_CODE = 0;
export const getV8Flags = () => {
const nodeVersionMajor = parseInt(process.version.slice(1).split(".")[0]);
const codspeedRunnerMode = getCodspeedRunnerMode();
const flags = ["--interpreted-frames-native-stack", "--allow-natives-syntax"];
if (codspeedRunnerMode === "simulation") {
flags.push(
...[
"--hash-seed=1",
"--random-seed=1",
"--no-opt",
"--predictable",
"--predictable-gc-schedule",
"--expose-gc",
"--no-concurrent-sweeping",
"--max-old-space-size=4096",
]
);
if (nodeVersionMajor < 18) {
flags.push("--no-randomize-hashes");
}
if (nodeVersionMajor < 20) {
flags.push("--no-scavenge-task");
}
}
return flags;
};
export const tryIntrospect = () => {
if (process.env.__CODSPEED_NODE_CORE_INTROSPECTION_PATH__ !== undefined) {
const introspectionMetadata = {
flags: getV8Flags(),
};
writeFileSync(
process.env.__CODSPEED_NODE_CORE_INTROSPECTION_PATH__,
JSON.stringify(introspectionMetadata)
);
process.exit(CUSTOM_INTROSPECTION_EXIT_CODE);
}
};
export const checkV8Flags = () => {
const requiredFlags = getV8Flags();
const actualFlags = process.execArgv;
const missingFlags = requiredFlags.filter(
(flag) => !actualFlags.includes(flag)
);
if (missingFlags.length > 0) {
console.warn(
`[CodSpeed] missing required flags: ${missingFlags.join(", ")}`
);
}
};