Bug 1622408 [wpt PR 22244] - Restore the event delegate for a CSSTransition after...
[gecko.git] / devtools / shared / fronts / performance-recording.js
blob93015e8df109f7ef48826754845de8d950af30bc
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/. */
4 "use strict";
6 const {
7   FrontClassWithSpec,
8   registerFront,
9 } = require("devtools/shared/protocol");
10 const {
11   performanceRecordingSpec,
12 } = require("devtools/shared/specs/performance-recording");
14 loader.lazyRequireGetter(
15   this,
16   "PerformanceIO",
17   "devtools/client/performance/modules/io"
19 loader.lazyRequireGetter(
20   this,
21   "PerformanceRecordingCommon",
22   "devtools/shared/performance/recording-common",
23   true
25 loader.lazyRequireGetter(
26   this,
27   "RecordingUtils",
28   "devtools/shared/performance/recording-utils"
31 /**
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.
34  */
35 class PerformanceRecordingFront extends FrontClassWithSpec(
36   performanceRecordingSpec
37 ) {
38   form(form) {
39     this.actorID = form.actor;
40     this._form = form;
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;
55     }
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;
63     }
64   }
66   constructor(client, targetFront, parentFront) {
67     super(client, targetFront, parentFront);
68     this._markers = [];
69     this._frames = [];
70     this._memory = [];
71     this._ticks = [];
72     this._allocations = { sites: [], timestamps: [], frames: [], sizes: [] };
73   }
75   /**
76    * Saves the current recording to a file.
77    *
78    * @param nsIFile file
79    *        The file to stream the data into.
80    */
81   exportRecording(file) {
82     const recordingData = this.getAllData();
83     return PerformanceIO.saveRecordingToFile(recordingData, file);
84   }
86   /**
87    * Fired whenever the PerformanceFront emits markers, memory or ticks.
88    */
89   _addTimelineData(eventName, data) {
90     const config = this.getConfiguration();
92     switch (eventName) {
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.
95       case "markers": {
96         if (!config.withMarkers) {
97           break;
98         }
99         const { markers } = data;
100         RecordingUtils.offsetMarkerTimes(markers, this._startTime);
101         RecordingUtils.pushAll(this._markers, markers);
102         break;
103       }
104       // Accumulate stack frames into an array.
105       case "frames": {
106         if (!config.withMarkers) {
107           break;
108         }
109         const { frames } = data;
110         RecordingUtils.pushAll(this._frames, frames);
111         break;
112       }
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.
115       case "memory": {
116         if (!config.withMemory) {
117           break;
118         }
119         const { delta, measurement } = data;
120         this._memory.push({
121           delta: delta - this._startTime,
122           value: measurement.total / 1024 / 1024,
123         });
124         break;
125       }
126       // Save the accumulated refresh driver ticks.
127       case "ticks": {
128         if (!config.withTicks) {
129           break;
130         }
131         const { timestamps } = data;
132         this._ticks = timestamps;
133         break;
134       }
135       // Accumulate allocation sites into an array.
136       case "allocations": {
137         if (!config.withAllocations) {
138           break;
139         }
140         const {
141           allocations: sites,
142           allocationsTimestamps: timestamps,
143           allocationSizes: sizes,
144           frames,
145         } = data;
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);
152         break;
153       }
154     }
155   }
157   toString() {
158     return "[object PerformanceRecordingFront]";
159   }
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);