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

Side by Side 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, 8 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/base/process_stats_util.h"
6
7 namespace remoting {
8
9 bool IsEmptyProcessResourceUsage(const protocol::ProcessResourceUsage& usage) {
10 return !usage.has_process_name() && !usage.has_processor_usage() &&
11 !usage.has_working_set_size() && !usage.has_pagefile_size();
12 }
13
14 protocol::AggregatedProcessResourceUsage AggregateProcessResourceUsage(
15 const std::vector<protocol::ProcessResourceUsage>& usages) {
16 if (usages.empty()) {
17 return protocol::AggregatedProcessResourceUsage();
18 }
19
20 if (usages.size() == 1) {
21 const protocol::ProcessResourceUsage& usage = usages[0];
22 protocol::AggregatedProcessResourceUsage aggregated;
23 aggregated.set_name(usage.process_name());
24 aggregated.set_processor_usage(usage.processor_usage());
25 aggregated.set_working_set_size(usage.working_set_size());
26 aggregated.set_pagefile_size(usage.pagefile_size());
27 return aggregated;
28 }
29
30 protocol::AggregatedProcessResourceUsage aggregated;
31 *aggregated.mutable_name() = "aggregate { ";
32 for (const auto& usage : usages) {
33 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.
34 aggregated.set_processor_usage(aggregated.processor_usage() +
35 usage.processor_usage());
36 aggregated.set_working_set_size(aggregated.working_set_size() +
37 usage.working_set_size());
38 aggregated.set_pagefile_size(aggregated.pagefile_size() +
39 usage.pagefile_size());
40 *aggregated.add_usages() = usage;
41 }
42 aggregated.mutable_name()->append(" }");
43 return aggregated;
44 }
45
46 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698