Skip to content

Commit

Permalink
Adds code_and_metadata_size statistics when collecting v8 heap statis…
Browse files Browse the repository at this point in the history
…tics.

To measure the overall size of code along with its metadata, we add
a new category called code_and_metadata_size. This data is collected by
scanning the heap for code/bytecode objects. V8 exposes an explicit API
to obtain this data. It should be used with caution as it could be slow.
It involves scanning the heap to collect this data. This data is collected
only when memory-infra.v8.code_stats is enabled.

BUG=v8:4280
LOG=N

Review-Url: https://codereview.chromium.org/1929523002
Cr-Commit-Position: refs/heads/master@{#397706}
  • Loading branch information
mythrialle authored and Commit bot committed Jun 3, 2016
1 parent 7985b74 commit 3554066
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion gin/v8_isolate_memory_dump_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,43 @@ bool V8IsolateMemoryDumpProvider::OnMemoryDump(
return true;
}

namespace {

// Dump statistics related to code/bytecode when memory-infra.v8.code_stats is
// enabled.
void DumpCodeStatistics(
base::trace_event::MemoryAllocatorDump* heap_spaces_dump,
IsolateHolder* isolate_holder) {
// Collecting code statistics is an expensive operation (~10 ms) when
// compared to other v8 metrics (< 1 ms). So, dump them only when
// memory-infra.v8.code_stats is enabled.
// TODO(primiano): This information should be plumbed through TraceConfig.
// See crbug.com/616441.
bool dump_code_stats = false;
TRACE_EVENT_CATEGORY_GROUP_ENABLED(
TRACE_DISABLED_BY_DEFAULT("memory-infra.v8.code_stats"),
&dump_code_stats);
if (!dump_code_stats)
return;

v8::HeapCodeStatistics code_statistics;
if (!isolate_holder->isolate()->GetHeapCodeAndMetadataStatistics(
&code_statistics)) {
return;
}

heap_spaces_dump->AddScalar(
"code_and_metadata_size",
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
code_statistics.code_and_metadata_size());
heap_spaces_dump->AddScalar(
"bytecode_and_metadata_size",
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
code_statistics.bytecode_and_metadata_size());
}

} // namespace anonymous

void V8IsolateMemoryDumpProvider::DumpHeapStatistics(
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* process_memory_dump) {
Expand Down Expand Up @@ -131,6 +168,11 @@ void V8IsolateMemoryDumpProvider::DumpHeapStatistics(
system_allocator_name);
}

// Add an empty row for the heap_spaces. This is to keep the shape of the
// dump stable, whether code stats are enabled or not.
auto heap_spaces_dump =
process_memory_dump->CreateAllocatorDump(space_name_prefix);

// Dump object statistics only for detailed dumps.
if (args.level_of_detail !=
base::trace_event::MemoryDumpLevelOfDetail::DETAILED) {
Expand Down Expand Up @@ -179,8 +221,11 @@ void V8IsolateMemoryDumpProvider::DumpHeapStatistics(
if (did_dump_object_stats) {
process_memory_dump->AddOwnershipEdge(
process_memory_dump->CreateAllocatorDump(object_name_prefix)->guid(),
process_memory_dump->CreateAllocatorDump(space_name_prefix)->guid());
heap_spaces_dump->guid());
}

// Dump statistics related to code and bytecode if requested.
DumpCodeStatistics(heap_spaces_dump, isolate_holder_);
}

} // namespace gin

0 comments on commit 3554066

Please sign in to comment.