diff --git a/include/v8-profiler.h b/include/v8-profiler.h index 8f380f2094..5f560c37ea 100644 --- a/include/v8-profiler.h +++ b/include/v8-profiler.h @@ -448,11 +448,12 @@ class V8EXPORT HeapProfiler { * reports updates for all previous time intervals via the OutputStream * object. Updates on each time interval are provided as a stream of the * HeapStatsUpdate structure instances. + * The return value of the function is the last seen heap object Id. * * StartHeapObjectsTracking must be called before the first call to this * method. */ - static void PushHeapObjectsStats(OutputStream* stream); + static SnapshotObjectId PushHeapObjectsStats(OutputStream* stream); /** * Stops tracking of heap objects population statistics, cleans up all diff --git a/src/api.cc b/src/api.cc index 74886f0085..6f38ba7491 100644 --- a/src/api.cc +++ b/src/api.cc @@ -6229,7 +6229,7 @@ void HeapProfiler::StopHeapObjectsTracking() { } -void HeapProfiler::PushHeapObjectsStats(OutputStream* stream) { +SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) { i::Isolate* isolate = i::Isolate::Current(); IsDeadCheck(isolate, "v8::HeapProfiler::PushHeapObjectsStats"); return i::HeapProfiler::PushHeapObjectsStats(stream); diff --git a/src/heap-profiler.cc b/src/heap-profiler.cc index 2e971a51b4..975d6f4221 100644 --- a/src/heap-profiler.cc +++ b/src/heap-profiler.cc @@ -97,7 +97,7 @@ void HeapProfiler::StopHeapObjectsTracking() { } -void HeapProfiler::PushHeapObjectsStats(v8::OutputStream* stream) { +SnapshotObjectId HeapProfiler::PushHeapObjectsStats(v8::OutputStream* stream) { ASSERT(Isolate::Current()->heap_profiler() != NULL); return Isolate::Current()->heap_profiler()->PushHeapObjectsStatsImpl(stream); } @@ -158,8 +158,8 @@ void HeapProfiler::StartHeapObjectsTrackingImpl() { } -void HeapProfiler::PushHeapObjectsStatsImpl(OutputStream* stream) { - snapshots_->PushHeapObjectsStats(stream); +SnapshotObjectId HeapProfiler::PushHeapObjectsStatsImpl(OutputStream* stream) { + return snapshots_->PushHeapObjectsStats(stream); } diff --git a/src/heap-profiler.h b/src/heap-profiler.h index 96b042d3cb..4a811573ac 100644 --- a/src/heap-profiler.h +++ b/src/heap-profiler.h @@ -58,7 +58,7 @@ class HeapProfiler { static void StartHeapObjectsTracking(); static void StopHeapObjectsTracking(); - static void PushHeapObjectsStats(OutputStream* stream); + static SnapshotObjectId PushHeapObjectsStats(OutputStream* stream); static int GetSnapshotsCount(); static HeapSnapshot* GetSnapshot(int index); static HeapSnapshot* FindSnapshot(unsigned uid); @@ -89,7 +89,7 @@ class HeapProfiler { void StartHeapObjectsTrackingImpl(); void StopHeapObjectsTrackingImpl(); - void PushHeapObjectsStatsImpl(OutputStream* stream); + SnapshotObjectId PushHeapObjectsStatsImpl(OutputStream* stream); HeapSnapshotsCollection* snapshots_; unsigned next_snapshot_uid_; diff --git a/src/profile-generator.cc b/src/profile-generator.cc index 0fe7499d70..69ef082dce 100644 --- a/src/profile-generator.cc +++ b/src/profile-generator.cc @@ -1357,7 +1357,7 @@ void HeapObjectsMap::UpdateHeapObjectsMap() { } -void HeapObjectsMap::PushHeapObjectsStats(OutputStream* stream) { +SnapshotObjectId HeapObjectsMap::PushHeapObjectsStats(OutputStream* stream) { UpdateHeapObjectsMap(); time_intervals_.Add(TimeInterval(next_id_)); int prefered_chunk_size = stream->GetChunkSize(); @@ -1387,7 +1387,7 @@ void HeapObjectsMap::PushHeapObjectsStats(OutputStream* stream) { if (stats_buffer.length() >= prefered_chunk_size) { OutputStream::WriteResult result = stream->WriteHeapStatsChunk( &stats_buffer.first(), stats_buffer.length()); - if (result == OutputStream::kAbort) return; + if (result == OutputStream::kAbort) return last_assigned_id(); stats_buffer.Clear(); } } @@ -1396,9 +1396,10 @@ void HeapObjectsMap::PushHeapObjectsStats(OutputStream* stream) { if (!stats_buffer.is_empty()) { OutputStream::WriteResult result = stream->WriteHeapStatsChunk( &stats_buffer.first(), stats_buffer.length()); - if (result == OutputStream::kAbort) return; + if (result == OutputStream::kAbort) return last_assigned_id(); } stream->EndOfStream(); + return last_assigned_id(); } diff --git a/src/profile-generator.h b/src/profile-generator.h index 349226b43f..6388985d40 100644 --- a/src/profile-generator.h +++ b/src/profile-generator.h @@ -649,7 +649,7 @@ class HeapObjectsMap { } void StopHeapObjectsTracking(); - void PushHeapObjectsStats(OutputStream* stream); + SnapshotObjectId PushHeapObjectsStats(OutputStream* stream); static SnapshotObjectId GenerateId(v8::RetainedObjectInfo* info); static inline SnapshotObjectId GetNthGcSubrootId(int delta); @@ -707,7 +707,7 @@ class HeapSnapshotsCollection { ~HeapSnapshotsCollection(); bool is_tracking_objects() { return is_tracking_objects_; } - void PushHeapObjectsStats(OutputStream* stream) { + SnapshotObjectId PushHeapObjectsStats(OutputStream* stream) { return ids_.PushHeapObjectsStats(stream); } void StartHeapObjectsTracking() { is_tracking_objects_ = true; } diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index c405b334c9..560d004680 100644 --- a/test/cctest/test-heap-profiler.cc +++ b/test/cctest/test-heap-profiler.cc @@ -691,9 +691,13 @@ class TestStatsStream : public v8::OutputStream { } // namespace -static TestStatsStream GetHeapStatsUpdate() { +static TestStatsStream GetHeapStatsUpdate( + v8::SnapshotObjectId* object_id = NULL) { TestStatsStream stream; - v8::HeapProfiler::PushHeapObjectsStats(&stream); + v8::SnapshotObjectId last_seen_id = + v8::HeapProfiler::PushHeapObjectsStats(&stream); + if (object_id) + *object_id = last_seen_id; CHECK_EQ(1, stream.eos_signaled()); return stream; } @@ -710,9 +714,10 @@ TEST(HeapSnapshotObjectsStats) { HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); } + v8::SnapshotObjectId initial_id; { // Single chunk of data expected in update. Initial data. - TestStatsStream stats_update = GetHeapStatsUpdate(); + TestStatsStream stats_update = GetHeapStatsUpdate(&initial_id); CHECK_EQ(1, stats_update.intervals_count()); CHECK_EQ(1, stats_update.updates_written()); CHECK_LT(0, stats_update.entries_size()); @@ -720,13 +725,18 @@ TEST(HeapSnapshotObjectsStats) { } // No data expected in update because nothing has happened. - CHECK_EQ(0, GetHeapStatsUpdate().updates_written()); + v8::SnapshotObjectId same_id; + CHECK_EQ(0, GetHeapStatsUpdate(&same_id).updates_written()); + CHECK_EQ_SNAPSHOT_OBJECT_ID(initial_id, same_id); + { + v8::SnapshotObjectId additional_string_id; v8::HandleScope inner_scope_1; v8_str("string1"); { // Single chunk of data with one new entry expected in update. - TestStatsStream stats_update = GetHeapStatsUpdate(); + TestStatsStream stats_update = GetHeapStatsUpdate(&additional_string_id); + CHECK_LT(same_id, additional_string_id); CHECK_EQ(1, stats_update.intervals_count()); CHECK_EQ(1, stats_update.updates_written()); CHECK_LT(0, stats_update.entries_size()); @@ -735,7 +745,9 @@ TEST(HeapSnapshotObjectsStats) { } // No data expected in update because nothing happened. - CHECK_EQ(0, GetHeapStatsUpdate().updates_written()); + v8::SnapshotObjectId last_id; + CHECK_EQ(0, GetHeapStatsUpdate(&last_id).updates_written()); + CHECK_EQ_SNAPSHOT_OBJECT_ID(additional_string_id, last_id); { v8::HandleScope inner_scope_2;