1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 } = require("devtools/shared/protocol");
11 performanceRecordingSpec,
12 } = require("devtools/shared/specs/performance-recording");
14 loader.lazyRequireGetter(
17 "devtools/client/performance/modules/io"
19 loader.lazyRequireGetter(
21 "PerformanceRecordingCommon",
22 "devtools/shared/performance/recording-common",
25 loader.lazyRequireGetter(
28 "devtools/shared/performance/recording-utils"
32 * This can be used on older Profiler implementations, but the methods cannot
33 * be changed -- you must introduce a new method, and detect the server.
35 class PerformanceRecordingFront extends FrontClassWithSpec(
36 performanceRecordingSpec
39 this.actorID = form.actor;
41 this._configuration = form.configuration;
42 this._startingBufferStatus = form.startingBufferStatus;
43 this._console = form.console;
44 this._label = form.label;
45 this._startTime = form.startTime;
46 this._localStartTime = form.localStartTime;
47 this._recording = form.recording;
48 this._completed = form.completed;
49 this._duration = form.duration;
51 if (form.finalizedData) {
52 this._profile = form.profile;
53 this._systemHost = form.systemHost;
54 this._systemClient = form.systemClient;
57 // Sort again on the client side if we're using realtime markers and the recording
58 // just finished. This is because GC/Compositing markers can come into the array out
59 // of order with the other markers, leading to strange collapsing in waterfall view.
60 if (this._completed && !this._markersSorted) {
61 this._markers = this._markers.sort((a, b) => a.start > b.start);
62 this._markersSorted = true;
66 constructor(client, targetFront, parentFront) {
67 super(client, targetFront, parentFront);
72 this._allocations = { sites: [], timestamps: [], frames: [], sizes: [] };
76 * Saves the current recording to a file.
79 * The file to stream the data into.
81 exportRecording(file) {
82 const recordingData = this.getAllData();
83 return PerformanceIO.saveRecordingToFile(recordingData, file);
87 * Fired whenever the PerformanceFront emits markers, memory or ticks.
89 _addTimelineData(eventName, data) {
90 const config = this.getConfiguration();
93 // Accumulate timeline markers into an array. Furthermore, the timestamps
94 // do not have a zero epoch, so offset all of them by the start time.
96 if (!config.withMarkers) {
99 const { markers } = data;
100 RecordingUtils.offsetMarkerTimes(markers, this._startTime);
101 RecordingUtils.pushAll(this._markers, markers);
104 // Accumulate stack frames into an array.
106 if (!config.withMarkers) {
109 const { frames } = data;
110 RecordingUtils.pushAll(this._frames, frames);
113 // Accumulate memory measurements into an array. Furthermore, the timestamp
114 // does not have a zero epoch, so offset it by the actor's start time.
116 if (!config.withMemory) {
119 const { delta, measurement } = data;
121 delta: delta - this._startTime,
122 value: measurement.total / 1024 / 1024,
126 // Save the accumulated refresh driver ticks.
128 if (!config.withTicks) {
131 const { timestamps } = data;
132 this._ticks = timestamps;
135 // Accumulate allocation sites into an array.
136 case "allocations": {
137 if (!config.withAllocations) {
142 allocationsTimestamps: timestamps,
143 allocationSizes: sizes,
147 RecordingUtils.offsetAndScaleTimestamps(timestamps, this._startTime);
148 RecordingUtils.pushAll(this._allocations.sites, sites);
149 RecordingUtils.pushAll(this._allocations.timestamps, timestamps);
150 RecordingUtils.pushAll(this._allocations.frames, frames);
151 RecordingUtils.pushAll(this._allocations.sizes, sizes);
158 return "[object PerformanceRecordingFront]";
162 // PerformanceRecordingFront also needs to inherit from PerformanceRecordingCommon
163 // but as ES classes don't support multiple inheritance, we are overriding the
164 // prototype with PerformanceRecordingCommon methods.
165 Object.defineProperties(
166 PerformanceRecordingFront.prototype,
167 Object.getOwnPropertyDescriptors(PerformanceRecordingCommon)
170 exports.PerformanceRecordingFront = PerformanceRecordingFront;
171 registerFront(PerformanceRecordingFront);