summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/actions/utils/middleware/timing.js
blob: 8b6b7baf5e91411f95efb1b2bdbcaf24e8454259 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

/**
 * Redux middleware that sets performance markers for all actions such that they
 * will appear in performance tooling under the User Timing API
 */

const mark = window.performance?.mark
  ? window.performance.mark.bind(window.performance)
  : () => {};

const measure = window.performance?.measure
  ? window.performance.measure.bind(window.performance)
  : () => {};

export function timing() {
  return next => action => {
    mark(`${action.type}_start`);
    const result = next(action);
    mark(`${action.type}_end`);
    measure(`${action.type}`, `${action.type}_start`, `${action.type}_end`);
    return result;
  };
}