(filename = 'node.heapsnapshot')
| 1042 | }, |
| 1043 | |
| 1044 | takeHeapSnapshot(filename = 'node.heapsnapshot') { |
| 1045 | if (heapSnapshotPromise) { |
| 1046 | print( |
| 1047 | 'Cannot take heap snapshot because another snapshot is in progress.', |
| 1048 | ); |
| 1049 | return heapSnapshotPromise; |
| 1050 | } |
| 1051 | heapSnapshotPromise = new Promise((resolve, reject) => { |
| 1052 | const absoluteFile = Path.resolve(filename); |
| 1053 | const writer = FS.createWriteStream(absoluteFile); |
| 1054 | let sizeWritten = 0; |
| 1055 | function onProgress({ done, total, finished }) { |
| 1056 | if (finished) { |
| 1057 | print('Heap snapshot prepared.'); |
| 1058 | } else { |
| 1059 | print(`Heap snapshot: ${done}/${total}`, false); |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | function onChunk({ chunk }) { |
| 1064 | sizeWritten += chunk.length; |
| 1065 | writer.write(chunk); |
| 1066 | print(`Writing snapshot: ${sizeWritten}`, false); |
| 1067 | } |
| 1068 | |
| 1069 | function onResolve() { |
| 1070 | writer.end(() => { |
| 1071 | teardown(); |
| 1072 | print(`Wrote snapshot: ${absoluteFile}`); |
| 1073 | heapSnapshotPromise = null; |
| 1074 | resolve(); |
| 1075 | }); |
| 1076 | } |
| 1077 | |
| 1078 | function onReject(error) { |
| 1079 | teardown(); |
| 1080 | reject(error); |
| 1081 | } |
| 1082 | |
| 1083 | function teardown() { |
| 1084 | HeapProfiler.removeListener( |
| 1085 | 'reportHeapSnapshotProgress', onProgress); |
| 1086 | HeapProfiler.removeListener('addHeapSnapshotChunk', onChunk); |
| 1087 | } |
| 1088 | |
| 1089 | HeapProfiler.on('reportHeapSnapshotProgress', onProgress); |
| 1090 | HeapProfiler.on('addHeapSnapshotChunk', onChunk); |
| 1091 | |
| 1092 | print('Heap snapshot: 0/0', false); |
| 1093 | PromisePrototypeThen( |
| 1094 | HeapProfiler.takeHeapSnapshot({ reportProgress: true }), |
| 1095 | onResolve, onReject); |
| 1096 | }); |
| 1097 | return heapSnapshotPromise; |
| 1098 | }, |
| 1099 | |
| 1100 | get watchers() { |
| 1101 | return watchers(); |
nothing calls this directly
no test coverage detected