Commit ed846135 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

Initial implementation of performance.measureMemory API

This adds IDL files and an experimental feature flag for the API.
The implementation simply forwards to v8::Isolate::MeasureMemory.

Bug: 973627

Change-Id: I80ac8b78e81a6fad6b25370b419a0392f6589cee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1796364Reviewed-by: default avatarYoav Weiss <yoavweiss@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703262}
parent c11cb0a8
......@@ -698,6 +698,9 @@ core_dictionary_idl_files =
"mojo/test/mojo_interface_request_event_init.idl",
"page/scrolling/scroll_state_init.idl",
"streams/queuing_strategy_init.idl",
"timing/measure_memory/measure_memory.idl",
"timing/measure_memory/measure_memory_entry.idl",
"timing/measure_memory/measure_memory_options.idl",
"timing/performance_mark_options.idl",
"timing/performance_measure_options.idl",
"timing/performance_observer_init.idl",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://github.com/ulan/javascript-agent-memory/blob/master/explainer.md
// The result of performance.measureMemory().
dictionary MeasureMemory {
required MeasureMemoryEntry total;
MeasureMemoryEntry current;
sequence<MeasureMemoryEntry> other;
};
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://github.com/ulan/javascript-agent-memory/blob/master/explainer.md
// A single entry of performance.measureMemory() result.
dictionary MeasureMemoryEntry {
unsigned long long jsMemoryEstimate;
sequence<unsigned long long> jsMemoryRange;
};
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://github.com/ulan/javascript-agent-memory/blob/master/explainer.md
// Options for performance.measureMemory().
dictionary MeasureMemoryOptions {
boolean detailed;
};
......@@ -37,6 +37,7 @@
#include "base/time/default_tick_clock.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/core/v8/string_or_performance_measure_options.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_object_builder.h"
#include "third_party/blink/renderer/core/dom/document.h"
......@@ -50,6 +51,7 @@
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/timing/largest_contentful_paint.h"
#include "third_party/blink/renderer/core/timing/layout_shift.h"
#include "third_party/blink/renderer/core/timing/measure_memory/measure_memory_options.h"
#include "third_party/blink/renderer/core/timing/performance_element_timing.h"
#include "third_party/blink/renderer/core/timing/performance_event_timing.h"
#include "third_party/blink/renderer/core/timing/performance_long_task_timing.h"
......@@ -141,6 +143,21 @@ MemoryInfo* Performance::memory() const {
return nullptr;
}
ScriptPromise Performance::measureMemory(ScriptState* script_state,
MeasureMemoryOptions* options) const {
v8::Isolate* isolate = script_state->GetIsolate();
v8::Local<v8::Context> context = script_state->GetContext();
v8::Local<v8::Promise> promise;
v8::MaybeLocal<v8::Promise> maybe_promise = isolate->MeasureMemory(
context, options && options->hasDetailed() && options->detailed()
? v8::MeasureMemoryMode::kDetailed
: v8::MeasureMemoryMode::kSummary);
if (!maybe_promise.ToLocal(&promise)) {
return ScriptPromise();
}
return ScriptPromise(script_state, promise);
}
DOMHighResTimeStamp Performance::timeOrigin() const {
DCHECK(!time_origin_.is_null());
return unified_clock_->GetUnixAtZeroMonotonic() +
......
......@@ -62,6 +62,7 @@ class PerformanceMarkOptions;
class ExceptionState;
class LargestContentfulPaint;
class LayoutShift;
class MeasureMemoryOptions;
class MemoryInfo;
class PerformanceElementTiming;
class PerformanceEventTiming;
......@@ -97,6 +98,8 @@ class CORE_EXPORT Performance : public EventTargetWithInlineData {
virtual PerformanceTiming* timing() const;
virtual PerformanceNavigation* navigation() const;
virtual MemoryInfo* memory() const;
virtual ScriptPromise measureMemory(ScriptState*,
MeasureMemoryOptions*) const;
virtual void UpdateLongTaskInstrumentation() {}
......
......@@ -80,6 +80,8 @@ interface Performance : EventTarget {
// https://groups.google.com/a/chromium.org/d/msg/blink-dev/g5YRCGpC9vs/b4OJz71NmPwJ
[Exposed=Window, Measure] readonly attribute MemoryInfo memory;
[Exposed=(Window,Worker), CallWith=ScriptState, RuntimeEnabled=MeasureMemory] Promise<MeasureMemory> measureMemory(optional MeasureMemoryOptions options);
// JS Self-Profiling API
// https://github.com/WICG/js-self-profiling/
[MeasureAs=JSSelfProfiling, CallWith=ScriptState, RuntimeEnabled=ExperimentalJSProfiler, RaisesException] Promise<Profiler> profile(ProfilerInitOptions options);
......
......@@ -911,6 +911,10 @@
name:"ManualSlotting",
status:"experimental",
},
{
name:"MeasureMemory",
status:"experimental",
},
{
name: "MediaCapabilitiesEncodingInfo",
status: "experimental",
......
# Tentative tests for performance.measureMemory API
Tests in this directory are for the proposed performance.measureMemory API.
This is not yet standardised and browsers should not be expected to pass
these tests.
See the explainer at
https://github.com/ulan/javascript-agent-memory/blob/master/explainer.md
for more information about the API.
function checkMeasureMemoryResultSummary(result) {
assert_own_property(result, "total");
assert_own_property(result.total, "jsMemoryEstimate");
assert_own_property(result.total, "jsMemoryRange");
assert_equals(result.total.jsMemoryRange.length, 2);
assert_greater_than_equal(
result.total.jsMemoryRange[1],
result.total.jsMemoryRange[0]);
assert_greater_than_equal(
result.total.jsMemoryEstimate,
result.total.jsMemoryRange[0]);
assert_greater_than_equal(
result.total.jsMemoryRange[1],
result.total.jsMemoryEstimate);
}
promise_test(async testCase => {
let result = await performance.measureMemory();
checkMeasureMemoryResultSummary(result);
}, 'Well-formed result of performance.measureMemory with default arguments.');
promise_test(async testcase => {
let result = await performance.measureMemory({detailed: false});
checkMeasureMemoryResultSummary(result);
}, 'well-formed result of performance.measurememory with detailed=false.');
......@@ -11,6 +11,7 @@ window.performance.getEntriesByName [function]
window.performance.getEntriesByType [function]
window.performance.mark [function]
window.performance.measure [function]
window.performance.measureMemory [function]
window.performance.memory [object MemoryInfo]
window.performance.memory.jsHeapSizeLimit [number]
window.performance.memory.totalJSHeapSize [number]
......
......@@ -1079,6 +1079,7 @@ interface Performance : EventTarget
method getEntriesByType
method mark
method measure
method measureMemory
method now
method profile
method setResourceTimingBufferSize
......
......@@ -1028,6 +1028,7 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method getEntriesByType
[Worker] method mark
[Worker] method measure
[Worker] method measureMemory
[Worker] method now
[Worker] method profile
[Worker] method setResourceTimingBufferSize
......
......@@ -5626,6 +5626,7 @@ interface Performance : EventTarget
method getEntriesByType
method mark
method measure
method measureMemory
method now
method profile
method setResourceTimingBufferSize
......
......@@ -1010,6 +1010,7 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method getEntriesByType
[Worker] method mark
[Worker] method measure
[Worker] method measureMemory
[Worker] method now
[Worker] method profile
[Worker] method setResourceTimingBufferSize
......
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