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

Unified Diff: remoting/host/host_stats.cc

Issue 2775983003: [Chromoting] Retrieve process resource usage (ProcessStats) and its tests (Closed)
Patch Set: Created 3 years, 9 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: remoting/host/host_stats.cc
diff --git a/remoting/host/host_stats.cc b/remoting/host/host_stats.cc
new file mode 100644
index 0000000000000000000000000000000000000000..56b92c504a61cd3c618411cad0071ef74c2288f2
--- /dev/null
+++ b/remoting/host/host_stats.cc
@@ -0,0 +1,53 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/logging.h"
+#include "base/message_loop/message_loop.h"
+#include "remoting/host/host_stats.h"
+
+namespace remoting {
+namespace host {
+
+HostStats::HostStats(HostStatsStub* host_stats_stub, base::TimeDelta interval)
+ : host_stats_stub_(host_stats_stub),
+ interval_(interval),
+ metrics_(base::ProcessMetrics::CreateCurrentProcessMetrics()),
+ weak_factory_(this) {
+ DCHECK(host_stats_stub_);
+ DCHECK(!interval_.is_zero());
+
+ PostTask();
+}
+
+HostStats::~HostStats() = default;
+
+void HostStats::PostTask() {
+ base::MessageLoop::current()->task_runner()->PostDelayedTask(FROM_HERE,
Sergey Ulanov 2017/03/27 19:43:20 I think it would be better to use base::RepeatingT
Hzj_jie 2017/03/30 01:09:45 Done.
+ base::Bind(&HostStats::ReportUsage, weak_factory_.GetWeakPtr()),
+ interval_);
+}
+
+void HostStats::ReportUsage() {
+ ProcessResourceUsage current;
+ current.processor_usage = metrics_->GetPlatformIndependentCPUUsage();
+ current.working_set_size = metrics_->GetWorkingSetSize();
+ current.pagefile_size = metrics_->GetPagefileUsage();
+ {
+ base::AutoLock lock(lock_);
Sergey Ulanov 2017/03/27 19:43:20 Why do we need lock?
Hzj_jie 2017/03/30 01:09:45 I suppose HostStats::OnHostStats() should be calle
+ current.Append(received_usage_);
+ }
+ host_stats_stub_->OnHostStats(current);
+
+ PostTask();
+}
+
+void HostStats::OnHostStats(const ProcessResourceUsage& usage) {
+ base::AutoLock lock(lock_);
+ received_usage_ = usage;
+}
+
+} // namespace host
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698