summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/actions/tracing.js
blob: 9cbe7bc20e0b866a5d1f9fc02a86bee1bc21e54a (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* 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/>. */

import { getIsThreadCurrentlyTracing, getAllThreads } from "../selectors";
import { PROMISE } from "./utils/middleware/promise";

/**
 * Toggle ON/OFF Javascript tracing for all targets,
 * using the specified log method.
 *
 * @param {string} logMethod
 *        Can be "stdout" or "console". See TracerActor.
 */
export function toggleTracing(logMethod) {
  return async ({ dispatch, getState, client, panel }) => {
    // Check if any of the thread is currently tracing.
    // For now, the UI can only toggle all the targets all at once.
    const threads = getAllThreads(getState());
    const isTracingEnabled = threads.some(thread =>
      getIsThreadCurrentlyTracing(getState(), thread.actor)
    );

    // Automatically open the split console when enabling tracing to the console
    if (!isTracingEnabled && logMethod == "console") {
      await panel.toolbox.openSplitConsole({ focusConsoleInput: false });
    }

    return dispatch({
      type: "TOGGLE_TRACING",
      [PROMISE]: isTracingEnabled
        ? client.stopTracing()
        : client.startTracing(logMethod),
    });
  };
}

/**
 * Called when tracing is toggled ON/OFF on a particular thread.
 */
export function tracingToggled(thread, enabled) {
  return ({ dispatch }) => {
    dispatch({
      type: "TRACING_TOGGLED",
      thread,
      enabled,
    });
  };
}