mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-27 20:25:44 +00:00
6ecbf50249
MozReview-Commit-ID: I1GlhEdco3H --HG-- extra : rebase_source : faa17e2cd6e985ada67ede46a11464e62f0f818f
104 lines
3.2 KiB
JavaScript
104 lines
3.2 KiB
JavaScript
/* 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/. */
|
|
|
|
"use strict";
|
|
|
|
const { Actor, ActorClassWithSpec } = require("devtools/shared/protocol");
|
|
const { actorBridgeWithSpec } = require("devtools/server/actors/common");
|
|
const { performanceSpec } = require("devtools/shared/specs/performance");
|
|
|
|
loader.lazyRequireGetter(this, "PerformanceRecorder",
|
|
"devtools/server/performance/recorder", true);
|
|
loader.lazyRequireGetter(this, "normalizePerformanceFeatures",
|
|
"devtools/shared/performance/recording-utils", true);
|
|
|
|
const PIPE_TO_FRONT_EVENTS = new Set([
|
|
"recording-started", "recording-stopping", "recording-stopped",
|
|
"profiler-status", "timeline-data", "console-profile-start"
|
|
]);
|
|
|
|
const RECORDING_STATE_CHANGE_EVENTS = new Set([
|
|
"recording-started", "recording-stopping", "recording-stopped"
|
|
]);
|
|
|
|
/**
|
|
* This actor wraps the Performance module at devtools/shared/shared/performance.js
|
|
* and provides RDP definitions.
|
|
*
|
|
* @see devtools/shared/shared/performance.js for documentation.
|
|
*/
|
|
var PerformanceActor = ActorClassWithSpec(performanceSpec, {
|
|
traits: {
|
|
features: {
|
|
withMarkers: true,
|
|
withTicks: true,
|
|
withMemory: true,
|
|
withFrames: true,
|
|
withGCEvents: true,
|
|
withDocLoadingEvents: true,
|
|
withAllocations: true,
|
|
},
|
|
},
|
|
|
|
initialize: function (conn, tabActor) {
|
|
Actor.prototype.initialize.call(this, conn);
|
|
this._onRecorderEvent = this._onRecorderEvent.bind(this);
|
|
this.bridge = new PerformanceRecorder(conn, tabActor);
|
|
this.bridge.on("*", this._onRecorderEvent);
|
|
},
|
|
|
|
destroy: function () {
|
|
this.bridge.off("*", this._onRecorderEvent);
|
|
this.bridge.destroy();
|
|
Actor.prototype.destroy.call(this);
|
|
},
|
|
|
|
connect: function (config) {
|
|
this.bridge.connect({ systemClient: config.systemClient });
|
|
return { traits: this.traits };
|
|
},
|
|
|
|
canCurrentlyRecord: function () {
|
|
return this.bridge.canCurrentlyRecord();
|
|
},
|
|
|
|
async startRecording(options = {}) {
|
|
if (!this.bridge.canCurrentlyRecord().success) {
|
|
return null;
|
|
}
|
|
|
|
let normalizedOptions = normalizePerformanceFeatures(options, this.traits.features);
|
|
let recording = await this.bridge.startRecording(normalizedOptions);
|
|
this.manage(recording);
|
|
|
|
return recording;
|
|
},
|
|
|
|
stopRecording: actorBridgeWithSpec("stopRecording"),
|
|
isRecording: actorBridgeWithSpec("isRecording"),
|
|
getRecordings: actorBridgeWithSpec("getRecordings"),
|
|
getConfiguration: actorBridgeWithSpec("getConfiguration"),
|
|
setProfilerStatusInterval: actorBridgeWithSpec("setProfilerStatusInterval"),
|
|
|
|
/**
|
|
* Filter which events get piped to the front.
|
|
*/
|
|
_onRecorderEvent: function (eventName, ...data) {
|
|
// If this is a recording state change, call
|
|
// a method on the related PerformanceRecordingActor so it can
|
|
// update its internal state.
|
|
if (RECORDING_STATE_CHANGE_EVENTS.has(eventName)) {
|
|
let recording = data[0];
|
|
let extraData = data[1];
|
|
recording._setState(eventName, extraData);
|
|
}
|
|
|
|
if (PIPE_TO_FRONT_EVENTS.has(eventName)) {
|
|
this.emit(eventName, ...data);
|
|
}
|
|
},
|
|
});
|
|
|
|
exports.PerformanceActor = PerformanceActor;
|