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

Unified Diff: remoting/base/process_stats.cc

Issue 2775983003: [Chromoting] Retrieve process resource usage (ProcessStats) and its tests (Closed)
Patch Set: Resolve review comments 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/base/process_stats.cc
diff --git a/remoting/base/process_stats.cc b/remoting/base/process_stats.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4cb580b1c51f9328548454181f608e56bc345be3
--- /dev/null
+++ b/remoting/base/process_stats.cc
@@ -0,0 +1,52 @@
+// 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 <utility>
+
+#include "base/location.h"
+#include "base/logging.h"
+#include "remoting/base/process_stats.h"
Sergey Ulanov 2017/04/03 23:50:21 This should be the first include in this file.
Hzj_jie 2017/04/05 20:52:16 Done.
+#include "remoting/base/process_stats_util.h"
+
+namespace remoting {
+
+ProcessStats::ProcessStats(ProcessStatsStub* host_stats_stub,
+ base::TimeDelta interval)
+ : host_stats_stub_(host_stats_stub), interval_(interval) {
+ DCHECK(host_stats_stub_);
+ DCHECK(!interval_.is_zero());
+}
+
+ProcessStats::~ProcessStats() = default;
+
+void ProcessStats::AddProcessStatsAgent(
+ std::unique_ptr<ProcessStatsAgent> agent) {
+ agents_.push_back(std::move(agent));
+}
+
+void ProcessStats::Start() {
+ timer_.Start(FROM_HERE, interval_, this, &ProcessStats::ReportUsage);
+}
+
+void ProcessStats::Stop() {
+ timer_.Stop();
+}
+
+void ProcessStats::ReportUsage() {
+ if (agents_.empty()) {
+ return;
+ }
+
+ std::vector<protocol::ProcessResourceUsage> usages;
+ for (const auto& agent : agents_) {
+ protocol::ProcessResourceUsage usage = agent->GetResourceUsage();
Sergey Ulanov 2017/04/03 23:50:21 Can this operation block? Would it be better to ru
Hzj_jie 2017/04/05 20:52:16 Emm, good point. On Windows and Mac OS, this opera
Sergey Ulanov 2017/04/06 05:55:50 Even if it doesn't contain any IO operation it may
Hzj_jie 2017/04/06 19:41:05 Definitely. The comment is added into ProcessStats
+ if (!IsEmptyProcessResourceUsage(usage)) {
+ usages.push_back(std::move(usage));
+ }
+ }
+
+ host_stats_stub_->OnProcessStats(AggregateProcessResourceUsage(usages));
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698