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

Unified Diff: remoting/base/process_stats_util.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_util.cc
diff --git a/remoting/base/process_stats_util.cc b/remoting/base/process_stats_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8c61598e634bb52efe6d20aebea294de795b2b30
--- /dev/null
+++ b/remoting/base/process_stats_util.cc
@@ -0,0 +1,46 @@
+// 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 "remoting/base/process_stats_util.h"
+
+namespace remoting {
+
+bool IsEmptyProcessResourceUsage(const protocol::ProcessResourceUsage& usage) {
+ return !usage.has_process_name() && !usage.has_processor_usage() &&
+ !usage.has_working_set_size() && !usage.has_pagefile_size();
+}
+
+protocol::AggregatedProcessResourceUsage AggregateProcessResourceUsage(
+ const std::vector<protocol::ProcessResourceUsage>& usages) {
+ if (usages.empty()) {
+ return protocol::AggregatedProcessResourceUsage();
+ }
+
+ if (usages.size() == 1) {
+ const protocol::ProcessResourceUsage& usage = usages[0];
+ protocol::AggregatedProcessResourceUsage aggregated;
+ aggregated.set_name(usage.process_name());
+ aggregated.set_processor_usage(usage.processor_usage());
+ aggregated.set_working_set_size(usage.working_set_size());
+ aggregated.set_pagefile_size(usage.pagefile_size());
+ return aggregated;
+ }
+
+ protocol::AggregatedProcessResourceUsage aggregated;
+ *aggregated.mutable_name() = "aggregate { ";
+ for (const auto& usage : usages) {
+ aggregated.mutable_name()->append(usage.process_name()).append(", ");
Sergey Ulanov 2017/04/03 23:50:21 nit: it would be cleaner to assemble the aggregate
Hzj_jie 2017/04/05 20:52:17 Done. Also updated other variables.
+ aggregated.set_processor_usage(aggregated.processor_usage() +
+ usage.processor_usage());
+ aggregated.set_working_set_size(aggregated.working_set_size() +
+ usage.working_set_size());
+ aggregated.set_pagefile_size(aggregated.pagefile_size() +
+ usage.pagefile_size());
+ *aggregated.add_usages() = usage;
+ }
+ aggregated.mutable_name()->append(" }");
+ return aggregated;
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698