From f5594f50ac61564cc9cd6062ad5042c4f90a466b Mon Sep 17 00:00:00 2001 From: Jakob Gruber Date: Wed, 28 Apr 2021 08:11:14 +0200 Subject: [PATCH] [snapshot] Fix the Memory.json benchmark .. which traces various stats (time, memory) related to the snapshot. Due to various flag shuffles, it was broken as of Oct 2020, with some line items reporting constant 0. This also refactors --profile-deserialization and --serialization-statistics s.t. the former only reports deserialization times and the latter reports memory. Memory.json now passes both flags. Change-Id: I7dacbbbe9f7a667e0802d0f7a44703dc34524a4e Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2854742 Auto-Submit: Jakob Gruber Commit-Queue: Leszek Swirski Reviewed-by: Leszek Swirski Cr-Commit-Position: refs/heads/master@{#74241} --- src/runtime/runtime-debug.cc | 2 +- src/snapshot/embedded/embedded-data.cc | 5 ++--- src/snapshot/mksnapshot.cc | 2 +- src/snapshot/snapshot.cc | 15 ++++++++++----- test/memory/Memory.json | 3 ++- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/runtime/runtime-debug.cc b/src/runtime/runtime-debug.cc index d7390c29ba..db36b017f8 100644 --- a/src/runtime/runtime-debug.cc +++ b/src/runtime/runtime-debug.cc @@ -897,7 +897,7 @@ RUNTIME_FUNCTION(Runtime_ProfileCreateSnapshotDataBlob) { // Used only by the test/memory/Memory.json benchmark. This creates a snapshot // blob and outputs various statistics around it. - DCHECK(FLAG_profile_deserialization); + DCHECK(FLAG_profile_deserialization && FLAG_serialization_statistics); DisableEmbeddedBlobRefcounting(); diff --git a/src/snapshot/embedded/embedded-data.cc b/src/snapshot/embedded/embedded-data.cc index 2fac12b6f9..fb3883a410 100644 --- a/src/snapshot/embedded/embedded-data.cc +++ b/src/snapshot/embedded/embedded-data.cc @@ -459,10 +459,9 @@ void EmbeddedData::PrintStatistics() const { const int k99th = kCount * 0.99; PrintF("EmbeddedData:\n"); - PrintF(" Total size: %d\n", + PrintF(" Total size: %d\n", static_cast(code_size() + data_size())); - PrintF(" Data size: %d\n", - static_cast(data_size())); + PrintF(" Data size: %d\n", static_cast(data_size())); PrintF(" Code size: %d\n", static_cast(code_size())); PrintF(" Instruction size (50th percentile): %d\n", sizes[k50th]); PrintF(" Instruction size (75th percentile): %d\n", sizes[k75th]); diff --git a/src/snapshot/mksnapshot.cc b/src/snapshot/mksnapshot.cc index 68483e2660..9a1e988bf8 100644 --- a/src/snapshot/mksnapshot.cc +++ b/src/snapshot/mksnapshot.cc @@ -155,7 +155,7 @@ v8::StartupData CreateSnapshotDataBlob(v8::Isolate* isolate, isolate); if (i::FLAG_profile_deserialization) { - i::PrintF("Creating snapshot took %0.3f ms\n", + i::PrintF("[Creating snapshot took %0.3f ms]\n", timer.Elapsed().InMillisecondsF()); } diff --git a/src/snapshot/snapshot.cc b/src/snapshot/snapshot.cc index b6d2566b95..852ef4c064 100644 --- a/src/snapshot/snapshot.cc +++ b/src/snapshot/snapshot.cc @@ -358,7 +358,7 @@ v8::StartupData Snapshot::Create( context_serializer.Serialize(&contexts->at(i), no_gc); can_be_rehashed = can_be_rehashed && context_serializer.can_be_rehashed(); context_snapshots.push_back(new SnapshotData(&context_serializer)); - if (FLAG_profile_deserialization) { + if (FLAG_serialization_statistics) { context_allocation_sizes.push_back( context_serializer.TotalAllocationSize()); } @@ -372,15 +372,19 @@ v8::StartupData Snapshot::Create( read_only_serializer.FinalizeSerialization(); can_be_rehashed = can_be_rehashed && read_only_serializer.can_be_rehashed(); - if (FLAG_profile_deserialization) { + if (FLAG_serialization_statistics) { // These prints should match the regexp in test/memory/Memory.json + DCHECK_NE(read_only_serializer.TotalAllocationSize(), 0); + DCHECK_NE(startup_serializer.TotalAllocationSize(), 0); PrintF("Deserialization will allocate:\n"); PrintF("%10d bytes per isolate\n", read_only_serializer.TotalAllocationSize() + startup_serializer.TotalAllocationSize()); for (int i = 0; i < num_contexts; i++) { + DCHECK_NE(context_allocation_sizes[i], 0); PrintF("%10d bytes per context #%d\n", context_allocation_sizes[i], i); } + PrintF("\n"); } SnapshotData read_only_snapshot(&read_only_serializer); @@ -469,7 +473,7 @@ v8::StartupData SnapshotImpl::CreateSnapshotBlob( CopyBytes(data + payload_offset, reinterpret_cast(startup_snapshot->RawData().begin()), payload_length); - if (FLAG_profile_deserialization) { + if (FLAG_serialization_statistics) { PrintF("Snapshot blob consists of:\n%10d bytes for startup\n", payload_length); } @@ -483,7 +487,7 @@ v8::StartupData SnapshotImpl::CreateSnapshotBlob( data + payload_offset, reinterpret_cast(read_only_snapshot->RawData().begin()), payload_length); - if (FLAG_profile_deserialization) { + if (FLAG_serialization_statistics) { PrintF("%10d bytes for read-only\n", payload_length); } payload_offset += payload_length; @@ -498,11 +502,12 @@ v8::StartupData SnapshotImpl::CreateSnapshotBlob( data + payload_offset, reinterpret_cast(context_snapshot->RawData().begin()), payload_length); - if (FLAG_profile_deserialization) { + if (FLAG_serialization_statistics) { PrintF("%10d bytes for context #%d\n", payload_length, i); } payload_offset += payload_length; } + if (FLAG_serialization_statistics) PrintF("\n"); DCHECK_EQ(total_length, payload_offset); v8::StartupData result = {data, static_cast(total_length)}; diff --git a/test/memory/Memory.json b/test/memory/Memory.json index f2b362768b..77be23c1a0 100644 --- a/test/memory/Memory.json +++ b/test/memory/Memory.json @@ -6,7 +6,8 @@ "resources": ["run.js"], "main": "run.js", "path": ["."], - "flags": ["--allow-natives-syntax", "--profile-deserialization"], + "flags": ["--allow-natives-syntax", "--profile-deserialization", + "--serialization-statistics"], "tests": [ { "name": "ReservedMemoryIsolate",