Skip to content

Commit

Permalink
Add performance.memory.jsHeapSizeLimit support (#3928)
Browse files Browse the repository at this point in the history
This value, in combination with the existing `totalJSHeapSize` and
`usedJSHeapSize` values, can help describe memory usage of a webpage.

See the MDN reference:

https://developer.mozilla.org/en-US/docs/Web/API/Performance/memory#value

b/355487905
  • Loading branch information
at-ninja committed Aug 21, 2024
1 parent 0fa8584 commit 5190ee9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
14 changes: 14 additions & 0 deletions cobalt/dom/memory_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ uint32 MemoryInfo::used_js_heap_size(
.used_heap_size);
}

uint32 MemoryInfo::js_heap_size_limit(
script::EnvironmentSettings* environment_settings) const {
if (!environment_settings) {
return 0u;
}
return static_cast<uint32>(
base::polymorphic_downcast<web::EnvironmentSettings*>(
environment_settings)
->context()
->javascript_engine()
->GetHeapStatistics()
.heap_size_limit);
}

uint32 MemoryInfo::media_source_size_limit(
script::EnvironmentSettings* environment_settings) const {
auto memory_info = GetDecoderBufferMemoryInfo(environment_settings);
Expand Down
2 changes: 2 additions & 0 deletions cobalt/dom/memory_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class MemoryInfo : public script::Wrappable {
script::EnvironmentSettings* environment_settings) const;
uint32 used_js_heap_size(
script::EnvironmentSettings* environment_settings) const;
uint32 js_heap_size_limit(
script::EnvironmentSettings* environment_settings) const;
uint32 media_source_size_limit(
script::EnvironmentSettings* environment_settings) const;
uint32 total_media_source_size(
Expand Down
1 change: 1 addition & 0 deletions cobalt/dom/memory_info.idl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
] interface MemoryInfo {
[CallWith=EnvironmentSettings] readonly attribute unsigned long totalJSHeapSize;
[CallWith=EnvironmentSettings] readonly attribute unsigned long usedJSHeapSize;
[CallWith=EnvironmentSettings] readonly attribute unsigned long jsHeapSizeLimit;

[CallWith=EnvironmentSettings] readonly attribute unsigned long mediaSourceSizeLimit;
[CallWith=EnvironmentSettings] readonly attribute unsigned long totalMediaSourceSize;
Expand Down
1 change: 1 addition & 0 deletions cobalt/script/javascript_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class GlobalEnvironment;
struct HeapStatistics {
size_t total_heap_size;
size_t used_heap_size;
size_t heap_size_limit;
};

class JavaScriptEngine {
Expand Down
3 changes: 2 additions & 1 deletion cobalt/script/v8c/v8c_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ HeapStatistics V8cEngine::GetHeapStatistics() {
v8::HeapStatistics v8_heap_statistics;
isolate_->GetHeapStatistics(&v8_heap_statistics);
return {v8_heap_statistics.total_heap_size(),
v8_heap_statistics.used_heap_size()};
v8_heap_statistics.used_heap_size(),
v8_heap_statistics.heap_size_limit()};
}

void V8cEngine::UpdateDateTimeConfiguration() {
Expand Down

0 comments on commit 5190ee9

Please sign in to comment.