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

Side by Side Diff: remoting/base/process_stats.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 <utility>
6
7 #include "base/location.h"
8 #include "base/logging.h"
9 #include "remoting/base/process_stats.h"
Sergey Ulanov 2017/04/03 23:50:21 This should be the first include in this file.
Hzj_jie 2017/04/05 20:52:16 Done.
10 #include "remoting/base/process_stats_util.h"
11
12 namespace remoting {
13
14 ProcessStats::ProcessStats(ProcessStatsStub* host_stats_stub,
15 base::TimeDelta interval)
16 : host_stats_stub_(host_stats_stub), interval_(interval) {
17 DCHECK(host_stats_stub_);
18 DCHECK(!interval_.is_zero());
19 }
20
21 ProcessStats::~ProcessStats() = default;
22
23 void ProcessStats::AddProcessStatsAgent(
24 std::unique_ptr<ProcessStatsAgent> agent) {
25 agents_.push_back(std::move(agent));
26 }
27
28 void ProcessStats::Start() {
29 timer_.Start(FROM_HERE, interval_, this, &ProcessStats::ReportUsage);
30 }
31
32 void ProcessStats::Stop() {
33 timer_.Stop();
34 }
35
36 void ProcessStats::ReportUsage() {
37 if (agents_.empty()) {
38 return;
39 }
40
41 std::vector<protocol::ProcessResourceUsage> usages;
42 for (const auto& agent : agents_) {
43 protocol::ProcessResourceUsage usage = agent->GetResourceUsage();
Sergey Ulanov 2017/04/03 23:50:21 Can this operation block? Would it be better to ru
Hzj_jie 2017/04/05 20:52:16 Emm, good point. On Windows and Mac OS, this opera
Sergey Ulanov 2017/04/06 05:55:50 Even if it doesn't contain any IO operation it may
Hzj_jie 2017/04/06 19:41:05 Definitely. The comment is added into ProcessStats
44 if (!IsEmptyProcessResourceUsage(usage)) {
45 usages.push_back(std::move(usage));
46 }
47 }
48
49 host_stats_stub_->OnProcessStats(AggregateProcessResourceUsage(usages));
50 }
51
52 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698