Skip to content

Commit 2cc1a76

Browse files
committed
[INTERNAL] Use promise inspector API
Available since Node v19
1 parent b1dae76 commit 2cc1a76

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

lib/utils/profile.js

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {writeFile} from "node:fs/promises";
2-
import {Session} from "node:inspector";
2+
import {Session} from "node:inspector/promises";
33

44
let session;
55
let processSignals;
@@ -10,15 +10,10 @@ export async function start() {
1010
}
1111
session = new Session();
1212
session.connect();
13-
await new Promise((resolve) => {
14-
session.post("Profiler.enable", () => {
15-
console.log(`Recording CPU profile...`);
16-
session.post("Profiler.start", () => {
17-
processSignals = registerSigHooks();
18-
resolve();
19-
});
20-
});
21-
});
13+
await session.post("Profiler.enable");
14+
await session.post("Profiler.start");
15+
console.log(`Recording CPU profile...`);
16+
processSignals = registerSigHooks();
2217
}
2318

2419
async function writeProfile(profile) {
@@ -46,23 +41,15 @@ export async function stop() {
4641
if (!session) {
4742
return;
4843
}
44+
const {profile} = await session.post("Profiler.stop");
45+
session = null;
46+
if (profile) {
47+
await writeProfile(profile);
48+
}
4949
if (processSignals) {
5050
deregisterSigHooks(processSignals);
5151
processSignals = null;
5252
}
53-
const profile = await new Promise((resolve) => {
54-
session.post("Profiler.stop", (err, {profile}) => {
55-
if (err) {
56-
resolve(null);
57-
} else {
58-
resolve(profile);
59-
}
60-
});
61-
session = null;
62-
});
63-
if (profile) {
64-
await writeProfile(profile);
65-
}
6653
}
6754

6855
function registerSigHooks() {

0 commit comments

Comments
 (0)