Files
palemoon27/toolkit/devtools/performance/modules/logic/waterfall-utils.js
T
roytam1 45b8007f3d import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1150717 - Test request with no params in the Network Monitor. r=brings (a60e9e8d9)
- Bug 1168077 - Remove remaining spidermonkey js specific syntax from browser/devtools; r=miker (c98f20c30)
- Bug 1168125 - Fix existing tests, r=jsantell (b1dfa101e)
- Bug 1169439 - Pull out marker definitions into its own file, and move formatter and collapse functions into marker-utils. r=vp (17eb24ab3)
- Bug 1173654 - Part 1: Add logging methods for SurfaceType and ImageFormat. r=Bas (22f2fa019)
- Bug 1169125 - Part 1: Allow sending any DataSourceSurface-backed image over WebRTC and fix failure cases. r=bwc (1fb0def92)
- Bug 1169125 - Part 2: Use UniquePtr for scoped delete of yuv data in MediaPipeline. r=bwc (cdb79e201)
- Bug 1173654 - Part 2: Use namespaces in MediaPipeline.cpp. r=bwc (311696260)
- Bug 1173654 - Part 3: Attempt to GetDataSurface() and convert if sending pure I420 fails. r=bwc, r=jesup (58520b820)
- Bug 1173654 - Part 4: Add detailed logging and asserts to MediaPipeline::ProcessVideoChunk. r=bwc (ba08ae5bc)
- Bug 1155089 - Part 1: Reset |TrackID| for MediaPipelineTransmit::PipelineListener on replaceTrack(). r=bwc (304fb8703)
- adapted Bug 1142688 - Wait for actual audio data on remote side before checking audio sanity. r=jesup,padenot (479f6356c)
- Bug 858927 - Move the mozilla::TimeStamp into mozglue. r=glandium (751938e09)
- Bug 1166559 - Add documentation for ProfileTimelineMarkers from a dev tools perspective. r=fitzgen (ed1563dfb)
- Bug 1141614 - Part 4: Expose cycle collection markers in the devtools frontend; r=jsantell (2eb830de7)
2021-07-30 11:25:34 +08:00

123 lines
3.4 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";
/**
* Utility functions for collapsing markers into a waterfall.
*/
loader.lazyRequireGetter(this, "TIMELINE_BLUEPRINT",
"devtools/performance/markers", true);
/**
* Collapses markers into a tree-like structure. Currently, this only goes
* one level deep.
* @param object markerNode
* @param array markersList
*/
function collapseMarkersIntoNode({ markerNode, markersList }) {
let [getOrCreateParentNode, getCurrentParentNode, clearParentNode] = makeParentNodeFactory();
for (let i = 0, len = markersList.length; i < len; i++) {
let curr = markersList[i];
let blueprint = TIMELINE_BLUEPRINT[curr.name];
let parentNode = getCurrentParentNode();
let collapse = blueprint.collapseFunc || (() => null);
let peek = distance => markersList[i + distance];
let collapseInfo = collapse(parentNode, curr, peek);
if (collapseInfo) {
let { toParent, withData, forceNew, forceEnd } = collapseInfo;
// If the `forceNew` prop is set on the collapse info, then a new parent
// marker needs to be created even if there is one already available.
if (forceNew) {
clearParentNode();
}
// If the `toParent` prop is set on the collapse info, then this marker
// can be collapsed into a higher-level parent marker.
if (toParent) {
let parentNode = getOrCreateParentNode(markerNode, toParent, curr.start);
parentNode.end = curr.end;
parentNode.submarkers.push(curr);
for (let key in withData) {
parentNode[key] = withData[key];
}
}
// If the `forceEnd` prop is set on the collapse info, then the higher-level
// parent marker is full and should be finalized.
if (forceEnd) {
clearParentNode();
}
} else {
clearParentNode();
markerNode.submarkers.push(curr);
}
}
}
/**
* Creates an empty parent marker, which functions like a regular marker,
* but is able to hold additional child markers.
* @param string name
* @param number start [optional]
* @param number end [optional]
* @return object
*/
function makeEmptyMarkerNode(name, start, end) {
return {
name: name,
start: start,
end: end,
submarkers: []
};
}
/**
* Creates a factory for markers containing other markers.
* @return array[function]
*/
function makeParentNodeFactory() {
let marker;
return [
/**
* Gets the current parent marker for the given marker name. If it doesn't
* exist, it creates it and appends it to another parent marker.
* @param object owner
* @param string name
* @param number start
* @return object
*/
function getOrCreateParentNode(owner, name, start) {
if (marker && marker.name == name) {
return marker;
} else {
marker = makeEmptyMarkerNode(name, start);
owner.submarkers.push(marker);
return marker;
}
},
/**
* Gets the current marker marker.
* @return object
*/
function getCurrentParentNode() {
return marker;
},
/**
* Clears the current marker marker.
*/
function clearParentNode() {
marker = null;
}
];
}
exports.makeEmptyMarkerNode = makeEmptyMarkerNode;
exports.collapseMarkersIntoNode = collapseMarkersIntoNode;