File tree Expand file tree Collapse file tree 1 file changed +10
-23
lines changed Expand file tree Collapse file tree 1 file changed +10
-23
lines changed Original file line number Diff line number Diff line change 1
1
import { writeFile } from "node:fs/promises" ;
2
- import { Session } from "node:inspector" ;
2
+ import { Session } from "node:inspector/promises " ;
3
3
4
4
let session ;
5
5
let processSignals ;
@@ -10,15 +10,10 @@ export async function start() {
10
10
}
11
11
session = new Session ( ) ;
12
12
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 ( ) ;
22
17
}
23
18
24
19
async function writeProfile ( profile ) {
@@ -46,23 +41,15 @@ export async function stop() {
46
41
if ( ! session ) {
47
42
return ;
48
43
}
44
+ const { profile} = await session . post ( "Profiler.stop" ) ;
45
+ session = null ;
46
+ if ( profile ) {
47
+ await writeProfile ( profile ) ;
48
+ }
49
49
if ( processSignals ) {
50
50
deregisterSigHooks ( processSignals ) ;
51
51
processSignals = null ;
52
52
}
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
- }
66
53
}
67
54
68
55
function registerSigHooks ( ) {
You can’t perform that action at this time.
0 commit comments