Skip to content

Commit

Permalink
Update to latest pprof dep, node 14
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Jan 23, 2024
1 parent 414e930 commit c454ec0
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 184 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-wombats-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"pprof-it": major
---

Update pprof dependency, fixing many things
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@
"unicorn/switch-case-braces": 0,
"unicorn/prefer-string-replace-all": 0, // Bad suggestion for old targets
"unicorn/prefer-module": 0,
"unicorn/no-process-exit": 0,
"unicorn/prefer-node-protocol": 0 // cjs
"unicorn/no-process-exit": 0
},
"ignorePatterns": ["**/dist/**", "**/node_modules/**", "bin/**", "coverage/**"]
}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [12, 14, 16, 18, 20]
node-version: [14, 16, 18, 20]
runs-on: ${{ matrix.os }}
env:
OS: ${{ matrix.os }}
Expand Down
231 changes: 69 additions & 162 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Jake Bailey",
"license": "MIT",
"engines": {
"node": ">=12.0.0"
"node": ">=14"
},
"bin": "dist/main.js",
"main": "dist/index.js",
Expand All @@ -21,14 +21,14 @@
"prepack": "rimraf dist && npm run build"
},
"dependencies": {
"@datadog/pprof": "^2.2.3",
"foreground-child": "^2.0.0",
"@datadog/pprof": "^5.0.0",
"foreground-child": "^3.1.1",
"pprof-format": "^2.0.7",
"signal-exit": "^3.0.7"
"signal-exit": "^4.1.0"
},
"devDependencies": {
"@changesets/cli": "^2.27.1",
"@tsconfig/node12": "^12.1.0",
"@tsconfig/node14": "^14.1.0",
"@types/foreground-child": "^2.0.2",
"@types/node": "^18.19.8",
"@types/signal-exit": "^3.0.4",
Expand Down
52 changes: 40 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ if (!isPreloading()) {
exitError("pprof-it must be required using the --require flag");
}

import assert from "node:assert";
import fs from "node:fs";
import path from "node:path";
import { isMainThread } from "node:worker_threads";

import * as pprof from "@datadog/pprof";
import assert from "assert";
import fs from "fs";
import path from "path";
import { serializeTimeProfile } from "@datadog/pprof/out/src/profile-serializer";
import { TimeProfilerOptions } from "@datadog/pprof/out/src/time-profiler";
import { TimeProfiler as PProfTimeProfiler } from "@datadog/pprof/out/src/time-profiler-bindings";
import { Profile } from "pprof-format";
import signalExit from "signal-exit";

Expand Down Expand Up @@ -234,25 +239,48 @@ class HeapProfiler extends Profiler {
}
}

const DEFAULT_INTERVAL_MICROS = 1000;
const DEFAULT_DURATION_MILLIS = 60_000;

const DEFAULT_OPTIONS: TimeProfilerOptions = {
durationMillis: DEFAULT_DURATION_MILLIS,
intervalMicros: DEFAULT_INTERVAL_MICROS,
lineNumbers: false,
withContexts: false,
workaroundV8Bug: true,
collectCpuTime: false,
};

class TimeProfiler extends Profiler {
private _stopFn?: () => Profile;
private _timeProfiler: typeof PProfTimeProfiler;

constructor() {
super(ProfilerName.Time, Options.timeOut);
}

start(): void {
this._stopFn = pprof.time.start(
Options.timeInterval,
/* name */ undefined,
/* sourceMapper */ undefined,
Options.lineNumbers,
);
const options: TimeProfilerOptions = {
...DEFAULT_OPTIONS,
intervalMicros: Options.timeInterval,
lineNumbers: Options.lineNumbers,
};

this._timeProfiler = new PProfTimeProfiler({ ...options, isMainThread });
this._timeProfiler.start();
}

protected _stop(): Profile {
assert(this._stopFn);
return this._stopFn();
const profile = this._timeProfiler.stop(false);

const serialized_profile = serializeTimeProfile(
profile,
Options.timeInterval,
/*gSourceMapper*/ undefined,
true,
/*generateLabels*/ undefined,
);

return serialized_profile;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node
import path from "node:path";

import foregroundChild from "foreground-child";
import path from "path";

const args = [...process.execArgv, `--require=${path.join(__dirname, "index.js")}`, ...process.argv.slice(2)];

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@tsconfig/node12/tsconfig.json",
"extends": "@tsconfig/node14/tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"declaration": true,
Expand Down

0 comments on commit c454ec0

Please sign in to comment.