Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #ifndef REMOTING_HOST_HOST_STATS_H_ | |
| 6 #define REMOTING_HOST_HOST_STATS_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/process/process_metrics.h" | |
| 13 #include "base/synchronization/lock.h" | |
| 14 #include "base/task_runner.h" | |
| 15 #include "base/threading/thread_checker.h" | |
| 16 #include "base/time/time.h" | |
| 17 #include "remoting/base/process_resource_usage.h" | |
| 18 #include "remoting/host/host_stats_stub.h" | |
| 19 | |
| 20 namespace remoting { | |
| 21 namespace host { | |
| 22 | |
| 23 // A component to report host process statistic data regularly. This class also | |
| 24 // implements HostStatsStub, so several HostStats instances can chain together | |
| 25 // to accumulate the total resource usage of several processes. | |
|
Sergey Ulanov
2017/03/27 19:43:20
I don't think that chaining is the best approach h
Hzj_jie
2017/03/30 01:09:45
I have no objection on holding several HostStats s
| |
| 26 class HostStats final : public HostStatsStub { | |
|
Sergey Ulanov
2017/03/27 19:43:20
HostStatsSender or maybe HostStatsAgenet
Hzj_jie
2017/03/30 01:09:46
Done.
| |
| 27 public: | |
| 28 // HostStats starts immediately, and reports the statistic data to | |
| 29 // |host_stats_stub| once per |interval| in | |
| 30 // MessageLoop::current()->task_runner(). HostStats does not take the | |
| 31 // ownership of |host_stats_stub|. It needs to be outlived this instance. | |
| 32 HostStats(HostStatsStub* host_stats_stub, base::TimeDelta interval); | |
| 33 | |
| 34 // Needs to be destructed on the same thread as constructing. | |
| 35 ~HostStats(); | |
| 36 | |
| 37 private: | |
| 38 void PostTask(); | |
| 39 | |
| 40 void ReportUsage(); | |
| 41 | |
| 42 // HostStatsStub interface. | |
| 43 void OnHostStats(const ProcessResourceUsage& usage) override; | |
| 44 | |
| 45 HostStatsStub* const host_stats_stub_; | |
| 46 const base::TimeDelta interval_; | |
| 47 const std::unique_ptr<base::ProcessMetrics> metrics_; | |
| 48 base::Lock lock_; | |
| 49 ProcessResourceUsage received_usage_; | |
| 50 base::WeakPtrFactory<HostStats> weak_factory_; | |
| 51 }; | |
| 52 | |
| 53 } // namespace host | |
| 54 } // namespace remoting | |
| 55 | |
| 56 #endif // REMOTING_HOST_HOST_STATS_H_ | |
| OLD | NEW |