@player-devtools/profiler-plugin 1.0.1-next.0 → 1.0.1-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ProfilerDevtoolsPlugin.native.js +127 -53
- package/dist/ProfilerDevtoolsPlugin.native.js.map +1 -1
- package/dist/cjs/index.cjs +98 -23
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +93 -18
- package/dist/index.mjs +93 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/__snapshots__/plugin.test.ts.snap +319 -319
- package/src/__tests__/plugin.test.ts +145 -1
- package/src/helpers/__tests__/profiler.test.ts +49 -0
- package/src/helpers/profiler.ts +30 -1
- package/src/plugin.ts +118 -17
- package/types/helpers/profiler.d.ts +12 -1
- package/types/plugin.d.ts +19 -0
|
@@ -226,14 +226,14 @@ function _create_super(Derived) {
|
|
|
226
226
|
}
|
|
227
227
|
var ProfilerDevtoolsPlugin = function() {
|
|
228
228
|
var dsetAssign = function dsetAssign(obj, keys, value) {
|
|
229
|
-
var
|
|
229
|
+
var merge = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
|
|
230
230
|
var key = keys[keys.length - 1];
|
|
231
231
|
if (key === void 0) throw Error("Unable to assign at path containing undefined keys");
|
|
232
232
|
var _acc_key2;
|
|
233
233
|
var target = keys.slice(0, -1).reduce(function(acc, key2) {
|
|
234
234
|
return (_acc_key2 = acc[key2]) !== null && _acc_key2 !== void 0 ? _acc_key2 : acc[key2] = {};
|
|
235
235
|
}, obj);
|
|
236
|
-
target[key] = deepAssign(target[key], value,
|
|
236
|
+
target[key] = deepAssign(target[key], value, merge);
|
|
237
237
|
};
|
|
238
238
|
var die = function die(error) {
|
|
239
239
|
for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
@@ -580,13 +580,14 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
580
580
|
}
|
|
581
581
|
}
|
|
582
582
|
};
|
|
583
|
-
var dset =
|
|
583
|
+
var dset = // ../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/dset@3.1.4/node_modules/dset/dist/index.mjs
|
|
584
|
+
function dset(obj, keys, val) {
|
|
584
585
|
keys.split && (keys = keys.split("."));
|
|
585
586
|
var i = 0, l = keys.length, t = obj, x, k;
|
|
586
587
|
while(i < l){
|
|
587
588
|
k = "" + keys[i++];
|
|
588
589
|
if (k === "__proto__" || k === "constructor" || k === "prototype") break;
|
|
589
|
-
t = t[k] = i === l ?
|
|
590
|
+
t = t[k] = i === l ? val : _type_of(x = t[k]) === (typeof keys === "undefined" ? "undefined" : _type_of(keys)) ? x : keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".") ? {} : [];
|
|
590
591
|
}
|
|
591
592
|
};
|
|
592
593
|
var __defProp = Object.defineProperty;
|
|
@@ -687,14 +688,14 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
687
688
|
};
|
|
688
689
|
};
|
|
689
690
|
function deepAssign(target, source) {
|
|
690
|
-
var
|
|
691
|
+
var merge = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
|
|
691
692
|
if (Array.isArray(target) && Array.isArray(source)) {
|
|
692
|
-
while(!
|
|
693
|
+
while(!merge && target.length > source.length)target.pop();
|
|
693
694
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
694
695
|
try {
|
|
695
696
|
for(var _iterator = source.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
696
697
|
var _step_value = _sliced_to_array(_step.value, 2), index = _step_value[0], item = _step_value[1];
|
|
697
|
-
target[index] = deepAssign(target[index], item,
|
|
698
|
+
target[index] = deepAssign(target[index], item, merge);
|
|
698
699
|
}
|
|
699
700
|
} catch (err) {
|
|
700
701
|
_didIteratorError = true;
|
|
@@ -713,7 +714,7 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
713
714
|
} else if (target && typeof target === "object" && !Array.isArray(target) && source && typeof source === "object" && !Array.isArray(source)) {
|
|
714
715
|
var record = target;
|
|
715
716
|
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
716
|
-
if (!
|
|
717
|
+
if (!merge) try {
|
|
717
718
|
for(var _iterator1 = Object.keys(target)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
718
719
|
var key = _step1.value;
|
|
719
720
|
if (!(key in source)) delete record[key];
|
|
@@ -736,7 +737,7 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
736
737
|
try {
|
|
737
738
|
for(var _iterator2 = Object.entries(source)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
|
|
738
739
|
var _step_value1 = _sliced_to_array(_step2.value, 2), key1 = _step_value1[0], item1 = _step_value1[1];
|
|
739
|
-
record[key1] = deepAssign(record[key1], item1,
|
|
740
|
+
record[key1] = deepAssign(record[key1], item1, merge);
|
|
740
741
|
}
|
|
741
742
|
} catch (err) {
|
|
742
743
|
_didIteratorError2 = true;
|
|
@@ -1724,7 +1725,7 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
1724
1725
|
rawNodes: []
|
|
1725
1726
|
}
|
|
1726
1727
|
};
|
|
1727
|
-
var PLUGIN_VERSION = true ? "1.0.1-next.
|
|
1728
|
+
var PLUGIN_VERSION = true ? "1.0.1-next.1" : "unstamped";
|
|
1728
1729
|
var _obj;
|
|
1729
1730
|
var ProfilerPluginData = {
|
|
1730
1731
|
id: PLUGIN_ID,
|
|
@@ -1757,23 +1758,6 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
1757
1758
|
}), _obj)
|
|
1758
1759
|
}
|
|
1759
1760
|
};
|
|
1760
|
-
// ../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/dset@3.1.4/node_modules/dset/merge/index.mjs
|
|
1761
|
-
function merge(a, b, k) {
|
|
1762
|
-
if (typeof a === "object" && typeof b === "object") {
|
|
1763
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
1764
|
-
for(k = 0; k < b.length; k++){
|
|
1765
|
-
a[k] = merge(a[k], b[k]);
|
|
1766
|
-
}
|
|
1767
|
-
} else {
|
|
1768
|
-
for(k in b){
|
|
1769
|
-
if (k === "__proto__" || k === "constructor" || k === "prototype") break;
|
|
1770
|
-
a[k] = merge(a[k], b[k]);
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
return a;
|
|
1774
|
-
}
|
|
1775
|
-
return b;
|
|
1776
|
-
}
|
|
1777
1761
|
// ../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/profiler/core/src/helpers/isRecordType.ts
|
|
1778
1762
|
var isRecordType = function(obj) {
|
|
1779
1763
|
return typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
@@ -1792,12 +1776,29 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
1792
1776
|
// ../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/profiler/core/src/helpers/profiler.ts
|
|
1793
1777
|
var Profiler = /*#__PURE__*/ function() {
|
|
1794
1778
|
function Profiler(onUpdate) {
|
|
1779
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1795
1780
|
_class_call_check(this, Profiler);
|
|
1796
1781
|
this.onUpdate = onUpdate;
|
|
1782
|
+
this.options = options;
|
|
1797
1783
|
this.rootNodes = [];
|
|
1798
1784
|
this.stack = [];
|
|
1799
1785
|
}
|
|
1800
1786
|
_create_class(Profiler, [
|
|
1787
|
+
{
|
|
1788
|
+
/** Drop the oldest finished top-level nodes until we are back within `maxRootNodes`. */ key: "trimRootNodes",
|
|
1789
|
+
value: function trimRootNodes() {
|
|
1790
|
+
var maxRootNodes = this.options.maxRootNodes;
|
|
1791
|
+
if (maxRootNodes === void 0) return;
|
|
1792
|
+
var excess = this.rootNodes.length - maxRootNodes;
|
|
1793
|
+
var drop = 0;
|
|
1794
|
+
while(drop < excess && this.rootNodes[drop].endTime !== void 0){
|
|
1795
|
+
drop++;
|
|
1796
|
+
}
|
|
1797
|
+
if (drop > 0) {
|
|
1798
|
+
this.rootNodes.splice(0, drop);
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
},
|
|
1801
1802
|
{
|
|
1802
1803
|
key: "start",
|
|
1803
1804
|
value: function start() {
|
|
@@ -1889,6 +1890,7 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
1889
1890
|
this.stack[this.stack.length - 1].children.push(node);
|
|
1890
1891
|
} else {
|
|
1891
1892
|
this.rootNodes.push(node);
|
|
1893
|
+
this.trimRootNodes();
|
|
1892
1894
|
}
|
|
1893
1895
|
this.stack.push(node);
|
|
1894
1896
|
}
|
|
@@ -2063,6 +2065,9 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
2063
2065
|
};
|
|
2064
2066
|
var pluginData = ProfilerPluginData;
|
|
2065
2067
|
var pluginID = pluginData.id;
|
|
2068
|
+
var MIN_PUBLISH_INTERVAL_MS = 250;
|
|
2069
|
+
var PUBLISH_BACKOFF_FACTOR = 10;
|
|
2070
|
+
var MAX_ROOT_NODES = 1e3;
|
|
2066
2071
|
var ProfilerDevtoolsPlugin = /*#__PURE__*/ function(DevtoolsPlugin) {
|
|
2067
2072
|
_inherits(ProfilerDevtoolsPlugin, DevtoolsPlugin);
|
|
2068
2073
|
var _super = _create_super(ProfilerDevtoolsPlugin);
|
|
@@ -2073,6 +2078,9 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
2073
2078
|
pluginData: pluginData
|
|
2074
2079
|
}));
|
|
2075
2080
|
_this.name = "ProfilerDevtoolsPlugin";
|
|
2081
|
+
/** The profiler tree changed since the last publish */ _this.publishPending = false;
|
|
2082
|
+
/** True while a publish is running, to ignore updates that it triggers itself */ _this.publishing = false;
|
|
2083
|
+
/** Earliest time (Date.now) at which the next publish may run */ _this.nextPublishAt = 0;
|
|
2076
2084
|
_this.interactionMap = /* @__PURE__ */ new Map([
|
|
2077
2085
|
[
|
|
2078
2086
|
INTERACTIONS2.START_PROFILING,
|
|
@@ -2094,36 +2102,91 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
2094
2102
|
]
|
|
2095
2103
|
]);
|
|
2096
2104
|
_this.profilerObj = new Profiler(function() {
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
[
|
|
2101
|
-
"plugins",
|
|
2102
|
-
pluginID,
|
|
2103
|
-
"flow",
|
|
2104
|
-
"data",
|
|
2105
|
-
"rootNode"
|
|
2106
|
-
],
|
|
2107
|
-
transformProfilerData(wrapInRoot(rootNodes))
|
|
2108
|
-
], [
|
|
2109
|
-
[
|
|
2110
|
-
"plugins",
|
|
2111
|
-
pluginID,
|
|
2112
|
-
"flow",
|
|
2113
|
-
"data",
|
|
2114
|
-
"rawNodes"
|
|
2115
|
-
],
|
|
2116
|
-
rootNodes
|
|
2117
|
-
]);
|
|
2118
|
-
_this.store.dispatch(genDataChangeTransaction({
|
|
2119
|
-
playerID: _this.playerID,
|
|
2120
|
-
data: (_newState_plugins_pluginID = newState.plugins[pluginID]) === null || _newState_plugins_pluginID === void 0 ? void 0 : _newState_plugins_pluginID.flow.data,
|
|
2121
|
-
pluginID: pluginID
|
|
2122
|
-
}));
|
|
2105
|
+
return _this.requestPublish();
|
|
2106
|
+
}, {
|
|
2107
|
+
maxRootNodes: MAX_ROOT_NODES
|
|
2123
2108
|
});
|
|
2124
2109
|
return _this;
|
|
2125
2110
|
}
|
|
2126
2111
|
_create_class(ProfilerDevtoolsPlugin, [
|
|
2112
|
+
{
|
|
2113
|
+
/** Clone the recorded tree and send it to devtools. Cost grows with the size of the tree. */ key: "publishSnapshot",
|
|
2114
|
+
value: function publishSnapshot() {
|
|
2115
|
+
var _newState_plugins_pluginID;
|
|
2116
|
+
var rootNodes = this.profilerObj.getSnapshot().rootNodes;
|
|
2117
|
+
var newState = this.produceState([
|
|
2118
|
+
[
|
|
2119
|
+
"plugins",
|
|
2120
|
+
pluginID,
|
|
2121
|
+
"flow",
|
|
2122
|
+
"data",
|
|
2123
|
+
"rootNode"
|
|
2124
|
+
],
|
|
2125
|
+
transformProfilerData(wrapInRoot(rootNodes))
|
|
2126
|
+
], [
|
|
2127
|
+
[
|
|
2128
|
+
"plugins",
|
|
2129
|
+
pluginID,
|
|
2130
|
+
"flow",
|
|
2131
|
+
"data",
|
|
2132
|
+
"rawNodes"
|
|
2133
|
+
],
|
|
2134
|
+
rootNodes
|
|
2135
|
+
]);
|
|
2136
|
+
this.store.dispatch(genDataChangeTransaction({
|
|
2137
|
+
playerID: this.playerID,
|
|
2138
|
+
data: (_newState_plugins_pluginID = newState.plugins[pluginID]) === null || _newState_plugins_pluginID === void 0 ? void 0 : _newState_plugins_pluginID.flow.data,
|
|
2139
|
+
pluginID: pluginID
|
|
2140
|
+
}));
|
|
2141
|
+
}
|
|
2142
|
+
},
|
|
2143
|
+
{
|
|
2144
|
+
/**
|
|
2145
|
+
* The recorded tree changed. Publish it now if we are allowed to, otherwise make sure a single
|
|
2146
|
+
* trailing publish happens once we are, so the latest state is never left unpublished.
|
|
2147
|
+
*/ key: "requestPublish",
|
|
2148
|
+
value: function requestPublish() {
|
|
2149
|
+
var _this = this;
|
|
2150
|
+
this.publishPending = true;
|
|
2151
|
+
if (this.publishing || this.publishTimer !== void 0) return;
|
|
2152
|
+
var wait = this.nextPublishAt - Date.now();
|
|
2153
|
+
if (wait <= 0) {
|
|
2154
|
+
this.flushPublish();
|
|
2155
|
+
} else if (typeof setTimeout === "function") {
|
|
2156
|
+
this.publishTimer = setTimeout(function() {
|
|
2157
|
+
_this.publishTimer = void 0;
|
|
2158
|
+
_this.flushPublish();
|
|
2159
|
+
}, wait);
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
},
|
|
2163
|
+
{
|
|
2164
|
+
/** Publish now if anything changed since the last publish, and set when the next one may run. */ key: "flushPublish",
|
|
2165
|
+
value: function flushPublish() {
|
|
2166
|
+
if (!this.publishPending || this.publishing) return;
|
|
2167
|
+
this.cancelScheduledPublish();
|
|
2168
|
+
this.publishPending = false;
|
|
2169
|
+
this.publishing = true;
|
|
2170
|
+
var start = Date.now();
|
|
2171
|
+
try {
|
|
2172
|
+
this.publishSnapshot();
|
|
2173
|
+
} finally{
|
|
2174
|
+
this.publishing = false;
|
|
2175
|
+
}
|
|
2176
|
+
var end = Date.now();
|
|
2177
|
+
this.nextPublishAt = end + Math.max(MIN_PUBLISH_INTERVAL_MS, PUBLISH_BACKOFF_FACTOR * (end - start));
|
|
2178
|
+
if (this.publishPending) this.requestPublish();
|
|
2179
|
+
}
|
|
2180
|
+
},
|
|
2181
|
+
{
|
|
2182
|
+
key: "cancelScheduledPublish",
|
|
2183
|
+
value: function cancelScheduledPublish() {
|
|
2184
|
+
if (this.publishTimer !== void 0) {
|
|
2185
|
+
clearTimeout(this.publishTimer);
|
|
2186
|
+
this.publishTimer = void 0;
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
},
|
|
2127
2190
|
{
|
|
2128
2191
|
/**
|
|
2129
2192
|
* Produces a new store state with each `[path, value]` pair written into the
|
|
@@ -2146,6 +2209,7 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
2146
2209
|
value: function startProfiler() {
|
|
2147
2210
|
var _newState_plugins_pluginID;
|
|
2148
2211
|
this.profilerObj.start();
|
|
2212
|
+
this.flushPublish();
|
|
2149
2213
|
var newState = produce(this.store.getState(), function(draft) {
|
|
2150
2214
|
dset(draft, [
|
|
2151
2215
|
"plugins",
|
|
@@ -2173,6 +2237,7 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
2173
2237
|
key: "clearProfiler",
|
|
2174
2238
|
value: function clearProfiler() {
|
|
2175
2239
|
this.profilerObj.clear();
|
|
2240
|
+
this.flushPublish();
|
|
2176
2241
|
}
|
|
2177
2242
|
},
|
|
2178
2243
|
{
|
|
@@ -2223,6 +2288,8 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
2223
2288
|
data: (_newState_plugins_pluginID = newState.plugins[pluginID]) === null || _newState_plugins_pluginID === void 0 ? void 0 : _newState_plugins_pluginID.flow.data,
|
|
2224
2289
|
pluginID: pluginID
|
|
2225
2290
|
}));
|
|
2291
|
+
this.publishPending = false;
|
|
2292
|
+
this.cancelScheduledPublish();
|
|
2226
2293
|
return result;
|
|
2227
2294
|
}
|
|
2228
2295
|
},
|
|
@@ -2267,6 +2334,13 @@ var ProfilerDevtoolsPlugin = function() {
|
|
|
2267
2334
|
var type = interaction.payload.type;
|
|
2268
2335
|
(_this_interactionMap_get = this.interactionMap.get(type)) === null || _this_interactionMap_get === void 0 ? void 0 : _this_interactionMap_get();
|
|
2269
2336
|
}
|
|
2337
|
+
},
|
|
2338
|
+
{
|
|
2339
|
+
key: "teardown",
|
|
2340
|
+
value: function teardown() {
|
|
2341
|
+
this.cancelScheduledPublish();
|
|
2342
|
+
_get(_get_prototype_of(ProfilerDevtoolsPlugin.prototype), "teardown", this).call(this);
|
|
2343
|
+
}
|
|
2270
2344
|
}
|
|
2271
2345
|
]);
|
|
2272
2346
|
return ProfilerDevtoolsPlugin;
|