Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"**/dist/**",
"**/node_modules/**",
"**/rollup.config.ts",
"**/jest.config.js"
"**/jest.config.js",
"packages/core/src/native_core/instruments/hooks/**"
],
"settings": {
"import/parsers": {
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ jobs:
- uses: "actions/checkout@v4"
with:
fetch-depth: 0
- name: Install valgrind
run: |
sudo apt-get update
sudo apt-get install -y valgrind
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
Expand All @@ -32,6 +29,9 @@ jobs:
examples: ${{ steps.list-examples.outputs.examples }}
steps:
- uses: "actions/checkout@v4"
with:
fetch-depth: 0
submodules: true
# list the directories in ./examples and output them to a github action workflow variables as a JSON array
- run: |
examples=$(find ./examples -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | jq -R -s -c 'split("\n") | map(select(length > 0))')
Expand All @@ -51,10 +51,7 @@ jobs:
- uses: "actions/checkout@v4"
with:
fetch-depth: 0
- name: Install valgrind
run: |
sudo apt-get update
sudo apt-get install -y valgrind
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ jobs:
- uses: "actions/checkout@v4"
with:
fetch-depth: 0
- name: Install valgrind
run: |
sudo apt-get update
sudo apt-get install -y valgrind
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
Expand All @@ -43,10 +40,7 @@ jobs:
- uses: "actions/checkout@v4"
with:
fetch-depth: 0
- name: Install valgrind
run: |
sudo apt-get update
sudo apt-get install -y valgrind
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
cache: pnpm
node-version-file: .nvmrc
registry-url: "https://registry.npmjs.org"
- run: pnpm install --frozen-lockfile --prefer-offline
- name: Install valgrind
run: |
sudo apt-get update
sudo apt-get install -y valgrind

- name: Build the libraries
run: pnpm moon run :build

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "packages/core/src/native_core/instruments/hooks"]
path = packages/core/src/native_core/instruments/hooks
url = git@github.com:CodSpeedHQ/instrument-hooks.git
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
.rollup.cache
dist
generated
packages/core/src/native_core/instruments/hooks
1 change: 0 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
setuptools
]
))
valgrind # TODO: Remove this in favor of codspeed's valgrind
];

in
Expand Down
6 changes: 4 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"npmClient": "pnpm",
"useWorkspaces": true,
"packages": ["packages/*"],
"packages": [
"packages/*"
],
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "4.0.1"
"version": "5.0.0"
}
4 changes: 2 additions & 2 deletions packages/benchmark.js-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codspeed/benchmark.js-plugin",
"version": "4.0.1",
"version": "5.0.0",
"description": "Benchmark.js compatibility layer for CodSpeed",
"keywords": [
"codspeed",
Expand All @@ -27,7 +27,7 @@
"jest-mock-extended": "^3.0.4"
},
"dependencies": {
"@codspeed/core": "workspace:^4.0.1",
"@codspeed/core": "workspace:^5.0.0",
"lodash": "^4.17.10",
"stack-trace": "1.0.0-pre2"
},
Expand Down
18 changes: 10 additions & 8 deletions packages/benchmark.js-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Measurement,
InstrumentHooks,
mongoMeasurement,
optimizeFunction,
optimizeFunctionSync,
Expand Down Expand Up @@ -90,7 +90,7 @@ export function withCodSpeed(item: unknown): unknown {
}

function withCodSpeedBenchmark(bench: Benchmark): WithCodSpeedBenchmark {
if (!Measurement.isInstrumented()) {
if (!InstrumentHooks.isInstrumented()) {
const rawRun = bench.run;
bench.run = (options?: Benchmark.Options) => {
console.warn(
Expand Down Expand Up @@ -120,7 +120,7 @@ function withCodSpeedBenchmark(bench: Benchmark): WithCodSpeedBenchmark {
}

function withCodSpeedSuite(suite: Benchmark.Suite): WithCodSpeedSuite {
if (!Measurement.isInstrumented()) {
if (!InstrumentHooks.isInstrumented()) {
const rawRun = suite.run;
suite.run = (options?: Benchmark.Options) => {
console.warn(
Expand Down Expand Up @@ -198,18 +198,20 @@ async function runBenchmarks({
await mongoMeasurement.start(uri);
global.gc?.();
await (async function __codspeed_root_frame__() {
Measurement.startInstrumentation();
InstrumentHooks.startBenchmark();
await benchPayload();
Measurement.stopInstrumentation(uri);
InstrumentHooks.stopBenchmark();
InstrumentHooks.setExecutedBenchmark(process.pid, uri);
})();
await mongoMeasurement.stop(uri);
} else {
optimizeFunctionSync(benchPayload);
await mongoMeasurement.start(uri);
(function __codspeed_root_frame__() {
Measurement.startInstrumentation();
InstrumentHooks.startBenchmark();
benchPayload();
Measurement.stopInstrumentation(uri);
InstrumentHooks.stopBenchmark();
InstrumentHooks.setExecutedBenchmark(process.pid, uri);
})();
await mongoMeasurement.stop(uri);
}
Expand All @@ -231,7 +233,7 @@ async function runBenchmarks({
export async function setupInstruments(
body: SetupInstrumentsRequestBody
): Promise<SetupInstrumentsResponse> {
if (!Measurement.isInstrumented()) {
if (!InstrumentHooks.isInstrumented()) {
console.warn("[CodSpeed] No instrumentation found, using default mongoUrl");

return { remoteAddr: body.mongoUrl };
Expand Down
76 changes: 47 additions & 29 deletions packages/benchmark.js-plugin/tests/index.integ.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const benchOptions: Benchmark.Options = {

describe("Benchmark", () => {
it("simple benchmark", async () => {
mockCore.Measurement.isInstrumented.mockReturnValue(false);
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(false);
const bench = withCodSpeed(
new Benchmark(
"RegExp",
Expand All @@ -37,11 +37,14 @@ describe("Benchmark", () => {
bench.on("complete", onComplete);
await bench.run();
expect(onComplete).toHaveBeenCalled();
expect(mockCore.Measurement.startInstrumentation).not.toHaveBeenCalled();
expect(mockCore.Measurement.stopInstrumentation).not.toHaveBeenCalled();
expect(mockCore.InstrumentHooks.startBenchmark).not.toHaveBeenCalled();
expect(mockCore.InstrumentHooks.stopBenchmark).not.toHaveBeenCalled();
expect(
mockCore.InstrumentHooks.setExecutedBenchmark
).not.toHaveBeenCalled();
});
it("check core methods are called", async () => {
mockCore.Measurement.isInstrumented.mockReturnValue(true);
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(true);

const bench = withCodSpeed(
new Benchmark(
Expand All @@ -56,13 +59,15 @@ describe("Benchmark", () => {
bench.on("complete", onComplete);
await bench.run();
expect(onComplete).toHaveBeenCalled();
expect(mockCore.Measurement.startInstrumentation).toHaveBeenCalled();
expect(mockCore.Measurement.stopInstrumentation).toHaveBeenCalledWith(
expect(mockCore.InstrumentHooks.startBenchmark).toHaveBeenCalled();
expect(mockCore.InstrumentHooks.stopBenchmark).toHaveBeenCalled();
expect(mockCore.InstrumentHooks.setExecutedBenchmark).toHaveBeenCalledWith(
process.pid,
"packages/benchmark.js-plugin/tests/index.integ.test.ts::RegExpSingle"
);
});
it("check error handling", async () => {
mockCore.Measurement.isInstrumented.mockReturnValue(true);
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(true);
const bench = withCodSpeed(
new Benchmark(
"throwing",
Expand All @@ -79,7 +84,7 @@ describe("Benchmark", () => {
async (instrumented) => {
const logSpy = jest.spyOn(console, "log");
const warnSpy = jest.spyOn(console, "warn");
mockCore.Measurement.isInstrumented.mockReturnValue(instrumented);
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(instrumented);
await withCodSpeed(
new Benchmark(
"RegExpSingle",
Expand Down Expand Up @@ -108,7 +113,7 @@ describe("Benchmark", () => {
}
);
it("should call setup and teardown", async () => {
mockCore.Measurement.isInstrumented.mockReturnValue(true);
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(true);
const setup = jest.fn();
const teardown = jest.fn();
const bench = withCodSpeed(
Expand All @@ -128,7 +133,7 @@ describe("Benchmark", () => {

describe("Benchmark.Suite", () => {
it("simple suite", async () => {
mockCore.Measurement.isInstrumented.mockReturnValue(false);
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(false);
const suite = withCodSpeed(new Benchmark.Suite());
suite.add(
"RegExp",
Expand All @@ -141,11 +146,14 @@ describe("Benchmark.Suite", () => {
suite.on("complete", onComplete);
await suite.run({ maxTime: 0.1, initCount: 1 });
expect(onComplete).toHaveBeenCalled();
expect(mockCore.Measurement.startInstrumentation).not.toHaveBeenCalled();
expect(mockCore.Measurement.stopInstrumentation).not.toHaveBeenCalled();
expect(mockCore.InstrumentHooks.startBenchmark).not.toHaveBeenCalled();
expect(mockCore.InstrumentHooks.stopBenchmark).not.toHaveBeenCalled();
expect(
mockCore.InstrumentHooks.setExecutedBenchmark
).not.toHaveBeenCalled();
});
it("check core methods are called", async () => {
mockCore.Measurement.isInstrumented.mockReturnValue(true);
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(true);
const suite = withCodSpeed(new Benchmark.Suite()).add(
"RegExp",
function () {
Expand All @@ -156,13 +164,15 @@ describe("Benchmark.Suite", () => {
const onComplete = jest.fn();
suite.on("complete", onComplete);
await suite.run({ maxTime: 0.1, initCount: 1 });
expect(mockCore.Measurement.startInstrumentation).toHaveBeenCalled();
expect(mockCore.Measurement.stopInstrumentation).toHaveBeenCalledWith(
expect(mockCore.InstrumentHooks.startBenchmark).toHaveBeenCalled();
expect(mockCore.InstrumentHooks.stopBenchmark).toHaveBeenCalled();
expect(mockCore.InstrumentHooks.setExecutedBenchmark).toHaveBeenCalledWith(
process.pid,
"packages/benchmark.js-plugin/tests/index.integ.test.ts::RegExp"
);
});
it("check suite name is in the uri", async () => {
mockCore.Measurement.isInstrumented.mockReturnValue(true);
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(true);
await withCodSpeed(new Benchmark.Suite("thesuite"))
.add(
"RegExp",
Expand All @@ -175,15 +185,18 @@ describe("Benchmark.Suite", () => {
/o/.test("Hello World!");
}, benchOptions)
.run();
expect(mockCore.Measurement.stopInstrumentation).toHaveBeenCalledWith(
expect(mockCore.InstrumentHooks.stopBenchmark).toHaveBeenCalledTimes(2);
expect(mockCore.InstrumentHooks.setExecutedBenchmark).toHaveBeenCalledWith(
process.pid,
"packages/benchmark.js-plugin/tests/index.integ.test.ts::thesuite::RegExp"
);
expect(mockCore.Measurement.stopInstrumentation).toHaveBeenCalledWith(
expect(mockCore.InstrumentHooks.setExecutedBenchmark).toHaveBeenCalledWith(
process.pid,
"packages/benchmark.js-plugin/tests/index.integ.test.ts::thesuite::unknown_1"
);
});
it("check error handling", async () => {
mockCore.Measurement.isInstrumented.mockReturnValue(true);
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(true);
const bench = withCodSpeed(new Benchmark.Suite("thesuite")).add(
"throwing",
() => {
Expand All @@ -197,7 +210,7 @@ describe("Benchmark.Suite", () => {
async (instrumented) => {
const logSpy = jest.spyOn(console, "log");
const warnSpy = jest.spyOn(console, "warn");
mockCore.Measurement.isInstrumented.mockReturnValue(instrumented);
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(instrumented);
await withCodSpeed(new Benchmark.Suite("thesuite"))
.add(
"RegExp",
Expand Down Expand Up @@ -229,35 +242,40 @@ describe("Benchmark.Suite", () => {
}
);
it("check nested file path is in the uri when bench is registered in another file", async () => {
mockCore.Measurement.isInstrumented.mockReturnValue(true);
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(true);
const suite = withCodSpeed(new Benchmark.Suite("thesuite"));
registerBenchmarks(suite);
const onComplete = jest.fn();
suite.on("complete", onComplete);
await suite.run({ maxTime: 0.1, initCount: 1 });
expect(mockCore.Measurement.startInstrumentation).toHaveBeenCalled();
expect(mockCore.Measurement.stopInstrumentation).toHaveBeenCalledWith(
expect(mockCore.InstrumentHooks.startBenchmark).toHaveBeenCalled();
expect(mockCore.InstrumentHooks.stopBenchmark).toHaveBeenCalled();
expect(mockCore.InstrumentHooks.setExecutedBenchmark).toHaveBeenCalledWith(
process.pid,
"packages/benchmark.js-plugin/tests/registerBenchmarks.ts::thesuite::RegExp"
);
});
it("check that benchmarks with same name have different URIs when registered in different files", async () => {
mockCore.Measurement.isInstrumented.mockReturnValue(true);
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(true);
const suite = withCodSpeed(new Benchmark.Suite("thesuite"));
registerBenchmarks(suite);
registerOtherBenchmarks(suite);
const onComplete = jest.fn();
suite.on("complete", onComplete);
await suite.run({ maxTime: 0.1, initCount: 1 });
expect(mockCore.Measurement.startInstrumentation).toHaveBeenCalled();
expect(mockCore.Measurement.stopInstrumentation).toHaveBeenCalledWith(
expect(mockCore.InstrumentHooks.startBenchmark).toHaveBeenCalled();
expect(mockCore.InstrumentHooks.stopBenchmark).toHaveBeenCalledTimes(2);
expect(mockCore.InstrumentHooks.setExecutedBenchmark).toHaveBeenCalledWith(
process.pid,
"packages/benchmark.js-plugin/tests/registerBenchmarks.ts::thesuite::RegExp"
);
expect(mockCore.Measurement.stopInstrumentation).toHaveBeenCalledWith(
expect(mockCore.InstrumentHooks.setExecutedBenchmark).toHaveBeenCalledWith(
process.pid,
"packages/benchmark.js-plugin/tests/registerOtherBenchmarks.ts::thesuite::RegExp"
);
});
it("should call setupCore and teardownCore only once after run()", async () => {
mockCore.Measurement.isInstrumented.mockReturnValue(true);
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(true);
const suite = withCodSpeed(new Benchmark.Suite("thesuite"));
registerBenchmarks(suite);
registerOtherBenchmarks(suite);
Expand All @@ -271,7 +289,7 @@ describe("Benchmark.Suite", () => {
expect(mockCore.teardownCore).toHaveBeenCalledTimes(1);
});
it("should call setup and teardown", async () => {
mockCore.Measurement.isInstrumented.mockReturnValue(true);
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(true);
const setup = jest.fn();
const teardown = jest.fn();

Expand Down
Loading
Loading