(cb?: () => void)
| 56 | } |
| 57 | |
| 58 | const stopProfiling = (cb?: () => void) => { |
| 59 | if (state !== 'profiling') { |
| 60 | cb?.() |
| 61 | return |
| 62 | } |
| 63 | |
| 64 | setState('stopping') |
| 65 | session.post('Profiler.stop', (err, params) => { |
| 66 | setState('idle') |
| 67 | |
| 68 | if (err) { |
| 69 | logger.error('cpu-prof', err) |
| 70 | cb?.() |
| 71 | return |
| 72 | } |
| 73 | |
| 74 | if (!params?.profile) { |
| 75 | cb?.() |
| 76 | return |
| 77 | } |
| 78 | |
| 79 | const date = new Date() |
| 80 | const timestamp = date.toISOString().replace(/[-:.]/g, '') |
| 81 | const title = `panda-${prefix}-${timestamp}` |
| 82 | |
| 83 | const outfile = path.join(cwd, `${title}.cpuprofile`) |
| 84 | fs.writeFileSync(outfile, JSON.stringify(params.profile)) |
| 85 | logger.info('cpu-prof', outfile) |
| 86 | cb?.() |
| 87 | }) |
| 88 | } |
| 89 | |
| 90 | return stopProfiling |
| 91 | } |
no test coverage detected