зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1126880 - FlameGraphUtils should have a cache to avoid duplicating work, r=jsantell
This commit is contained in:
Родитель
f17811e79d
Коммит
d4ea5b902a
|
@ -24,6 +24,7 @@ support-files =
|
||||||
[browser_flame-graph-utils-02.js]
|
[browser_flame-graph-utils-02.js]
|
||||||
[browser_flame-graph-utils-03.js]
|
[browser_flame-graph-utils-03.js]
|
||||||
[browser_flame-graph-utils-04.js]
|
[browser_flame-graph-utils-04.js]
|
||||||
|
[browser_flame-graph-utils-05.js]
|
||||||
[browser_flame-graph-utils-hash.js]
|
[browser_flame-graph-utils-hash.js]
|
||||||
[browser_graphs-01.js]
|
[browser_graphs-01.js]
|
||||||
[browser_graphs-02.js]
|
[browser_graphs-02.js]
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
// Tests that flame graph data is cached, and that the cache may be cleared.
|
||||||
|
|
||||||
|
let {FlameGraphUtils} = Cu.import("resource:///modules/devtools/FlameGraph.jsm", {});
|
||||||
|
|
||||||
|
add_task(function*() {
|
||||||
|
yield promiseTab("about:blank");
|
||||||
|
yield performTest();
|
||||||
|
gBrowser.removeCurrentTab();
|
||||||
|
});
|
||||||
|
|
||||||
|
function* performTest() {
|
||||||
|
let out1 = FlameGraphUtils.createFlameGraphDataFromSamples(TEST_DATA);
|
||||||
|
let out2 = FlameGraphUtils.createFlameGraphDataFromSamples(TEST_DATA);
|
||||||
|
is(out1, out2, "The outputted data is identical.")
|
||||||
|
|
||||||
|
let out3 = FlameGraphUtils.createFlameGraphDataFromSamples(TEST_DATA, { flattenRecursion: true });
|
||||||
|
is(out2, out3, "The outputted data is still identical.");
|
||||||
|
|
||||||
|
FlameGraphUtils.removeFromCache(TEST_DATA);
|
||||||
|
let out4 = FlameGraphUtils.createFlameGraphDataFromSamples(TEST_DATA, { flattenRecursion: true });
|
||||||
|
isnot(out3, out4, "The outputted data is not identical anymore.");
|
||||||
|
}
|
||||||
|
|
||||||
|
let TEST_DATA = [{
|
||||||
|
frames: [{
|
||||||
|
location: "A"
|
||||||
|
}, {
|
||||||
|
location: "A"
|
||||||
|
}, {
|
||||||
|
location: "A"
|
||||||
|
}, {
|
||||||
|
location: "B",
|
||||||
|
}, {
|
||||||
|
location: "B",
|
||||||
|
}, {
|
||||||
|
location: "C"
|
||||||
|
}],
|
||||||
|
time: 50,
|
||||||
|
}];
|
|
@ -856,10 +856,16 @@ const COLOR_PALLETTE = Array.from(Array(PALLETTE_SIZE)).map((_, i) => "hsla" +
|
||||||
* into a format drawable by the FlameGraph.
|
* into a format drawable by the FlameGraph.
|
||||||
*/
|
*/
|
||||||
let FlameGraphUtils = {
|
let FlameGraphUtils = {
|
||||||
|
_cache: new WeakMap(),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a list of samples from the profiler data to something that's
|
* Converts a list of samples from the profiler data to something that's
|
||||||
* drawable by a FlameGraph widget.
|
* drawable by a FlameGraph widget.
|
||||||
*
|
*
|
||||||
|
* The outputted data will be cached, so the next time this method is called
|
||||||
|
* the previous output is returned. If this is undesirable, or should the
|
||||||
|
* options change, use `removeFromCache`.
|
||||||
|
*
|
||||||
* @param array samples
|
* @param array samples
|
||||||
* A list of { time, frames: [{ location }] } objects.
|
* A list of { time, frames: [{ location }] } objects.
|
||||||
* @param object options [optional]
|
* @param object options [optional]
|
||||||
|
@ -876,6 +882,11 @@ let FlameGraphUtils = {
|
||||||
* The flame graph data.
|
* The flame graph data.
|
||||||
*/
|
*/
|
||||||
createFlameGraphDataFromSamples: function(samples, options = {}, out = []) {
|
createFlameGraphDataFromSamples: function(samples, options = {}, out = []) {
|
||||||
|
let cached = this._cache.get(samples);
|
||||||
|
if (cached) {
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
// 1. Create a map of colors to arrays, representing buckets of
|
// 1. Create a map of colors to arrays, representing buckets of
|
||||||
// blocks inside the flame graph pyramid sharing the same style.
|
// blocks inside the flame graph pyramid sharing the same style.
|
||||||
|
|
||||||
|
@ -952,9 +963,18 @@ let FlameGraphUtils = {
|
||||||
out.push({ color, blocks });
|
out.push({ color, blocks });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._cache.set(samples, out);
|
||||||
return out;
|
return out;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the cached flame graph data created for the given source.
|
||||||
|
* @param any source
|
||||||
|
*/
|
||||||
|
removeFromCache: function(source) {
|
||||||
|
this._cache.delete(source);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the provided frame is the same as the next one in a sample.
|
* Checks if the provided frame is the same as the next one in a sample.
|
||||||
*
|
*
|
||||||
|
|
Загрузка…
Ссылка в новой задаче