Commit 796cdadd authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

[heap profiler] Fix heap snapshot progress report stopping at 50%

Make the progress report aligned with the single pass over the heap.

Change-Id: I6a63e7eee86719328daa588e5a0c53a668aca464
Reviewed-on: https://chromium-review.googlesource.com/1099863Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53744}
parent 9f7abe66
...@@ -785,17 +785,13 @@ const char* V8HeapExplorer::GetSystemEntryName(HeapObject* object) { ...@@ -785,17 +785,13 @@ const char* V8HeapExplorer::GetSystemEntryName(HeapObject* object) {
} }
} }
int V8HeapExplorer::EstimateObjectsCount() {
int V8HeapExplorer::EstimateObjectsCount(HeapIterator* iterator) { HeapIterator it(heap_, HeapIterator::kFilterUnreachable);
int objects_count = 0; int objects_count = 0;
for (HeapObject* obj = iterator->next(); obj != nullptr; while (it.next()) ++objects_count;
obj = iterator->next()) {
objects_count++;
}
return objects_count; return objects_count;
} }
class IndexedReferencesExtractor : public ObjectVisitor { class IndexedReferencesExtractor : public ObjectVisitor {
public: public:
IndexedReferencesExtractor(V8HeapExplorer* generator, HeapObject* parent_obj, IndexedReferencesExtractor(V8HeapExplorer* generator, HeapObject* parent_obj,
...@@ -1551,9 +1547,7 @@ class RootsReferencesExtractor : public RootVisitor { ...@@ -1551,9 +1547,7 @@ class RootsReferencesExtractor : public RootVisitor {
bool visiting_weak_roots_; bool visiting_weak_roots_;
}; };
bool V8HeapExplorer::IterateAndExtractReferences(SnapshotFiller* filler) {
bool V8HeapExplorer::IterateAndExtractReferences(
SnapshotFiller* filler) {
filler_ = filler; filler_ = filler;
// Create references to the synthetic roots. // Create references to the synthetic roots.
...@@ -1603,13 +1597,8 @@ bool V8HeapExplorer::IterateAndExtractReferences( ...@@ -1603,13 +1597,8 @@ bool V8HeapExplorer::IterateAndExtractReferences(
if (!progress_->ProgressReport(false)) interrupted = true; if (!progress_->ProgressReport(false)) interrupted = true;
} }
if (interrupted) {
filler_ = nullptr;
return false;
}
filler_ = nullptr; filler_ = nullptr;
return progress_->ProgressReport(true); return interrupted ? false : progress_->ProgressReport(true);
} }
...@@ -2419,7 +2408,7 @@ bool HeapSnapshotGenerator::GenerateSnapshot() { ...@@ -2419,7 +2408,7 @@ bool HeapSnapshotGenerator::GenerateSnapshot() {
} }
#endif #endif
SetProgressTotal(2); // 2 passes. InitProgressCounter();
#ifdef VERIFY_HEAP #ifdef VERIFY_HEAP
if (FLAG_verify_heap) { if (FLAG_verify_heap) {
...@@ -2439,12 +2428,10 @@ bool HeapSnapshotGenerator::GenerateSnapshot() { ...@@ -2439,12 +2428,10 @@ bool HeapSnapshotGenerator::GenerateSnapshot() {
return true; return true;
} }
void HeapSnapshotGenerator::ProgressStep() { void HeapSnapshotGenerator::ProgressStep() {
++progress_counter_; ++progress_counter_;
} }
bool HeapSnapshotGenerator::ProgressReport(bool force) { bool HeapSnapshotGenerator::ProgressReport(bool force) {
const int kProgressReportGranularity = 10000; const int kProgressReportGranularity = 10000;
if (control_ != nullptr && if (control_ != nullptr &&
...@@ -2455,27 +2442,22 @@ bool HeapSnapshotGenerator::ProgressReport(bool force) { ...@@ -2455,27 +2442,22 @@ bool HeapSnapshotGenerator::ProgressReport(bool force) {
return true; return true;
} }
void HeapSnapshotGenerator::InitProgressCounter() {
void HeapSnapshotGenerator::SetProgressTotal(int iterations_count) {
if (control_ == nullptr) return; if (control_ == nullptr) return;
HeapIterator iterator(heap_, HeapIterator::kFilterUnreachable);
// The +1 ensures that intermediate ProgressReport calls will never signal // The +1 ensures that intermediate ProgressReport calls will never signal
// that the work is finished (i.e. progress_counter_ == progress_total_). // that the work is finished (i.e. progress_counter_ == progress_total_).
// Only the forced ProgressReport() at the end of GenerateSnapshot() // Only the forced ProgressReport() at the end of GenerateSnapshot()
// should signal that the work is finished because signalling finished twice // should signal that the work is finished because signalling finished twice
// breaks the DevTools frontend. // breaks the DevTools frontend.
progress_total_ = progress_total_ = v8_heap_explorer_.EstimateObjectsCount() +
iterations_count * (v8_heap_explorer_.EstimateObjectsCount(&iterator) + dom_explorer_.EstimateObjectsCount() + 1;
dom_explorer_.EstimateObjectsCount()) +
1;
progress_counter_ = 0; progress_counter_ = 0;
} }
bool HeapSnapshotGenerator::FillReferences() { bool HeapSnapshotGenerator::FillReferences() {
SnapshotFiller filler(snapshot_, &entries_); SnapshotFiller filler(snapshot_, &entries_);
return v8_heap_explorer_.IterateAndExtractReferences(&filler) return v8_heap_explorer_.IterateAndExtractReferences(&filler) &&
&& dom_explorer_.IterateAndExtractReferences(&filler); dom_explorer_.IterateAndExtractReferences(&filler);
} }
......
...@@ -342,7 +342,7 @@ class V8HeapExplorer : public HeapEntriesAllocator { ...@@ -342,7 +342,7 @@ class V8HeapExplorer : public HeapEntriesAllocator {
v8::HeapProfiler::ObjectNameResolver* resolver); v8::HeapProfiler::ObjectNameResolver* resolver);
virtual ~V8HeapExplorer(); virtual ~V8HeapExplorer();
virtual HeapEntry* AllocateEntry(HeapThing ptr); virtual HeapEntry* AllocateEntry(HeapThing ptr);
int EstimateObjectsCount(HeapIterator* iterator); int EstimateObjectsCount();
bool IterateAndExtractReferences(SnapshotFiller* filler); bool IterateAndExtractReferences(SnapshotFiller* filler);
void TagGlobalObjects(); void TagGlobalObjects();
void TagCodeObject(Code* code); void TagCodeObject(Code* code);
...@@ -554,7 +554,7 @@ class HeapSnapshotGenerator : public SnapshottingProgressReportingInterface { ...@@ -554,7 +554,7 @@ class HeapSnapshotGenerator : public SnapshottingProgressReportingInterface {
bool FillReferences(); bool FillReferences();
void ProgressStep(); void ProgressStep();
bool ProgressReport(bool force = false); bool ProgressReport(bool force = false);
void SetProgressTotal(int iterations_count); void InitProgressCounter();
HeapSnapshot* snapshot_; HeapSnapshot* snapshot_;
v8::ActivityControl* control_; v8::ActivityControl* control_;
......
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