Commit f13d04d2 authored by yurys's avatar yurys Committed by Commit bot

Return timestamp of the last recorded interval to the caller of HeapProfiler::GetHeapStats

Before this patch the embedder could assign timestamp to the last interval after calling GetHeapStats. This would be slightly different from the timstamps assigned by v8 internally and written into heap snapshot. This patch allow to avoid this small discrepancy by returning timestamp along with last heap stats update.

BUG=chromium:467222
LOG=Y

Review URL: https://codereview.chromium.org/1037803002

Cr-Commit-Position: refs/heads/master@{#27466}
parent 4518e927
...@@ -471,17 +471,19 @@ class V8_EXPORT HeapProfiler { ...@@ -471,17 +471,19 @@ class V8_EXPORT HeapProfiler {
* reports updates for all previous time intervals via the OutputStream * reports updates for all previous time intervals via the OutputStream
* object. Updates on each time interval are provided as a stream of the * object. Updates on each time interval are provided as a stream of the
* HeapStatsUpdate structure instances. * HeapStatsUpdate structure instances.
* The return value of the function is the last seen heap object Id. * If |timestamp_us| is supplied, timestamp of the new entry will be written
* into it. The return value of the function is the last seen heap object Id.
* *
* StartTrackingHeapObjects must be called before the first call to this * StartTrackingHeapObjects must be called before the first call to this
* method. * method.
*/ */
SnapshotObjectId GetHeapStats(OutputStream* stream); SnapshotObjectId GetHeapStats(OutputStream* stream,
int64_t* timestamp_us = NULL);
/** /**
* Stops tracking of heap objects population statistics, cleans up all * Stops tracking of heap objects population statistics, cleans up all
* collected data. StartHeapObjectsTracking must be called again prior to * collected data. StartHeapObjectsTracking must be called again prior to
* calling PushHeapObjectsStats next time. * calling GetHeapStats next time.
*/ */
void StopTrackingHeapObjects(); void StopTrackingHeapObjects();
......
...@@ -7789,8 +7789,10 @@ void HeapProfiler::StopTrackingHeapObjects() { ...@@ -7789,8 +7789,10 @@ void HeapProfiler::StopTrackingHeapObjects() {
} }
SnapshotObjectId HeapProfiler::GetHeapStats(OutputStream* stream) { SnapshotObjectId HeapProfiler::GetHeapStats(OutputStream* stream,
return reinterpret_cast<i::HeapProfiler*>(this)->PushHeapObjectsStats(stream); int64_t* timestamp_us) {
i::HeapProfiler* heap_profiler = reinterpret_cast<i::HeapProfiler*>(this);
return heap_profiler->PushHeapObjectsStats(stream, timestamp_us);
} }
......
...@@ -91,8 +91,9 @@ void HeapProfiler::StartHeapObjectsTracking(bool track_allocations) { ...@@ -91,8 +91,9 @@ void HeapProfiler::StartHeapObjectsTracking(bool track_allocations) {
} }
SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) { SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream,
return ids_->PushHeapObjectsStats(stream); int64_t* timestamp_us) {
return ids_->PushHeapObjectsStats(stream, timestamp_us);
} }
......
...@@ -33,7 +33,8 @@ class HeapProfiler { ...@@ -33,7 +33,8 @@ class HeapProfiler {
HeapObjectsMap* heap_object_map() const { return ids_.get(); } HeapObjectsMap* heap_object_map() const { return ids_.get(); }
StringsStorage* names() const { return names_.get(); } StringsStorage* names() const { return names_.get(); }
SnapshotObjectId PushHeapObjectsStats(OutputStream* stream); SnapshotObjectId PushHeapObjectsStats(OutputStream* stream,
int64_t* timestamp_us);
int GetSnapshotsCount(); int GetSnapshotsCount();
HeapSnapshot* GetSnapshot(int index); HeapSnapshot* GetSnapshot(int index);
SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj); SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj);
......
...@@ -611,7 +611,8 @@ int HeapObjectsMap::FindUntrackedObjects() { ...@@ -611,7 +611,8 @@ int HeapObjectsMap::FindUntrackedObjects() {
} }
SnapshotObjectId HeapObjectsMap::PushHeapObjectsStats(OutputStream* stream) { SnapshotObjectId HeapObjectsMap::PushHeapObjectsStats(OutputStream* stream,
int64_t* timestamp_us) {
UpdateHeapObjectsMap(); UpdateHeapObjectsMap();
time_intervals_.Add(TimeInterval(next_id_)); time_intervals_.Add(TimeInterval(next_id_));
int prefered_chunk_size = stream->GetChunkSize(); int prefered_chunk_size = stream->GetChunkSize();
...@@ -653,6 +654,10 @@ SnapshotObjectId HeapObjectsMap::PushHeapObjectsStats(OutputStream* stream) { ...@@ -653,6 +654,10 @@ SnapshotObjectId HeapObjectsMap::PushHeapObjectsStats(OutputStream* stream) {
if (result == OutputStream::kAbort) return last_assigned_id(); if (result == OutputStream::kAbort) return last_assigned_id();
} }
stream->EndOfStream(); stream->EndOfStream();
if (timestamp_us) {
*timestamp_us = (time_intervals_.last().timestamp -
time_intervals_[0].timestamp).InMicroseconds();
}
return last_assigned_id(); return last_assigned_id();
} }
......
...@@ -219,7 +219,8 @@ class HeapObjectsMap { ...@@ -219,7 +219,8 @@ class HeapObjectsMap {
} }
void StopHeapObjectsTracking(); void StopHeapObjectsTracking();
SnapshotObjectId PushHeapObjectsStats(OutputStream* stream); SnapshotObjectId PushHeapObjectsStats(OutputStream* stream,
int64_t* timestamp_us);
const List<TimeInterval>& samples() const { return time_intervals_; } const List<TimeInterval>& samples() const { return time_intervals_; }
size_t GetUsedMemorySize() const; size_t GetUsedMemorySize() const;
......
...@@ -1044,9 +1044,12 @@ static TestStatsStream GetHeapStatsUpdate( ...@@ -1044,9 +1044,12 @@ static TestStatsStream GetHeapStatsUpdate(
v8::HeapProfiler* heap_profiler, v8::HeapProfiler* heap_profiler,
v8::SnapshotObjectId* object_id = NULL) { v8::SnapshotObjectId* object_id = NULL) {
TestStatsStream stream; TestStatsStream stream;
v8::SnapshotObjectId last_seen_id = heap_profiler->GetHeapStats(&stream); int64_t timestamp = -1;
v8::SnapshotObjectId last_seen_id =
heap_profiler->GetHeapStats(&stream, &timestamp);
if (object_id) if (object_id)
*object_id = last_seen_id; *object_id = last_seen_id;
CHECK_NE(-1, timestamp);
CHECK_EQ(1, stream.eos_signaled()); CHECK_EQ(1, stream.eos_signaled());
return stream; return stream;
} }
......
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