Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 0e983a1

Browse files
authored
Profiler tweaks (#1105)
* Fixed a potential null prop access bug in SnapshotSelector * Fixed horizontal padding nit Sophie mentioned * Tweaked duration rounding * Changed label when filtered fiber isn't in the selector to -/X * "Render count" -> "Total renders" * Snapshot selector shouldnt wrap around * Time -> Timestamp * Hide snapshot selector when viewing Interactions tab
1 parent 1198718 commit 0e983a1

8 files changed

+44
-37
lines changed

plugins/Profiler/views/FiberRenderDurations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ class ListItem extends PureComponent<any, void> {
193193
height={safeHeight}
194194
isDimmed={node.parentSnapshot === selectedSnapshot}
195195
key={index}
196-
label={`${node.value.toFixed(2)}ms`}
196+
label={`${node.value.toFixed(1)}ms`}
197197
onClick={() => selectSnapshot(node.parentSnapshot)}
198198
onDoubleClick={stopInspecting}
199199
theme={theme}
200-
title={`${node.value}ms`}
200+
title={`${node.value.toFixed(3)}ms`}
201201
width={width}
202202
x={left}
203203
y={height - safeHeight}

plugins/Profiler/views/ProfilerFiberDetailPane.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const ProfilerFiberDetailPane = ({
101101
fontSize: monospace.sizes.normal,
102102
fontFamily: monospace.family,
103103
}}>
104-
<strong>Render count</strong>: {snapshotFiber.get('renders')}
104+
<strong>Total renders</strong>: {snapshotFiber.get('renders')}
105105
</div>
106106
<DetailPane theme={theme}>
107107
<DetailPaneSection title="Props">

plugins/Profiler/views/ProfilerInteractionDetailPane.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const ProfilerInteractionDetailPane = ({
5858
<div style={{
5959
padding: '0.5rem',
6060
}}>
61-
<div><strong>Time</strong>: {formatTime(interaction.timestamp)}s</div>
61+
<div><strong>Timestamp</strong>: {formatTime(interaction.timestamp)}s</div>
6262
<div style={{margin: '0.5rem 0'}}><strong>Renders</strong>:</div>
6363
<ul style={{
6464
listStyle: 'none',
@@ -119,8 +119,8 @@ const SnapshotLink = Hoverable(({
119119
>
120120
{cpuSvg}
121121
<ul style={{paddingLeft: '1.5rem'}}>
122+
<li>Timestamp: {formatTime(snapshot.commitTime)}s</li>
122123
<li>Duration: {formatDuration(snapshot.duration)}ms</li>
123-
<li>Time: {formatTime(snapshot.commitTime)}s</li>
124124
<li>CPU: {formatPercentage(cpuPercentage)}%</li>
125125
</ul>
126126
</li>

plugins/Profiler/views/ProfilerTabToolbar.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,23 @@ const ProfilerTabToolbar = ({
162162
theme={theme}
163163
/>
164164

165-
<HRule theme={theme} />
165+
{selectedChartType !== 'interactions' && (
166+
<Fragment>
167+
<HRule theme={theme} />
166168

167-
<SnapshotSelector
168-
commitThreshold={commitThreshold}
169-
hideCommitsBelowThreshold={hideCommitsBelowThreshold}
170-
isInspectingSelectedFiber={isInspectingSelectedFiber}
171-
selectedFiberID={selectedFiberID}
172-
selectedSnapshot={selectedSnapshot}
173-
selectSnapshot={selectSnapshot}
174-
snapshotIndex={snapshotIndex}
175-
snapshots={snapshots}
176-
theme={theme}
177-
/>
169+
<SnapshotSelector
170+
commitThreshold={commitThreshold}
171+
hideCommitsBelowThreshold={hideCommitsBelowThreshold}
172+
isInspectingSelectedFiber={isInspectingSelectedFiber}
173+
selectedFiberID={selectedFiberID}
174+
selectedSnapshot={selectedSnapshot}
175+
selectSnapshot={selectSnapshot}
176+
snapshotIndex={snapshotIndex}
177+
snapshots={snapshots}
178+
theme={theme}
179+
/>
180+
</Fragment>
181+
)}
178182
</Fragment>
179183
)}
180184
</div>
@@ -185,7 +189,7 @@ const HRule = ({ theme }) => (
185189
height: '18px',
186190
width: '1px',
187191
backgroundColor: theme.base03,
188-
margin: '0 0.5rem',
192+
margin: '0px 0.5rem 0 0.25rem',
189193
}} />
190194
);
191195

plugins/Profiler/views/SnapshotFlamegraph.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ class ListItem extends PureComponent<any, void> {
266266
height={barHeight}
267267
isDimmed={index < focusedNodeIndex}
268268
key={id}
269-
label={didRender ? `${name} (${actualDuration.toFixed(2)}ms)` : name}
269+
label={didRender ? `${name} (${actualDuration.toFixed(1)}ms)` : name}
270270
onClick={this.handleClick.bind(this, id, name)}
271271
onDoubleClick={this.handleDoubleClick.bind(this, id, name)}
272272
theme={itemData.theme}
273-
title={didRender ? `${name} (${actualDuration}ms)` : name}
273+
title={didRender ? `${name} (${actualDuration.toFixed(3)}ms)` : name}
274274
width={nodeWidth}
275275
x={nodeX - focusedNodeX}
276276
y={top}

plugins/Profiler/views/SnapshotRanked.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ const convertSnapshotToChartData = (snapshot: Snapshot, showNativeNodes: boolean
258258

259259
return {
260260
id: node.id,
261-
label: `${name} (${node.actualDuration.toFixed(2)}ms)`,
261+
label: `${name} (${node.actualDuration.toFixed(1)}ms)`,
262262
name,
263-
title: `${name} (${node.actualDuration}ms)`,
263+
title: `${name} (${node.actualDuration.toFixed(3)}ms)`,
264264
value: node.actualDuration,
265265
};
266266
})

plugins/Profiler/views/SnapshotSelector.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ class SnapshotSelectorWrapper extends PureComponent<Props, void> {
115115
snapshots,
116116
} = this.props;
117117

118-
if (snapshots.length > 0) {
119-
const newIndex = snapshotIndex < snapshots.length - 1
120-
? snapshotIndex + 1
121-
: 0;
122-
118+
if (
119+
snapshots.length > 0 &&
120+
snapshotIndex < snapshots.length - 1
121+
) {
122+
const newIndex = snapshotIndex + 1;
123123
selectSnapshot(snapshots[newIndex]);
124124
}
125125
};
@@ -131,11 +131,11 @@ class SnapshotSelectorWrapper extends PureComponent<Props, void> {
131131
snapshots,
132132
} = this.props;
133133

134-
if (snapshots.length > 0) {
135-
const newIndex = snapshotIndex > 0
136-
? snapshotIndex - 1
137-
: snapshots.length - 1;
138-
134+
if (
135+
snapshots.length > 0 &&
136+
snapshotIndex > 0
137+
) {
138+
const newIndex = snapshotIndex - 1;
139139
selectSnapshot(snapshots[newIndex]);
140140
}
141141
};
@@ -173,11 +173,11 @@ class SnapshotSelectorWrapper extends PureComponent<Props, void> {
173173
)}
174174
{numSnapshots > 0 && (
175175
<span style={{whiteSpace: 'nowrap'}}>
176-
{`${snapshotIndex + 1}`.padStart(`${numSnapshots}`.length, '0')} / {numSnapshots}
176+
{`${snapshotIndex >= 0 ? snapshotIndex + 1 : '-'}`.padStart(`${numSnapshots}`.length, '0')} / {numSnapshots}
177177
</span>
178178
)}
179179
<IconButton
180-
disabled={numSnapshots === 0}
180+
disabled={snapshotIndex <= 0}
181181
icon={Icons.BACK}
182182
isTransparent={true}
183183
onClick={this.selectPreviousSnapshotIndex}
@@ -196,7 +196,7 @@ class SnapshotSelectorWrapper extends PureComponent<Props, void> {
196196
theme={theme}
197197
/>
198198
<IconButton
199-
disabled={numSnapshots === 0}
199+
disabled={numSnapshots === 0 || snapshotIndex >= numSnapshots - 1}
200200
icon={Icons.FORWARD}
201201
isTransparent={true}
202202
onClick={this.selectNextSnapshotIndex}
@@ -271,7 +271,10 @@ class SnapshotSelector extends PureComponent<SnapshotSelectorProps, SnapshotSele
271271

272272
componentDidUpdate(prevProps) {
273273
// Make sure any newly selected snapshot is visible within the list.
274-
if (this.props.snapshotIndex !== prevProps.snapshotIndex) {
274+
if (
275+
this.props.snapshotIndex !== prevProps.snapshotIndex &&
276+
this.listRef.current !== null
277+
) {
275278
this.listRef.current.scrollToItem(this.props.snapshotIndex);
276279
}
277280
}

plugins/Profiler/views/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export const getFilteredSnapshotData = memoize((
7979
const filteredSnapshotIndex = filteredSnapshots.indexOf(selectedSnapshot);
8080

8181
return {
82-
snapshotIndex: filteredSnapshotIndex >= 0 ? filteredSnapshotIndex : 0,
82+
snapshotIndex: filteredSnapshotIndex,
8383
snapshots: filteredSnapshots,
8484
};
8585
});

0 commit comments

Comments
 (0)