Commit 514054d9 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[heap-profiler] Report finished progress only once.

This fixes HeapSnapshotGenerator::SetProgressTotal so that
ProgressReport is called with finished flag only once.

The DevTools front-end assumes that progress with finished flag is
reported only once.

Change-Id: Iad958478aa8ad27a520cb491419e521027967754
Reviewed-on: https://chromium-review.googlesource.com/949224
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51767}
parent e816d2ba
...@@ -2485,9 +2485,15 @@ bool HeapSnapshotGenerator::ProgressReport(bool force) { ...@@ -2485,9 +2485,15 @@ bool HeapSnapshotGenerator::ProgressReport(bool force) {
void HeapSnapshotGenerator::SetProgressTotal(int iterations_count) { void HeapSnapshotGenerator::SetProgressTotal(int iterations_count) {
if (control_ == nullptr) return; if (control_ == nullptr) return;
HeapIterator iterator(heap_, HeapIterator::kFilterUnreachable); HeapIterator iterator(heap_, HeapIterator::kFilterUnreachable);
progress_total_ = iterations_count * ( // The +1 ensures that intermediate ProgressReport calls will never signal
v8_heap_explorer_.EstimateObjectsCount(&iterator) + // that the work is finished (i.e. progress_counter_ == progress_total_).
dom_explorer_.EstimateObjectsCount()); // Only the forced ProgressReport() at the end of GenerateSnapshot()
// should signal that the work is finished because signalling finished twice
// breaks the DevTools frontend.
progress_total_ =
iterations_count * (v8_heap_explorer_.EstimateObjectsCount(&iterator) +
dom_explorer_.EstimateObjectsCount()) +
1;
progress_counter_ = 0; progress_counter_ = 0;
} }
......
...@@ -1430,10 +1430,18 @@ namespace { ...@@ -1430,10 +1430,18 @@ namespace {
class TestActivityControl : public v8::ActivityControl { class TestActivityControl : public v8::ActivityControl {
public: public:
explicit TestActivityControl(int abort_count) explicit TestActivityControl(int abort_count)
: done_(0), total_(0), abort_count_(abort_count) {} : done_(0),
total_(0),
abort_count_(abort_count),
reported_finish_(false) {}
ControlOption ReportProgressValue(int done, int total) { ControlOption ReportProgressValue(int done, int total) {
done_ = done; done_ = done;
total_ = total; total_ = total;
CHECK_LE(done_, total_);
if (done_ == total_) {
CHECK(!reported_finish_);
reported_finish_ = true;
}
return --abort_count_ != 0 ? kContinue : kAbort; return --abort_count_ != 0 ? kContinue : kAbort;
} }
int done() { return done_; } int done() { return done_; }
...@@ -1443,6 +1451,7 @@ class TestActivityControl : public v8::ActivityControl { ...@@ -1443,6 +1451,7 @@ class TestActivityControl : public v8::ActivityControl {
int done_; int done_;
int total_; int total_;
int abort_count_; int abort_count_;
bool reported_finish_;
}; };
} // namespace } // namespace
...@@ -1471,6 +1480,16 @@ TEST(TakeHeapSnapshotAborting) { ...@@ -1471,6 +1480,16 @@ TEST(TakeHeapSnapshotAborting) {
CHECK_GT(control.total(), 0); CHECK_GT(control.total(), 0);
} }
TEST(TakeHeapSnapshotReportFinishOnce) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
TestActivityControl control(-1);
const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(&control);
CHECK(ValidateSnapshot(snapshot));
CHECK_EQ(control.total(), control.done());
CHECK_GT(control.total(), 0);
}
namespace { namespace {
......
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