Only measure "base" times within ProfileMode (#12821)
* Conditionally start/stop base timer only within Profile mode tree * Added test to ensure ProfilerTimer not called outside of Profiler root
This commit is contained in:
parent
9097f3cdf0
commit
103503eb69
|
@ -962,12 +962,17 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
|
||||||
|
|
||||||
let next;
|
let next;
|
||||||
if (enableProfilerTimer) {
|
if (enableProfilerTimer) {
|
||||||
startBaseRenderTimer();
|
if (workInProgress.mode & ProfileMode) {
|
||||||
|
startBaseRenderTimer();
|
||||||
|
}
|
||||||
|
|
||||||
next = beginWork(current, workInProgress, nextRenderExpirationTime);
|
next = beginWork(current, workInProgress, nextRenderExpirationTime);
|
||||||
|
|
||||||
// Update "base" time if the render wasn't bailed out on.
|
if (workInProgress.mode & ProfileMode) {
|
||||||
recordElapsedBaseRenderTimeIfRunning(workInProgress);
|
// Update "base" time if the render wasn't bailed out on.
|
||||||
stopBaseRenderTimerIfRunning();
|
recordElapsedBaseRenderTimeIfRunning(workInProgress);
|
||||||
|
stopBaseRenderTimerIfRunning();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
next = beginWork(current, workInProgress, nextRenderExpirationTime);
|
next = beginWork(current, workInProgress, nextRenderExpirationTime);
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,10 +108,14 @@ describe('Profiler', () => {
|
||||||
describe('onRender callback', () => {
|
describe('onRender callback', () => {
|
||||||
let AdvanceTime;
|
let AdvanceTime;
|
||||||
let advanceTimeBy;
|
let advanceTimeBy;
|
||||||
|
let mockNow;
|
||||||
|
|
||||||
const mockNowForTests = () => {
|
const mockNowForTests = () => {
|
||||||
let currentTime = 0;
|
let currentTime = 0;
|
||||||
ReactTestRenderer.unstable_setNowImplementation(() => currentTime);
|
|
||||||
|
mockNow = jest.fn().mockImplementation(() => currentTime);
|
||||||
|
|
||||||
|
ReactTestRenderer.unstable_setNowImplementation(mockNow);
|
||||||
advanceTimeBy = amount => {
|
advanceTimeBy = amount => {
|
||||||
currentTime += amount;
|
currentTime += amount;
|
||||||
};
|
};
|
||||||
|
@ -164,6 +168,20 @@ describe('Profiler', () => {
|
||||||
expect(callback).toHaveBeenCalledTimes(1);
|
expect(callback).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not record times for components outside of Profiler tree', () => {
|
||||||
|
ReactTestRenderer.create(
|
||||||
|
<div>
|
||||||
|
<AdvanceTime />
|
||||||
|
<AdvanceTime />
|
||||||
|
<AdvanceTime />
|
||||||
|
</div>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Should only be called twice, for normal expiration time purposes.
|
||||||
|
// No additional calls from ProfilerTimer are expected.
|
||||||
|
expect(mockNow).toHaveBeenCalledTimes(2);
|
||||||
|
});
|
||||||
|
|
||||||
it('logs render times for both mount and update', () => {
|
it('logs render times for both mount and update', () => {
|
||||||
const callback = jest.fn();
|
const callback = jest.fn();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue