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

Side by Side Diff: remoting/host/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/host/process_stats_util.h"
6
7 #include <stdint.h>
8
9 #include <string>
10 #include <utility>
11
12 namespace remoting {
13 namespace host {
14
15 bool IsEmptyProcessResourceUsage(const protocol::ProcessResourceUsage& usage) {
16 return !usage.has_process_name() && !usage.has_processor_usage() &&
17 !usage.has_working_set_size() && !usage.has_pagefile_size();
18 }
19
20 protocol::AggregatedProcessResourceUsage AggregateProcessResourceUsage(
21 const std::vector<protocol::ProcessResourceUsage>& usages) {
22 if (usages.empty()) {
23 return protocol::AggregatedProcessResourceUsage();
24 }
25
26 if (usages.size() == 1) {
27 const protocol::ProcessResourceUsage& usage = usages[0];
28 protocol::AggregatedProcessResourceUsage aggregated;
29 aggregated.set_name(usage.process_name());
30 aggregated.set_processor_usage(usage.processor_usage());
31 aggregated.set_working_set_size(usage.working_set_size());
32 aggregated.set_pagefile_size(usage.pagefile_size());
33 return aggregated;
34 }
35
36 std::string name = "aggregate { ";
37 double processor_usage = 0;
38 uint64_t working_set_size = 0;
39 uint64_t pagefile_size = 0;
40 protocol::AggregatedProcessResourceUsage aggregated;
41 for (const auto& usage : usages) {
42 name.append(usage.process_name()).append(", ");
43 processor_usage += usage.processor_usage();
44 working_set_size += usage.working_set_size();
45 pagefile_size += usage.pagefile_size();
46 *aggregated.add_usages() = usage;
47 }
48 name += " }";
49 aggregated.set_name(std::move(name));
50 aggregated.set_processor_usage(processor_usage);
51 aggregated.set_working_set_size(working_set_size);
52 aggregated.set_pagefile_size(pagefile_size);
53
54 return aggregated;
55 }
56
57 } // namespace host
58 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698