Commit 5856879b authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Chromium LUCI CQ

Update performance.measureMemory to the latest spec

The result of a memory measurement now:
- includes an empty breakdown entry.
- has random order of breakdown entryies.

Bug: chromium:1085129
Change-Id: Ie3f338d8274a0276d09f732560ed9797f5c376af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2607339
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: default avatarNicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841002}
parent c41222f8
......@@ -4,6 +4,8 @@
#include "third_party/blink/renderer/core/timing/measure_memory/measure_memory_controller.h"
#include <algorithm>
#include "base/rand_util.h"
#include "components/performance_manager/public/mojom/coordination_unit.mojom-blink.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/platform/platform.h"
......@@ -112,6 +114,19 @@ bool MeasureMemoryController::IsMeasureMemoryAvailable(LocalDOMWindow* window) {
namespace {
// Satisfies the requirements of UniformRandomBitGenerator from C++ standard.
// It is used in std::shuffle calls below.
struct RandomBitGenerator {
using result_type = size_t;
static constexpr size_t min() { return 0; }
static constexpr size_t max() {
return static_cast<size_t>(std::numeric_limits<int>::max());
}
size_t operator()() {
return static_cast<size_t>(base::RandInt(min(), max()));
}
};
// These functions convert WebMemory* mojo structs to IDL and JS values.
WTF::String ConvertScope(WebMemoryAttribution::Scope scope) {
using Scope = WebMemoryAttribution::Scope;
......@@ -141,7 +156,15 @@ MemoryBreakdownEntry* ConvertBreakdown(
attribution.push_back(ConvertAttribution(entry));
}
result->setAttribution(attribution);
result->setUserAgentSpecificTypes(Vector<String>());
result->setUserAgentSpecificTypes({});
return result;
}
MemoryBreakdownEntry* EmptyBreakdown() {
auto* result = MemoryBreakdownEntry::Create();
result->setBytes(0);
result->setAttribution({});
result->setUserAgentSpecificTypes({});
return result;
}
......@@ -150,6 +173,11 @@ MemoryMeasurement* ConvertResult(const WebMemoryMeasurementPtr& measurement) {
for (const auto& entry : measurement->breakdown) {
breakdown.push_back(ConvertBreakdown(entry));
}
// Add an empty breakdown entry as required by the spec.
// See https://github.com/WICG/performance-measure-memory/issues/10.
breakdown.push_back(EmptyBreakdown());
// Randomize the order of the entries as required by the spec.
std::shuffle(breakdown.begin(), breakdown.end(), RandomBitGenerator{});
size_t bytes = 0;
for (auto entry : breakdown) {
bytes += entry->bytes();
......
......@@ -3157,6 +3157,7 @@ crbug.com/1050754 external/wpt/measure-memory/window-open.cross-origin.tentative
crbug.com/1050754 external/wpt/measure-memory/window-open.cross-site.tentative.https.window.html [ Failure ]
crbug.com/1050754 external/wpt/measure-memory/window-open.mix.tentative.https.window.html [ Failure Timeout ]
crbug.com/1050754 external/wpt/measure-memory/window-open.same-origin.tentative.https.window.html [ Failure ]
crbug.com/1050754 external/wpt/measure-memory/randomized-breakdown.tentative.https.window.html [ Failure ]
crbug.com/1050754 external/wpt/media-capabilities/decodingInfo.any.html [ Failure ]
crbug.com/1050754 external/wpt/media-capabilities/decodingInfo.any.worker.html [ Failure ]
crbug.com/1050754 external/wpt/media-capabilities/encodingInfo.html [ Failure Pass ]
......
......@@ -3137,6 +3137,7 @@ crbug.com/1050754 external/wpt/measure-memory/window-open.cross-origin.tentative
crbug.com/1050754 external/wpt/measure-memory/window-open.cross-site.tentative.https.window.html [ Failure ]
crbug.com/1050754 external/wpt/measure-memory/window-open.mix.tentative.https.window.html [ Failure Timeout ]
crbug.com/1050754 external/wpt/measure-memory/window-open.same-origin.tentative.https.window.html [ Failure ]
crbug.com/1050754 external/wpt/measure-memory/randomized-breakdown.tentative.https.window.html [ Failure ]
crbug.com/1050754 external/wpt/media-capabilities/decodingInfo.any.html [ Failure ]
crbug.com/1050754 external/wpt/media-capabilities/decodingInfo.any.worker.html [ Failure ]
crbug.com/1050754 external/wpt/media-capabilities/encodingInfo.html [ Failure ]
......
......@@ -3384,6 +3384,7 @@ crbug.com/1050754 external/wpt/measure-memory/window-open.cross-origin.tentative
crbug.com/1050754 external/wpt/measure-memory/window-open.cross-site.tentative.https.window.html [ Failure ]
crbug.com/1050754 external/wpt/measure-memory/window-open.mix.tentative.https.window.html [ Failure Timeout ]
crbug.com/1050754 external/wpt/measure-memory/window-open.same-origin.tentative.https.window.html [ Failure ]
crbug.com/1050754 external/wpt/measure-memory/randomized-breakdown.tentative.https.window.html [ Failure ]
crbug.com/1050754 external/wpt/media-capabilities/decodingInfo.any.html [ Failure ]
crbug.com/1050754 external/wpt/media-capabilities/decodingInfo.any.worker.html [ Failure ]
crbug.com/1050754 external/wpt/media-capabilities/encodingInfo.html [ Failure ]
......
// META: script=/common/get-host-info.sub.js
// META: script=./resources/common.js
// META: timeout=long
'use strict';
function indexOfEmptyEntry(result) {
return result.breakdown.findIndex(isEmptyBreakdownEntry);
}
assert_true(self.crossOriginIsolated);
promise_test(async testCase => {
const initial = await performance.measureMemory();
let observed_different_order = false;
for (let i = 0; i < 100; ++i) {
const current = await performance.measureMemory();
if (indexOfEmptyEntry(initial) != indexOfEmptyEntry(current)) {
observed_different_order = true;
}
}
// The order of the breakdown entries must be randomized.
// A conforming implementation may fail the following assert with
// the probability of at most 2^-100 since there are at least two
// entries in the breakdown.
assert_true(observed_different_order);
}, 'Well-formed result of performance.measureMemory.');
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
\ No newline at end of file
......@@ -39,6 +39,11 @@ function checkBreakdown(breakdown, expected) {
}
}
function isEmptyBreakdownEntry(entry) {
return entry.bytes === 0 && entry.attribution.length === 0 &&
entry.userAgentSpecificTypes.length === 0;
}
function checkMeasureMemory(result, expected) {
assert_own_property(result, 'bytes');
assert_own_property(result, 'breakdown');
......@@ -54,6 +59,8 @@ function checkMeasureMemory(result, expected) {
JSON.stringify(e) + ' did not appear in the result.');
}
}
assert_true(result.breakdown.some(isEmptyBreakdownEntry),
'The result must include an empty breakdown entry.');
}
function url(params) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment