Commit 463a6ffd authored by loislo@chromium.org's avatar loislo@chromium.org

Expose last seen heap object id via v8 public api.

BUG=none
TEST=none

Review URL: https://chromiumcodereview.appspot.com/10444137

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11702 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c5160606
......@@ -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
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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_;
......
......@@ -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();
}
......
......@@ -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; }
......
......@@ -691,9 +691,13 @@ class TestStatsStream : public v8::OutputStream {
} // namespace
static TestStatsStream GetHeapStatsUpdate() {
static TestStatsStream GetHeapStatsUpdate(
v8::SnapshotObjectId* object_id = NULL) {
TestStatsStream 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;
......
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