-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.ts
More file actions
83 lines (68 loc) · 2.5 KB
/
index.ts
File metadata and controls
83 lines (68 loc) · 2.5 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { checkV8Flags } from "./introspection";
import { MongoMeasurement } from "./mongoMeasurement";
import native_core from "./native_core";
declare const __VERSION__: string;
const linuxPerf = new native_core.LinuxPerf();
export const isBound = native_core.isBound;
export const mongoMeasurement = new MongoMeasurement();
type CodSpeedRunnerMode = "disabled" | "simulation" | "memory" | "walltime";
type InstrumentMode = "disabled" | "analysis" | "walltime";
export function getCodspeedRunnerMode(): CodSpeedRunnerMode {
const isCodSpeedEnabled = process.env.CODSPEED_ENV !== undefined;
if (!isCodSpeedEnabled) {
return "disabled";
}
// If CODSPEED_ENV is set, check CODSPEED_RUNNER_MODE
const codspeedRunnerMode = process.env.CODSPEED_RUNNER_MODE;
if (
codspeedRunnerMode === "instrumentation" ||
codspeedRunnerMode === "simulation"
) {
return "simulation";
} else if (codspeedRunnerMode === "memory") {
return "memory";
} else if (codspeedRunnerMode === "walltime") {
return "walltime";
}
console.warn(
`Unknown codspeed runner mode: ${codspeedRunnerMode}, defaulting to disabled`
);
return "disabled";
}
export function getInstrumentMode(): InstrumentMode {
const runnerMode = getCodspeedRunnerMode();
// Both "simulation" and "memory" map to "analysis" instrument mode
if (runnerMode === "simulation" || runnerMode === "memory") {
return "analysis";
}
return runnerMode; // "disabled" or "walltime"
}
export const setupCore = () => {
if (!native_core.isBound) {
throw new Error(
"Native core module is not bound, CodSpeed integration will not work properly"
);
}
native_core.InstrumentHooks.setIntegration("codspeed-node", __VERSION__);
linuxPerf.start();
checkV8Flags();
// Collect Node.js runtime environment to detect changes that could
// cause performance differences across runs
const hooks = native_core.InstrumentHooks;
hooks.setEnvironment("nodejs", "version", process.versions.node);
hooks.setEnvironment("nodejs", "v8", process.versions.v8);
hooks.writeEnvironment(process.pid);
};
export const teardownCore = () => {
linuxPerf.stop();
};
export type {
SetupInstrumentsRequestBody,
SetupInstrumentsResponse,
} from "./generated/openapi";
export { getV8Flags, tryIntrospect } from "./introspection";
export { optimizeFunction, optimizeFunctionSync } from "./optimization";
export * from "./utils";
export * from "./walltime";
export type { InstrumentMode };
export const InstrumentHooks = native_core.InstrumentHooks;