Skip to content

Commit 008953e

Browse files
committed
feat: log process pid only when CODSPEED_DEBUG is set
1 parent 4e3002b commit 008953e

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

packages/benchmark.js-plugin/benches/sample.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { logDebug } from "@codspeed/core";
12
import Benchmark from "benchmark";
23
import { withCodSpeed } from "..";
34
import parsePr from "./parsePr";
@@ -11,7 +12,7 @@ const LONG_BODY =
1112

1213
const suite = withCodSpeed(new Benchmark.Suite());
1314

14-
console.log(`PROCESS PID: ${process.pid} in ${__filename}`);
15+
logDebug(`PROCESS PID: ${process.pid} in ${__filename}`);
1516

1617
suite
1718
.add("RegExp#test", function () {

packages/core/src/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@ export function getGitDir(path: string): string | undefined {
88
} as FindupOptions);
99
return dotGitPath ? dirname(dotGitPath) : undefined;
1010
}
11+
12+
/**
13+
* Log debug messages if the environment variable `CODSPEED_DEBUG` is set.
14+
*/
15+
export function logDebug(...args: unknown[]) {
16+
if (process.env.CODSPEED_DEBUG) {
17+
console.log(...args);
18+
}
19+
}

packages/tinybench-plugin/benches/sample.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { logDebug } from "@codspeed/core";
12
import { Bench } from "tinybench";
23
import { withCodSpeed } from "..";
34
import parsePr from "./parsePr";
@@ -11,7 +12,7 @@ const LONG_BODY =
1112

1213
const bench = withCodSpeed(new Bench({ time: 100 }));
1314

14-
console.log(`PROCESS PID: ${process.pid} in ${__filename}`);
15+
logDebug(`PROCESS PID: ${process.pid} in ${__filename}`);
1516

1617
bench
1718
.add("switch 1", () => {

packages/vitest-plugin/src/runner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
getGitDir,
3+
logDebug,
34
Measurement,
45
optimizeFunction,
56
setupCore,
@@ -66,7 +67,7 @@ function patchRootSuiteWithFullFilePath(suite: Suite) {
6667

6768
class CodSpeedRunner extends NodeBenchmarkRunner {
6869
async runSuite(suite: Suite): Promise<void> {
69-
logCodSpeed(`PROCESS PID: ${process.pid} in ${__filename}`);
70+
logDebug(`PROCESS PID: ${process.pid} in ${__filename}`);
7071
setupCore();
7172

7273
patchRootSuiteWithFullFilePath(suite);

0 commit comments

Comments
 (0)