MCPcopy Index your code
hub / github.com/react/react / startProfiling

Function startProfiling

packages/react-devtools-shared/src/backend/fiber/renderer.js:7624–7666  ·  view source on GitHub ↗
(
    shouldRecordChangeDescriptions: boolean,
    shouldRecordTimeline: boolean,
  )

Source from the content-addressed store, hash-verified

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;

Callers 1

attachFunction · 0.70

Calls 7

getDisplayNameForRootFunction · 0.85
toggleProfilingStatusFunction · 0.85
setMethod · 0.80
forEachMethod · 0.65
getMethod · 0.65
getCurrentTimeFunction · 0.50

Tested by

no test coverage detected