(
shouldRecordChangeDescriptions: boolean,
shouldRecordTimeline: boolean,
)
| 7622 | } |
| 7623 | |
| 7624 | function startProfiling( |
| 7625 | shouldRecordChangeDescriptions: boolean, |
| 7626 | shouldRecordTimeline: boolean, |
| 7627 | ) { |
| 7628 | if (isProfiling) { |
| 7629 | return; |
| 7630 | } |
| 7631 | |
| 7632 | recordChangeDescriptions = shouldRecordChangeDescriptions; |
| 7633 | recordTimeline = shouldRecordTimeline; |
| 7634 | |
| 7635 | // Capture initial values as of the time profiling starts. |
| 7636 | // It's important we snapshot both the durations and the id-to-root map, |
| 7637 | // since either of these may change during the profiling session |
| 7638 | // (e.g. when a fiber is re-rendered or when a fiber gets removed). |
| 7639 | displayNamesByRootID = new Map(); |
| 7640 | initialTreeBaseDurationsMap = new Map(); |
| 7641 | |
| 7642 | hook.getFiberRoots(rendererID).forEach(root => { |
| 7643 | const rootInstance = rootToFiberInstanceMap.get(root); |
| 7644 | if (rootInstance === undefined) { |
| 7645 | throw new Error( |
| 7646 | 'Expected the root instance to already exist when starting profiling', |
| 7647 | ); |
| 7648 | } |
| 7649 | const rootID = rootInstance.id; |
| 7650 | ((displayNamesByRootID: any): DisplayNamesByRootID).set( |
| 7651 | rootID, |
| 7652 | getDisplayNameForRoot(root.current), |
| 7653 | ); |
| 7654 | const initialTreeBaseDurations: Array<[number, number]> = []; |
| 7655 | snapshotTreeBaseDurations(rootInstance, initialTreeBaseDurations); |
| 7656 | (initialTreeBaseDurationsMap: any).set(rootID, initialTreeBaseDurations); |
| 7657 | }); |
| 7658 | |
| 7659 | isProfiling = true; |
| 7660 | profilingStartTime = getCurrentTime(); |
| 7661 | rootToCommitProfilingMetadataMap = new Map(); |
| 7662 | |
| 7663 | if (toggleProfilingStatus !== null) { |
| 7664 | toggleProfilingStatus(true, recordTimeline); |
| 7665 | } |
| 7666 | } |
| 7667 | |
| 7668 | function stopProfiling() { |
| 7669 | isProfiling = false; |
no test coverage detected