2018-04-13 23:29:34 +03:00
|
|
|
/* 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/. */
|
2019-10-08 23:30:49 +03:00
|
|
|
// @ts-check
|
2018-04-13 23:29:34 +03:00
|
|
|
"use strict";
|
2019-10-07 16:44:12 +03:00
|
|
|
|
2018-04-13 23:29:34 +03:00
|
|
|
const { combineReducers } = require("devtools/client/shared/vendor/redux");
|
|
|
|
|
2019-10-07 16:44:12 +03:00
|
|
|
/**
|
2019-10-08 23:30:49 +03:00
|
|
|
* @typedef {import("../@types/perf").Action} Action
|
|
|
|
* @typedef {import("../@types/perf").State} State
|
|
|
|
* @typedef {import("../@types/perf").RecordingState} RecordingState
|
|
|
|
* @typedef {import("../@types/perf").InitializedValues} InitializedValues
|
2019-10-07 16:44:12 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @template S
|
2019-10-08 23:30:49 +03:00
|
|
|
* @typedef {import("../@types/perf").Reducer<S>} Reducer<S>
|
2019-10-07 16:44:12 +03:00
|
|
|
*/
|
|
|
|
|
2018-04-13 23:29:34 +03:00
|
|
|
/**
|
|
|
|
* The current state of the recording.
|
2019-10-07 16:44:12 +03:00
|
|
|
* @type {Reducer<RecordingState>}
|
2018-04-13 23:29:34 +03:00
|
|
|
*/
|
2019-10-07 16:43:58 +03:00
|
|
|
function recordingState(state = "not-yet-known", action) {
|
2018-04-13 23:29:34 +03:00
|
|
|
switch (action.type) {
|
|
|
|
case "CHANGE_RECORDING_STATE":
|
|
|
|
return action.state;
|
|
|
|
case "REPORT_PROFILER_READY":
|
|
|
|
return action.recordingState;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not the recording state unexpectedly stopped. This allows
|
|
|
|
* the UI to display a helpful message.
|
2019-10-07 16:44:12 +03:00
|
|
|
* @type {Reducer<boolean>}
|
2018-04-13 23:29:34 +03:00
|
|
|
*/
|
|
|
|
function recordingUnexpectedlyStopped(state = false, action) {
|
|
|
|
switch (action.type) {
|
|
|
|
case "CHANGE_RECORDING_STATE":
|
|
|
|
return action.didRecordingUnexpectedlyStopped;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The profiler needs to be queried asynchronously on whether or not
|
|
|
|
* it supports the user's platform.
|
2019-10-07 16:44:12 +03:00
|
|
|
* @type {Reducer<boolean | null>}
|
2018-04-13 23:29:34 +03:00
|
|
|
*/
|
|
|
|
function isSupportedPlatform(state = null, action) {
|
|
|
|
switch (action.type) {
|
|
|
|
case "REPORT_PROFILER_READY":
|
|
|
|
return action.isSupportedPlatform;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Right now all recording setting the defaults are reset every time the panel
|
|
|
|
// is opened. These should be persisted between sessions. See Bug 1453014.
|
|
|
|
|
|
|
|
/**
|
2018-07-26 12:47:30 +03:00
|
|
|
* The setting for the recording interval. Defaults to 1ms.
|
2019-10-07 16:44:12 +03:00
|
|
|
* @type {Reducer<number>}
|
2018-04-13 23:29:34 +03:00
|
|
|
*/
|
2019-10-22 11:13:55 +03:00
|
|
|
function interval(state = 1, action) {
|
2018-04-13 23:29:34 +03:00
|
|
|
switch (action.type) {
|
|
|
|
case "CHANGE_INTERVAL":
|
|
|
|
return action.interval;
|
2020-01-23 02:11:49 +03:00
|
|
|
case "CHANGE_PRESET":
|
|
|
|
return action.preset ? action.preset.interval : state;
|
2018-04-18 19:15:59 +03:00
|
|
|
case "INITIALIZE_STORE":
|
|
|
|
return action.recordingSettingsFromPreferences.interval;
|
2018-04-13 23:29:34 +03:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-10 21:00:05 +03:00
|
|
|
* The number of entries in the profiler's circular buffer.
|
2019-10-07 16:44:12 +03:00
|
|
|
* @type {Reducer<number>}
|
2018-04-13 23:29:34 +03:00
|
|
|
*/
|
2019-10-10 21:00:05 +03:00
|
|
|
function entries(state = 0, action) {
|
2018-04-13 23:29:34 +03:00
|
|
|
switch (action.type) {
|
|
|
|
case "CHANGE_ENTRIES":
|
|
|
|
return action.entries;
|
2020-01-23 02:11:49 +03:00
|
|
|
case "CHANGE_PRESET":
|
|
|
|
return action.preset ? action.preset.entries : state;
|
2018-04-18 19:15:59 +03:00
|
|
|
case "INITIALIZE_STORE":
|
|
|
|
return action.recordingSettingsFromPreferences.entries;
|
2018-04-13 23:29:34 +03:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The features that are enabled for the profiler.
|
2019-10-07 16:44:12 +03:00
|
|
|
* @type {Reducer<string[]>}
|
2018-04-13 23:29:34 +03:00
|
|
|
*/
|
2019-10-10 21:00:05 +03:00
|
|
|
function features(state = [], action) {
|
2018-04-13 23:29:34 +03:00
|
|
|
switch (action.type) {
|
|
|
|
case "CHANGE_FEATURES":
|
|
|
|
return action.features;
|
2020-01-23 02:11:49 +03:00
|
|
|
case "CHANGE_PRESET":
|
|
|
|
return action.preset ? action.preset.features : state;
|
2018-04-18 19:15:59 +03:00
|
|
|
case "INITIALIZE_STORE":
|
|
|
|
return action.recordingSettingsFromPreferences.features;
|
2018-04-13 23:29:34 +03:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current threads list.
|
2019-10-07 16:44:12 +03:00
|
|
|
* @type {Reducer<string[]>}
|
2018-04-13 23:29:34 +03:00
|
|
|
*/
|
2019-10-10 21:00:05 +03:00
|
|
|
function threads(state = [], action) {
|
2018-04-13 23:29:34 +03:00
|
|
|
switch (action.type) {
|
|
|
|
case "CHANGE_THREADS":
|
|
|
|
return action.threads;
|
2020-01-23 02:11:49 +03:00
|
|
|
case "CHANGE_PRESET":
|
|
|
|
return action.preset ? action.preset.threads : state;
|
2018-04-18 19:15:59 +03:00
|
|
|
case "INITIALIZE_STORE":
|
|
|
|
return action.recordingSettingsFromPreferences.threads;
|
2018-04-13 23:29:34 +03:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-07 22:43:47 +03:00
|
|
|
/**
|
|
|
|
* The current objdirs list.
|
2019-10-07 16:44:12 +03:00
|
|
|
* @type {Reducer<string[]>}
|
2019-02-07 22:43:47 +03:00
|
|
|
*/
|
|
|
|
function objdirs(state = [], action) {
|
|
|
|
switch (action.type) {
|
|
|
|
case "CHANGE_OBJDIRS":
|
|
|
|
return action.objdirs;
|
|
|
|
case "INITIALIZE_STORE":
|
|
|
|
return action.recordingSettingsFromPreferences.objdirs;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-23 02:11:49 +03:00
|
|
|
/**
|
|
|
|
* The current preset name, used to select
|
|
|
|
* @type {Reducer<string>}
|
|
|
|
*/
|
|
|
|
function presetName(state = "", action) {
|
|
|
|
switch (action.type) {
|
|
|
|
case "INITIALIZE_STORE":
|
|
|
|
return action.recordingSettingsFromPreferences.presetName;
|
|
|
|
case "CHANGE_PRESET":
|
|
|
|
return action.presetName;
|
|
|
|
case "CHANGE_INTERVAL":
|
|
|
|
case "CHANGE_ENTRIES":
|
|
|
|
case "CHANGE_FEATURES":
|
|
|
|
case "CHANGE_THREADS":
|
|
|
|
// When updating any values, switch the preset over to "custom".
|
|
|
|
return "custom";
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 23:29:34 +03:00
|
|
|
/**
|
2019-10-07 16:44:12 +03:00
|
|
|
* These are all the values used to initialize the profiler. They should never
|
|
|
|
* change once added to the store.
|
2018-04-13 23:29:34 +03:00
|
|
|
*
|
2019-10-07 16:44:12 +03:00
|
|
|
* @type {Reducer<InitializedValues | null>}
|
2018-04-13 23:29:34 +03:00
|
|
|
*/
|
|
|
|
function initializedValues(state = null, action) {
|
|
|
|
switch (action.type) {
|
|
|
|
case "INITIALIZE_STORE":
|
2018-04-18 19:15:59 +03:00
|
|
|
return {
|
|
|
|
perfFront: action.perfFront,
|
|
|
|
receiveProfile: action.receiveProfile,
|
|
|
|
setRecordingPreferences: action.setRecordingPreferences,
|
2020-03-02 19:53:39 +03:00
|
|
|
presets: action.presets,
|
2019-12-05 20:39:07 +03:00
|
|
|
pageContext: action.pageContext,
|
2019-10-04 21:17:43 +03:00
|
|
|
getSymbolTableGetter: action.getSymbolTableGetter,
|
2019-11-12 22:07:46 +03:00
|
|
|
supportedFeatures: action.supportedFeatures,
|
2020-03-09 18:01:02 +03:00
|
|
|
openAboutProfiling: action.openAboutProfiling,
|
|
|
|
openRemoteDevTools: action.openRemoteDevTools,
|
2018-04-18 19:15:59 +03:00
|
|
|
};
|
2018-04-13 23:29:34 +03:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-12 22:06:48 +03:00
|
|
|
/**
|
|
|
|
* Some features may need a browser restart with an environment flag. Request
|
|
|
|
* one here.
|
|
|
|
*
|
|
|
|
* @type {Reducer<string | null>}
|
|
|
|
*/
|
|
|
|
function promptEnvRestart(state = null, action) {
|
|
|
|
switch (action.type) {
|
|
|
|
case "CHANGE_FEATURES":
|
|
|
|
return action.promptEnvRestart;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 16:44:12 +03:00
|
|
|
/**
|
|
|
|
* The main reducer for the performance-new client.
|
|
|
|
* @type {Reducer<State>}
|
|
|
|
*/
|
2018-04-13 23:29:34 +03:00
|
|
|
module.exports = combineReducers({
|
2019-10-07 16:44:12 +03:00
|
|
|
// TODO - The object going into `combineReducers` is not currently type checked
|
|
|
|
// as being correct for. For instance, recordingState here could be removed, or
|
|
|
|
// not return the right state, and TypeScript will not create an error.
|
2018-04-13 23:29:34 +03:00
|
|
|
recordingState,
|
|
|
|
recordingUnexpectedlyStopped,
|
|
|
|
isSupportedPlatform,
|
|
|
|
interval,
|
|
|
|
entries,
|
|
|
|
features,
|
|
|
|
threads,
|
2019-02-07 22:43:47 +03:00
|
|
|
objdirs,
|
2020-01-23 02:11:49 +03:00
|
|
|
presetName,
|
2018-04-13 23:29:34 +03:00
|
|
|
initializedValues,
|
2019-11-12 22:06:48 +03:00
|
|
|
promptEnvRestart,
|
2018-04-13 23:29:34 +03:00
|
|
|
});
|