Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(741)

Unified Diff: components/domain_reliability/scheduler.cc

Issue 357103002: Domain Reliability: Add rudimentary WebUI page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/domain_reliability/scheduler.cc
diff --git a/components/domain_reliability/scheduler.cc b/components/domain_reliability/scheduler.cc
index 3b7cfb5212f46a277fd1c3ff9a5de98dd0f523f1..fa8ba50969b1fd2216db503708e67398e94e2018 100644
--- a/components/domain_reliability/scheduler.cc
+++ b/components/domain_reliability/scheduler.cc
@@ -8,6 +8,7 @@
#include "base/metrics/field_trial.h"
#include "base/strings/string_number_conversions.h"
+#include "base/values.h"
#include "components/domain_reliability/config.h"
#include "components/domain_reliability/util.h"
@@ -74,7 +75,8 @@ DomainReliabilityScheduler::DomainReliabilityScheduler(
upload_pending_(false),
upload_scheduled_(false),
upload_running_(false),
- collector_index_(kInvalidCollectorIndex) {
+ collector_index_(kInvalidCollectorIndex),
+ last_upload_finished_(false) {
}
DomainReliabilityScheduler::~DomainReliabilityScheduler() {}
@@ -100,6 +102,9 @@ size_t DomainReliabilityScheduler::OnUploadStart() {
VLOG(1) << "Starting upload to collector " << collector_index_ << ".";
+ last_upload_start_time_ = now;
+ last_upload_collector_index_ = collector_index_;
+
return collector_index_;
}
@@ -125,8 +130,13 @@ void DomainReliabilityScheduler::OnUploadComplete(bool success) {
++collector->failures;
}
+ base::TimeTicks now = time_->NowTicks();
base::TimeDelta retry_interval = GetUploadRetryInterval(collector->failures);
- collector->next_upload = time_->NowTicks() + retry_interval;
+ collector->next_upload = now + retry_interval;
+
+ last_upload_end_time_ = now;
+ last_upload_success_ = success;
+ last_upload_finished_ = true;
VLOG(1) << "Next upload to collector at least "
<< retry_interval.InSeconds() << " seconds from now.";
@@ -134,6 +144,42 @@ void DomainReliabilityScheduler::OnUploadComplete(bool success) {
MaybeScheduleUpload();
}
+base::Value* DomainReliabilityScheduler::GetWebUIData() const {
+ base::TimeTicks now = time_->NowTicks();
+
+ base::DictionaryValue* data = new base::DictionaryValue();
+
+ data->SetBoolean("upload_pending", upload_pending_);
+ data->SetBoolean("upload_scheduled", upload_scheduled_);
+ data->SetBoolean("upload_running", upload_running_);
+
+ data->SetInteger("scheduled_min", (scheduled_min_time_ - now).InSeconds());
+ data->SetInteger("scheduled_max", (scheduled_max_time_ - now).InSeconds());
+
+ data->SetInteger("collector_index", collector_index_);
+
+ if (last_upload_finished_) {
+ base::DictionaryValue* last = new base::DictionaryValue();
+ last->SetInteger("start_time", (now - last_upload_start_time_).InSeconds());
+ last->SetInteger("end_time", (now - last_upload_end_time_).InSeconds());
+ last->SetInteger("collector_index", last_upload_collector_index_);
+ last->SetBoolean("success", last_upload_success_);
+ data->Set("last_upload", last);
+ }
+
+ base::ListValue* collectors = new base::ListValue();
+ for (size_t i = 0; i < collectors_.size(); ++i) {
+ const CollectorState* state = &collectors_[i];
+ base::DictionaryValue* value = new base::DictionaryValue();
+ value->SetInteger("failures", state->failures);
+ value->SetInteger("next_upload", (state->next_upload - now).InSeconds());
+ collectors->Append(value);
+ }
+ data->Set("collectors", collectors);
+
+ return data;
+}
+
DomainReliabilityScheduler::CollectorState::CollectorState() : failures(0) {}
void DomainReliabilityScheduler::MaybeScheduleUpload() {
@@ -154,8 +200,11 @@ void DomainReliabilityScheduler::MaybeScheduleUpload() {
size_t collector_index;
GetNextUploadTimeAndCollector(now, &min_by_backoff, &collector_index);
- base::TimeDelta min_delay = std::max(min_by_deadline, min_by_backoff) - now;
- base::TimeDelta max_delay = std::max(max_by_deadline, min_by_backoff) - now;
+ scheduled_min_time_ = std::max(min_by_deadline, min_by_backoff);
+ scheduled_max_time_ = std::max(max_by_deadline, min_by_backoff);
+
+ base::TimeDelta min_delay = scheduled_min_time_ - now;
+ base::TimeDelta max_delay = scheduled_max_time_ - now;
VLOG(1) << "Scheduling upload for between " << min_delay.InSeconds()
<< " and " << max_delay.InSeconds() << " seconds from now.";

Powered by Google App Engine
This is Rietveld 408576698