OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/process_stats_sender.h" | 5 #include "remoting/host/process_stats_sender.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "remoting/host/process_stats_agent.h" | 11 #include "remoting/host/process_stats_agent.h" |
12 #include "remoting/host/process_stats_util.h" | |
13 | 12 |
14 namespace remoting { | 13 namespace remoting { |
15 | 14 |
| 15 namespace { |
| 16 |
| 17 bool IsProcessResourceUsageValid(const protocol::ProcessResourceUsage& usage) { |
| 18 return usage.has_process_name() && usage.has_processor_usage() && |
| 19 usage.has_working_set_size() && usage.has_pagefile_size(); |
| 20 } |
| 21 |
| 22 } // namespace |
| 23 |
16 ProcessStatsSender::ProcessStatsSender( | 24 ProcessStatsSender::ProcessStatsSender( |
17 protocol::ProcessStatsStub* host_stats_stub, | 25 protocol::ProcessStatsStub* host_stats_stub, |
18 base::TimeDelta interval, | 26 base::TimeDelta interval, |
19 std::initializer_list<ProcessStatsAgent*> agents) | 27 std::initializer_list<ProcessStatsAgent*> agents) |
20 : host_stats_stub_(host_stats_stub), | 28 : host_stats_stub_(host_stats_stub), |
21 agents_(agents), | 29 agents_(agents), |
22 interval_(interval), | 30 interval_(interval), |
23 thread_checker_() { | 31 thread_checker_() { |
24 DCHECK(thread_checker_.CalledOnValidThread()); | 32 DCHECK(thread_checker_.CalledOnValidThread()); |
25 DCHECK(host_stats_stub_); | 33 DCHECK(host_stats_stub_); |
26 DCHECK(interval > base::TimeDelta()); | 34 DCHECK(interval > base::TimeDelta()); |
27 DCHECK(!agents_.empty()); | 35 DCHECK(!agents_.empty()); |
28 | 36 |
29 timer_.Start(FROM_HERE, interval, this, &ProcessStatsSender::ReportUsage); | 37 timer_.Start(FROM_HERE, interval, this, &ProcessStatsSender::ReportUsage); |
30 } | 38 } |
31 | 39 |
32 ProcessStatsSender::~ProcessStatsSender() { | 40 ProcessStatsSender::~ProcessStatsSender() { |
33 DCHECK(thread_checker_.CalledOnValidThread()); | 41 DCHECK(thread_checker_.CalledOnValidThread()); |
34 timer_.Stop(); | 42 timer_.Stop(); |
35 } | 43 } |
36 | 44 |
37 base::TimeDelta ProcessStatsSender::interval() const { | 45 base::TimeDelta ProcessStatsSender::interval() const { |
38 return interval_; | 46 return interval_; |
39 } | 47 } |
40 | 48 |
41 void ProcessStatsSender::ReportUsage() { | 49 void ProcessStatsSender::ReportUsage() { |
42 DCHECK(thread_checker_.CalledOnValidThread()); | 50 DCHECK(thread_checker_.CalledOnValidThread()); |
43 | 51 |
44 std::vector<protocol::ProcessResourceUsage> usages; | 52 protocol::AggregatedProcessResourceUsage aggregated; |
45 for (auto* const agent : agents_) { | 53 for (auto* const agent : agents_) { |
46 DCHECK(agent); | 54 DCHECK(agent); |
47 protocol::ProcessResourceUsage usage = agent->GetResourceUsage(); | 55 protocol::ProcessResourceUsage usage = agent->GetResourceUsage(); |
48 if (!IsEmptyProcessResourceUsage(usage)) { | 56 if (IsProcessResourceUsageValid(usage)) { |
49 usages.push_back(std::move(usage)); | 57 *aggregated.add_usages() = usage; |
| 58 } else { |
| 59 LOG(ERROR) << "Invalid ProcessResourceUsage " |
| 60 << usage.process_name() |
| 61 << " received."; |
50 } | 62 } |
51 } | 63 } |
52 | 64 |
53 host_stats_stub_->OnProcessStats(AggregateProcessResourceUsage(usages)); | 65 host_stats_stub_->OnProcessStats(aggregated); |
54 } | 66 } |
55 | 67 |
56 } // namespace remoting | 68 } // namespace remoting |
OLD | NEW |