Commit 0c588fb6 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

Add V8SharedMemoryDumpProvider to dump shared memory stats

Uses new V8::GetSharedMemoryStatistics API to report stats on shared
memory in V8 (i.e. not per isolate) such as read_only_space's size.

Bug: v8:7464
Change-Id: I139e084c51703dd5cf1239a59128de874aea62c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1905547
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: default avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714262}
parent f63fad52
...@@ -63,6 +63,8 @@ component("gin") { ...@@ -63,6 +63,8 @@ component("gin") {
"v8_isolate_memory_dump_provider.cc", "v8_isolate_memory_dump_provider.cc",
"v8_isolate_memory_dump_provider.h", "v8_isolate_memory_dump_provider.h",
"v8_platform.cc", "v8_platform.cc",
"v8_shared_memory_dump_provider.cc",
"v8_shared_memory_dump_provider.h",
"wrappable.cc", "wrappable.cc",
"wrappable.h", "wrappable.h",
"wrapper_info.cc", "wrapper_info.cc",
...@@ -138,6 +140,7 @@ test("gin_unittests") { ...@@ -138,6 +140,7 @@ test("gin_unittests") {
"test/run_all_unittests.cc", "test/run_all_unittests.cc",
"v8_isolate_memory_dump_provider_unittest.cc", "v8_isolate_memory_dump_provider_unittest.cc",
"v8_platform_unittest.cc", "v8_platform_unittest.cc",
"v8_shared_memory_dump_provider_unittest.cc",
"wrappable_unittest.cc", "wrappable_unittest.cc",
] ]
......
...@@ -23,9 +23,12 @@ ...@@ -23,9 +23,12 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/system/sys_info.h" #include "base/system/sys_info.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/trace_event/memory_dump_manager.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gin/gin_features.h" #include "gin/gin_features.h"
#include "gin/v8_shared_memory_dump_provider.h"
#if defined(V8_USE_EXTERNAL_STARTUP_DATA) #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
...@@ -270,6 +273,10 @@ void V8Initializer::Initialize(IsolateHolder::ScriptMode mode) { ...@@ -270,6 +273,10 @@ void V8Initializer::Initialize(IsolateHolder::ScriptMode mode) {
v8::V8::SetEntropySource(&GenerateEntropy); v8::V8::SetEntropySource(&GenerateEntropy);
v8::V8::Initialize(); v8::V8::Initialize();
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
gin::V8SharedMemoryDumpProvider::Instance(), "V8SharedMemory",
base::ThreadTaskRunnerHandle::Get());
v8_is_initialized = true; v8_is_initialized = true;
} }
......
// 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.
#include "gin/v8_shared_memory_dump_provider.h"
#include <string>
#include "base/memory/singleton.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/process_memory_dump.h"
#include "v8/include/v8.h"
namespace gin {
V8SharedMemoryDumpProvider::V8SharedMemoryDumpProvider() {}
// static
V8SharedMemoryDumpProvider* V8SharedMemoryDumpProvider::Instance() {
return base::Singleton<
V8SharedMemoryDumpProvider,
base::LeakySingletonTraits<V8SharedMemoryDumpProvider>>::get();
}
// Called at trace dump point time. Creates a snapshot with the memory counters
// for the current isolate.
bool V8SharedMemoryDumpProvider::OnMemoryDump(
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* process_memory_dump) {
v8::SharedMemoryStatistics shared_memory_statistics;
v8::V8::GetSharedMemoryStatistics(&shared_memory_statistics);
std::string dump_base_name = "v8/shared";
auto* shared_memory_dump = process_memory_dump->CreateAllocatorDump(
dump_base_name + "/read_only_space");
shared_memory_dump->AddScalar(
base::trace_event::MemoryAllocatorDump::kNameSize,
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
shared_memory_statistics.read_only_space_physical_size());
shared_memory_dump->AddScalar(
"allocated_objects_size",
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
shared_memory_statistics.read_only_space_used_size());
shared_memory_dump->AddScalar(
"virtual_size", base::trace_event::MemoryAllocatorDump::kUnitsBytes,
shared_memory_statistics.read_only_space_size());
return true;
}
} // namespace gin
// 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.
#ifndef GIN_V8_SHARED_MEMORY_DUMP_PROVIDER_H_
#define GIN_V8_SHARED_MEMORY_DUMP_PROVIDER_H_
#include <string>
#include "base/macros.h"
#include "base/trace_event/memory_dump_provider.h"
#include "gin/gin_export.h"
namespace gin {
// Memory dump provider for the chrome://tracing infrastructure. It dumps
// summarized memory stats about V8 Memory shared between Isolates in the same
// process.
class GIN_EXPORT V8SharedMemoryDumpProvider
: public base::trace_event::MemoryDumpProvider {
public:
V8SharedMemoryDumpProvider();
// MemoryDumpProvider implementation.
bool OnMemoryDump(
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* process_memory_dump) override;
static V8SharedMemoryDumpProvider* Instance();
private:
DISALLOW_COPY_AND_ASSIGN(V8SharedMemoryDumpProvider);
};
} // namespace gin
#endif // GIN_V8_SHARED_MEMORY_DUMP_PROVIDER_H_
// 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.
#include "gin/v8_shared_memory_dump_provider.h"
#include <memory>
#include "base/trace_event/process_memory_dump.h"
#include "base/trace_event/trace_event.h"
#include "gin/test/v8_test.h"
namespace gin {
typedef V8Test V8SharedMemoryDumpProviderTest;
// Checks if the dump provider runs without crashing and dumps root objects.
TEST_F(V8SharedMemoryDumpProviderTest, DumpStatistics) {
V8SharedMemoryDumpProvider provider;
base::trace_event::MemoryDumpArgs dump_args = {
base::trace_event::MemoryDumpLevelOfDetail::DETAILED};
std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
new base::trace_event::ProcessMemoryDump(dump_args));
provider.OnMemoryDump(dump_args, process_memory_dump.get());
const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap&
allocator_dumps = process_memory_dump->allocator_dumps();
bool did_dump_shared_memory_stats = false;
bool did_dump_read_only_space = false;
for (const auto& name_dump : allocator_dumps) {
const std::string& name = name_dump.first;
if (name.find("v8/shared") != std::string::npos) {
did_dump_shared_memory_stats = true;
}
if (name.find("v8/shared/read_only_space") != std::string::npos) {
did_dump_read_only_space = true;
}
}
ASSERT_TRUE(did_dump_shared_memory_stats);
ASSERT_TRUE(did_dump_read_only_space);
}
} // namespace gin
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