Commit 0edfddf2 authored by Nicolas Pena's avatar Nicolas Pena Committed by Commit Bot

Do not return heap size if there are multiple tabs in the same process

This CL changes MemoryInfo so that, when the heap statistics are calculated, the
values for totalJSHeapSize and usedJSHeapSize are not used if the number of
pages is greater than 1.

Bug: 807651
Change-Id: I99bc52e0e2cb8e17c797fdb3868110fc409ad00e
Reviewed-on: https://chromium-review.googlesource.com/904972Reviewed-by: default avatarTimothy Dresser <tdresser@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536755}
parent 864dabc9
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "core/frame/LocalFrame.h" #include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h" #include "core/frame/Settings.h"
#include "core/page/Page.h"
#include "platform/runtime_enabled_features.h" #include "platform/runtime_enabled_features.h"
#include "platform/wtf/MathExtras.h" #include "platform/wtf/MathExtras.h"
#include "platform/wtf/ThreadSpecific.h" #include "platform/wtf/ThreadSpecific.h"
...@@ -48,9 +49,14 @@ static const double kTwentyMinutesInSeconds = 20 * 60; ...@@ -48,9 +49,14 @@ static const double kTwentyMinutesInSeconds = 20 * 60;
static void GetHeapSize(HeapInfo& info) { static void GetHeapSize(HeapInfo& info) {
v8::HeapStatistics heap_statistics; v8::HeapStatistics heap_statistics;
v8::Isolate::GetCurrent()->GetHeapStatistics(&heap_statistics); v8::Isolate::GetCurrent()->GetHeapStatistics(&heap_statistics);
info.js_heap_size_limit = heap_statistics.heap_size_limit();
// If there are multiple tabs from this renderer, do not report used and total
// js heap size.
if (Page::OrdinaryPages().size() > 1u)
return;
info.used_js_heap_size = heap_statistics.used_heap_size(); info.used_js_heap_size = heap_statistics.used_heap_size();
info.total_js_heap_size = heap_statistics.total_physical_size(); info.total_js_heap_size = heap_statistics.total_physical_size();
info.js_heap_size_limit = heap_statistics.heap_size_limit();
} }
class HeapSizeCache { class HeapSizeCache {
...@@ -86,9 +92,16 @@ class HeapSizeCache { ...@@ -86,9 +92,16 @@ class HeapSizeCache {
void Update() { void Update() {
GetHeapSize(info_); GetHeapSize(info_);
info_.used_js_heap_size = QuantizeMemorySize(info_.used_js_heap_size);
info_.total_js_heap_size = QuantizeMemorySize(info_.total_js_heap_size);
info_.js_heap_size_limit = QuantizeMemorySize(info_.js_heap_size_limit); info_.js_heap_size_limit = QuantizeMemorySize(info_.js_heap_size_limit);
DCHECK(info_.used_js_heap_size.has_value() ==
info_.total_js_heap_size.has_value());
if (!info_.used_js_heap_size.has_value())
return;
info_.used_js_heap_size =
QuantizeMemorySize(info_.used_js_heap_size.value());
info_.total_js_heap_size =
QuantizeMemorySize(info_.total_js_heap_size.value());
} }
double last_update_time_; double last_update_time_;
...@@ -156,4 +169,22 @@ MemoryInfo::MemoryInfo() { ...@@ -156,4 +169,22 @@ MemoryInfo::MemoryInfo() {
HeapSizeCache::ForCurrentThread().GetCachedHeapSize(info_); HeapSizeCache::ForCurrentThread().GetCachedHeapSize(info_);
} }
size_t MemoryInfo::totalJSHeapSize(bool& is_null) const {
if (!info_.total_js_heap_size.has_value()) {
is_null = true;
return 0;
}
is_null = false;
return info_.total_js_heap_size.value();
}
size_t MemoryInfo::usedJSHeapSize(bool& is_null) const {
if (!info_.used_js_heap_size.has_value()) {
is_null = true;
return 0;
}
is_null = false;
return info_.used_js_heap_size.value();
}
} // namespace blink } // namespace blink
...@@ -35,16 +35,16 @@ ...@@ -35,16 +35,16 @@
#include "platform/bindings/ScriptWrappable.h" #include "platform/bindings/ScriptWrappable.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "platform/wtf/Allocator.h" #include "platform/wtf/Allocator.h"
#include "platform/wtf/Optional.h"
namespace blink { namespace blink {
struct HeapInfo { struct HeapInfo {
DISALLOW_NEW(); DISALLOW_NEW();
HeapInfo() HeapInfo() : js_heap_size_limit(0) {}
: used_js_heap_size(0), total_js_heap_size(0), js_heap_size_limit(0) {}
size_t used_js_heap_size; Optional<size_t> used_js_heap_size;
size_t total_js_heap_size; Optional<size_t> total_js_heap_size;
size_t js_heap_size_limit; size_t js_heap_size_limit;
}; };
...@@ -54,8 +54,8 @@ class CORE_EXPORT MemoryInfo final : public ScriptWrappable { ...@@ -54,8 +54,8 @@ class CORE_EXPORT MemoryInfo final : public ScriptWrappable {
public: public:
static MemoryInfo* Create() { return new MemoryInfo(); } static MemoryInfo* Create() { return new MemoryInfo(); }
size_t totalJSHeapSize() const { return info_.total_js_heap_size; } size_t totalJSHeapSize(bool& is_null) const;
size_t usedJSHeapSize() const { return info_.used_js_heap_size; } size_t usedJSHeapSize(bool& is_null) const;
size_t jsHeapSizeLimit() const { return info_.js_heap_size_limit; } size_t jsHeapSizeLimit() const { return info_.js_heap_size_limit; }
private: private:
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
[ [
NoInterfaceObject NoInterfaceObject
] interface MemoryInfo { ] interface MemoryInfo {
[Measure] readonly attribute unsigned long totalJSHeapSize; [Measure] readonly attribute unsigned long? totalJSHeapSize;
[Measure] readonly attribute unsigned long usedJSHeapSize; [Measure] readonly attribute unsigned long? usedJSHeapSize;
[Measure] readonly attribute unsigned long jsHeapSizeLimit; [Measure] readonly attribute unsigned long jsHeapSizeLimit;
}; };
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include "core/timing/MemoryInfo.h" #include "core/timing/MemoryInfo.h"
#include "core/page/Page.h"
#include "core/testing/DummyPageHolder.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace blink { namespace blink {
...@@ -53,4 +55,38 @@ TEST(MemoryInfo, quantizeMemorySize) { ...@@ -53,4 +55,38 @@ TEST(MemoryInfo, quantizeMemorySize) {
EXPECT_EQ(10000000u, QuantizeMemorySize(0)); EXPECT_EQ(10000000u, QuantizeMemorySize(0));
} }
TEST(MemoryInfo, nullableValues) {
RuntimeEnabledFeatures::SetPreciseMemoryInfoEnabled(true);
// Having a single page, MemoryInfo provides all values.
std::unique_ptr<DummyPageHolder> page_holder = DummyPageHolder::Create();
Page::OrdinaryPages().insert(&page_holder->GetPage());
Persistent<MemoryInfo> info(MemoryInfo::Create());
bool is_null;
EXPECT_LT(0U, info->totalJSHeapSize(is_null));
EXPECT_FALSE(is_null);
EXPECT_LT(0U, info->usedJSHeapSize(is_null));
EXPECT_FALSE(is_null);
EXPECT_LT(0U, info->jsHeapSizeLimit());
// Now two pages total. MemoryInfo should only provide jsHeapSizeLimit.
std::unique_ptr<DummyPageHolder> other_page_holder =
DummyPageHolder::Create();
Page::OrdinaryPages().insert(&other_page_holder->GetPage());
info = MemoryInfo::Create();
EXPECT_EQ(0U, info->totalJSHeapSize(is_null));
EXPECT_TRUE(is_null);
EXPECT_EQ(0U, info->usedJSHeapSize(is_null));
EXPECT_TRUE(is_null);
EXPECT_LT(0U, info->jsHeapSizeLimit());
// Remove both pages. MemoryInfo should now provide all values.
Page::OrdinaryPages().clear();
info = MemoryInfo::Create();
EXPECT_LT(0U, info->totalJSHeapSize(is_null));
EXPECT_FALSE(is_null);
EXPECT_LT(0U, info->usedJSHeapSize(is_null));
EXPECT_FALSE(is_null);
EXPECT_LT(0U, info->jsHeapSizeLimit());
}
} // namespace blink } // namespace blink
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