Profiler: Improve labels for times that round to 0.0ms
Subhan committed
May 8, 2019 at 10:11 UTC
60511aadc065d49d0b83578c8983b4447de45abb
4 files changed
+14
-8
src/devtools/views/Profiler/FlamegraphChartBuilder.js
+3
-3
@@ -1,6 +1,6 @@
1
// @flow
2
3
-import { calculateSelfDuration } from './utils';
3
+import { calculateSelfDuration, fineTune } from './utils';
4
5
import type { CommitDetailsFrontend, CommitTreeFrontend } from './types';
6
@@ -68,8 +68,8 @@ export function getChartData({
68
69
let label = `${name}${maybeKey}`;
70
if (didRender) {
71
- label += ` (${selfDuration.toFixed(1)}ms of ${actualDuration.toFixed(
72
- 1
71
+ label += ` (${fineTune(selfDuration.toFixed(1))}ms of ${fineTune(
72
+ actualDuration.toFixed(1)
73
)}ms)`;
74
}
75
src/devtools/views/Profiler/RankedChartBuilder.js
+2
-3
@@ -1,6 +1,6 @@
1
// @flow
2
3
-import { calculateSelfDuration } from './utils';
3
+import { calculateSelfDuration, fineTune } from './utils';
4
5
import type { CommitDetailsFrontend, CommitTreeFrontend } from './types';
6
@@ -49,13 +49,12 @@ export function getChartData({
49
if (node.parentID === 0) {
50
return;
51
}
52
-
52
const selfDuration = calculateSelfDuration(id, commitTree, commitDetails);
53
maxSelfDuration = Math.max(maxSelfDuration, selfDuration);
54
55
const name = node.displayName || 'Unknown';
56
const maybeKey = node.key !== null ? ` key="${node.key}"` : '';
58
- const label = `${name}${maybeKey} (${selfDuration.toFixed(1)}ms)`;
57
+ const label = `${name}${maybeKey} (${fineTune(selfDuration.toFixed(1))}ms)`;
58
chartNodes.push({
59
id,
60
label,
src/devtools/views/Profiler/SidebarSelectedFiberInfo.js
+2
-2
@@ -2,7 +2,7 @@
2
3
import React, { Fragment, useContext } from 'react';
4
import { ProfilerContext } from './ProfilerContext';
5
-import { formatDuration, formatTime } from './utils';
5
+import { formatDuration, formatTime, fineTune } from './utils';
6
import { StoreContext } from '../context';
7
import Button from '../Button';
8
import ButtonIcon from '../ButtonIcon';
@@ -50,7 +50,7 @@ export default function SidebarSelectedFiberInfo(_: Props) {
50
}
51
onClick={() => selectCommitIndex(commitIndex)}
52
>
53
- {formatTime(time)}s for {formatDuration(duration)}ms
53
+ {fineTune(formatTime(time))}s for {fineTune(formatDuration(duration))}ms
54
</button>
55
);
56
}
src/devtools/views/Profiler/utils.js
+7
@@ -72,3 +72,10 @@ export const scale = (
72
maxValue - minValue === 0
73
? fallbackValue
74
: ((value - minValue) / (maxValue - minValue)) * (maxRange - minRange);
75
+
76
+export const fineTune = (duration: number | string): string => {
77
+ if (Number(duration) === 0) {
78
+ return '<0.1';
79
+ }
80
+ return `${duration}`;
81
+};