Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef CHROME_BROWSER_PROCESS_RESOURCE_USAGE_H_ | 5 #ifndef CHROME_BROWSER_PROCESS_RESOURCE_USAGE_H_ |
| 6 #define CHROME_BROWSER_PROCESS_RESOURCE_USAGE_H_ | 6 #define CHROME_BROWSER_PROCESS_RESOURCE_USAGE_H_ |
| 7 | 7 |
| 8 #include <deque> | |
| 9 | |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | |
| 9 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
| 10 #include "chrome/common/resource_usage_reporter.mojom.h" | 13 #include "chrome/common/resource_usage_reporter.mojom.h" |
| 14 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" | |
| 11 | 15 |
| 12 // Provides resource usage information about a child process. | 16 // Provides resource usage information about a child process. |
| 13 // | 17 // |
| 14 // This is a wrapper around the ResourceUsageReporter Mojo service that exposes | 18 // This is a wrapper around the ResourceUsageReporter Mojo service that exposes |
| 15 // information about resources used by a child process. Currently, this is only | 19 // information about resources used by a child process. Currently, this is only |
| 16 // V8 memory usage, but could be expanded to include other resources such as web | 20 // V8 memory usage, but could be expanded to include other resources such as web |
| 17 // cache. This is intended for status viewers such as the task manager and | 21 // cache. This is intended for status viewers such as the task manager and |
| 18 // about://memory-internals. | 22 // about://memory-internals. |
| 19 // | 23 // |
| 20 // To create: | 24 // To create: |
| 21 // 1. Obtain a ResourceUsageReporter connection using the child process's | 25 // 1. Obtain a ResourceUsageReporter connection using the child process's |
| 22 // service registry. i.e: | 26 // service registry. i.e: |
| 23 // ResourceUsageReporterPtr service; | 27 // ResourceUsageReporterPtr service; |
| 24 // process->GetServiceRegistry()->ConnectToRemoteService(&service); | 28 // process->GetServiceRegistry()->ConnectToRemoteService(&service); |
| 25 // 2. If needed, the connection can be passed to another thread using | 29 // 2. If needed, the connection can be passed to another thread using |
| 26 // ResourceUsageReporterPtr::PassInterface(). | 30 // ResourceUsageReporterPtr::PassInterface(). |
| 27 // 3. Pass the service to the constructor. | 31 // 3. Pass the service to the constructor. |
| 28 // | 32 // |
| 29 // Note: ProcessResourceUsage is thread-hostile and must live on a single | 33 // Note: ProcessResourceUsage is thread-hostile and must live on a single |
| 30 // thread. | 34 // thread. |
| 31 class ProcessResourceUsage { | 35 class ProcessResourceUsage : public mojo::ErrorHandler { |
| 32 public: | 36 public: |
| 33 // Must be called from the same thread that created |service|. | 37 // Must be called from the same thread that created |service|. |
| 34 explicit ProcessResourceUsage(ResourceUsageReporterPtr service); | 38 explicit ProcessResourceUsage(ResourceUsageReporterPtr service); |
| 35 ~ProcessResourceUsage(); | 39 ~ProcessResourceUsage() override; |
| 36 | 40 |
| 37 // Refresh the resource usage information. | 41 // Refresh the resource usage information. |callback| is invoked when the |
| 38 void Refresh(); | 42 // usage data is updated, or when the IPC connection is lost. |
| 43 void Refresh(const base::Closure& callback); | |
| 39 | 44 |
| 40 // Get V8 memory usage information. | 45 // Get V8 memory usage information. |
| 41 bool ReportsV8MemoryStats() const; | 46 bool ReportsV8MemoryStats() const; |
| 42 size_t GetV8MemoryAllocated() const; | 47 size_t GetV8MemoryAllocated() const; |
| 43 size_t GetV8MemoryUsed() const; | 48 size_t GetV8MemoryUsed() const; |
| 44 | 49 |
| 45 private: | 50 private: |
| 46 // Mojo IPC callback. | 51 // Mojo IPC callback. |
| 47 void OnRefreshDone(ResourceUsageDataPtr data); | 52 void OnRefreshDone(ResourceUsageDataPtr data); |
| 48 | 53 |
| 54 // mojo::ErrorHandler implementation: | |
| 55 void OnConnectionError() override; | |
|
ncarter (slow)
2015/05/14 06:28:12
Making this method private doesn't really hide it
Anand Mistry (off Chromium)
2015/05/14 07:30:41
Moved to a private helper class. I'd rather not go
| |
| 56 | |
| 57 void RunPendingRefreshCallbacks(); | |
| 58 | |
| 49 ResourceUsageReporterPtr service_; | 59 ResourceUsageReporterPtr service_; |
| 50 bool update_in_progress_; | 60 bool update_in_progress_; |
| 61 std::deque<base::Closure> refresh_callbacks_; | |
| 51 | 62 |
| 52 ResourceUsageDataPtr stats_; | 63 ResourceUsageDataPtr stats_; |
| 53 | 64 |
| 54 base::ThreadChecker thread_checker_; | 65 base::ThreadChecker thread_checker_; |
| 55 | 66 |
| 56 DISALLOW_COPY_AND_ASSIGN(ProcessResourceUsage); | 67 DISALLOW_COPY_AND_ASSIGN(ProcessResourceUsage); |
| 57 }; | 68 }; |
| 58 | 69 |
| 59 #endif // CHROME_BROWSER_PROCESS_RESOURCE_USAGE_H_ | 70 #endif // CHROME_BROWSER_PROCESS_RESOURCE_USAGE_H_ |
| OLD | NEW |