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 |