getChartData() — react Function Reference
Architecture documentation for the getChartData() function in FlamegraphChartBuilder.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD dce5bc8b_527d_16a9_6892_63dede170a19["getChartData()"] 9d7f3d0b_1959_a3f3_e24e_821787aa2f54["FlamegraphChartBuilder.js"] dce5bc8b_527d_16a9_6892_63dede170a19 -->|defined in| 9d7f3d0b_1959_a3f3_e24e_821787aa2f54 style dce5bc8b_527d_16a9_6892_63dede170a19 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/react-devtools-shared/src/devtools/views/Profiler/FlamegraphChartBuilder.js lines 37–196
export function getChartData({
commitIndex,
commitTree,
profilerStore,
rootID,
}: {
commitIndex: number,
commitTree: CommitTree,
profilerStore: ProfilerStore,
rootID: number,
}): ChartData {
const commitDatum = profilerStore.getCommitData(rootID, commitIndex);
const {fiberActualDurations, fiberSelfDurations} = commitDatum;
const {nodes} = commitTree;
const chartDataKey = `${rootID}-${commitIndex}`;
if (cachedChartData.has(chartDataKey)) {
return ((cachedChartData.get(chartDataKey): any): ChartData);
}
const idToDepthMap: Map<number, number> = new Map();
const renderPathNodes: Set<number> = new Set();
const rows: Array<Array<ChartNode>> = [];
let maxDepth = 0;
let maxSelfDuration = 0;
// Generate flame graph structure using tree base durations.
const walkTree = (
id: number,
rightOffset: number,
currentDepth: number,
): ChartNode => {
idToDepthMap.set(id, currentDepth);
const node = nodes.get(id);
if (node == null) {
throw Error(`Could not find node with id "${id}" in commit tree`);
}
const {
children,
displayName,
hocDisplayNames,
key,
treeBaseDuration,
compiledWithForget,
} = node;
const actualDuration = fiberActualDurations.get(id) || 0;
const selfDuration = fiberSelfDurations.get(id) || 0;
const didRender = fiberActualDurations.has(id);
const name = displayName || 'Anonymous';
const maybeKey = key !== null ? ` key="${key}"` : '';
let maybeBadge = '';
const maybeForgetBadge = compiledWithForget ? '✨ ' : '';
if (hocDisplayNames !== null && hocDisplayNames.length > 0) {
maybeBadge = ` (${hocDisplayNames[0]})`;
}
let label = `${maybeForgetBadge}${name}${maybeBadge}${maybeKey}`;
if (didRender) {
label += ` (${formatDuration(selfDuration)}ms of ${formatDuration(
actualDuration,
)}ms)`;
}
maxDepth = Math.max(maxDepth, currentDepth);
maxSelfDuration = Math.max(maxSelfDuration, selfDuration);
const chartNode: ChartNode = {
actualDuration,
didRender,
id,
label,
name,
offset: rightOffset - treeBaseDuration,
Domain
Subdomains
Source
Frequently Asked Questions
What does getChartData() do?
getChartData() is a function in the react codebase, defined in packages/react-devtools-shared/src/devtools/views/Profiler/FlamegraphChartBuilder.js.
Where is getChartData() defined?
getChartData() is defined in packages/react-devtools-shared/src/devtools/views/Profiler/FlamegraphChartBuilder.js at line 37.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free