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

Unified Diff: remoting/host/host_stats.h

Issue 2775983003: [Chromoting] Retrieve process resource usage (ProcessStats) and its tests (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/host_stats.h
diff --git a/remoting/host/host_stats.h b/remoting/host/host_stats.h
new file mode 100644
index 0000000000000000000000000000000000000000..81d8cab8ce93b89255d591e800f1e03752dd2bec
--- /dev/null
+++ b/remoting/host/host_stats.h
@@ -0,0 +1,56 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_HOST_HOST_STATS_H_
+#define REMOTING_HOST_HOST_STATS_H_
+
+#include <memory>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "base/process/process_metrics.h"
+#include "base/synchronization/lock.h"
+#include "base/task_runner.h"
+#include "base/threading/thread_checker.h"
+#include "base/time/time.h"
+#include "remoting/base/process_resource_usage.h"
+#include "remoting/host/host_stats_stub.h"
+
+namespace remoting {
+namespace host {
+
+// A component to report host process statistic data regularly. This class also
+// implements HostStatsStub, so several HostStats instances can chain together
+// 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
+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.
+ public:
+ // HostStats starts immediately, and reports the statistic data to
+ // |host_stats_stub| once per |interval| in
+ // MessageLoop::current()->task_runner(). HostStats does not take the
+ // ownership of |host_stats_stub|. It needs to be outlived this instance.
+ HostStats(HostStatsStub* host_stats_stub, base::TimeDelta interval);
+
+ // Needs to be destructed on the same thread as constructing.
+ ~HostStats();
+
+ private:
+ void PostTask();
+
+ void ReportUsage();
+
+ // HostStatsStub interface.
+ void OnHostStats(const ProcessResourceUsage& usage) override;
+
+ HostStatsStub* const host_stats_stub_;
+ const base::TimeDelta interval_;
+ const std::unique_ptr<base::ProcessMetrics> metrics_;
+ base::Lock lock_;
+ ProcessResourceUsage received_usage_;
+ base::WeakPtrFactory<HostStats> weak_factory_;
+};
+
+} // namespace host
+} // namespace remoting
+
+#endif // REMOTING_HOST_HOST_STATS_H_

Powered by Google App Engine
This is Rietveld 408576698