Reviewers: Yury Semikhatsky, Mikhail Naganov (Chromium), alexeif,
Description:
Expose last seen heap object id via v8 public api.
BUG=none
TEST=none
Please review this at https://chromiumcodereview.appspot.com/10444137/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M include/v8-profiler.h
M src/api.cc
M src/heap-profiler.h
M src/heap-profiler.cc
M src/profile-generator.h
M src/profile-generator.cc
M test/cctest/test-heap-profiler.cc
Index: include/v8-profiler.h
diff --git a/include/v8-profiler.h b/include/v8-profiler.h
index
8f380f2094daef623204390b9f73e3c1b5f5ecae..5f560c37eae8425cca4553f6fa01be21e3de3ead
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
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
74886f00859b8a467f213d217f658583bc8e6b42..6f38ba74919a8413922651140be9a6b806c6c746
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);
Index: src/heap-profiler.cc
diff --git a/src/heap-profiler.cc b/src/heap-profiler.cc
index
2e971a51b4076ac3c4ad29327c509ab13d13653b..975d6f4221c9162a79ae37413bb2362839f78108
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);
}
Index: src/heap-profiler.h
diff --git a/src/heap-profiler.h b/src/heap-profiler.h
index
96b042d3cb49903acd91fa9e812cfac2be7ecbab..4a811573ac1764742432d4e87852682e802d5291
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_;
Index: src/profile-generator.cc
diff --git a/src/profile-generator.cc b/src/profile-generator.cc
index
0fe7499d70abb2bc4bd75fe9b94c20c759536d46..69ef082dce09da266bc4300b4781a387f25e854a
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();
}
Index: src/profile-generator.h
diff --git a/src/profile-generator.h b/src/profile-generator.h
index
349226b43fad3ea9d996ce5bd539c979391810fa..6388985d40a90f08f8ddd77332c22cc55f4ae87d
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; }
Index: test/cctest/test-heap-profiler.cc
diff --git a/test/cctest/test-heap-profiler.cc
b/test/cctest/test-heap-profiler.cc
index
c405b334c91d62d329c9a4b6ed592a0f1059af40..560d004680ab6a71eec85fe20f23d365c059b036
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;
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev