OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ |
6 #define CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ | 6 #define CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/id_map.h" | 12 #include "base/id_map.h" |
13 #include "base/memory/weak_ptr.h" | |
13 #include "base/scoped_observer.h" | 14 #include "base/scoped_observer.h" |
14 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
15 #include "components/metrics/metrics_provider.h" | 16 #include "components/metrics/metrics_provider.h" |
17 #include "content/public/browser/browser_child_process_observer.h" | |
16 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
18 #include "content/public/browser/render_process_host_observer.h" | 20 #include "content/public/browser/render_process_host_observer.h" |
19 | 21 |
20 namespace base { | 22 namespace base { |
21 class PersistentHistogramAllocator; | 23 class PersistentHistogramAllocator; |
22 class SharedPersistentMemoryAllocator; | 24 class SharedPersistentMemoryAllocator; |
23 } | 25 } |
24 | 26 |
25 // SubprocessMetricsProvider gathers and merges histograms stored in shared | 27 // SubprocessMetricsProvider gathers and merges histograms stored in shared |
26 // memory segments between processes. Merging occurs when a process exits, | 28 // memory segments between processes. Merging occurs when a process exits, |
27 // when metrics are being collected for upload, or when something else needs | 29 // when metrics are being collected for upload, or when something else needs |
28 // combined metrics (such as the chrome://histograms page). | 30 // combined metrics (such as the chrome://histograms page). |
29 class SubprocessMetricsProvider : public metrics::MetricsProvider, | 31 class SubprocessMetricsProvider : public metrics::MetricsProvider, |
32 public content::BrowserChildProcessObserver, | |
30 public content::NotificationObserver, | 33 public content::NotificationObserver, |
31 public content::RenderProcessHostObserver { | 34 public content::RenderProcessHostObserver { |
32 public: | 35 public: |
33 SubprocessMetricsProvider(); | 36 SubprocessMetricsProvider(); |
34 ~SubprocessMetricsProvider() override; | 37 ~SubprocessMetricsProvider() override; |
35 | 38 |
39 // Start tracking sub-processes. This is called separately rather than being | |
40 // set in the constructor because library code that checks for calling on | |
41 // the correct thread can break tests. | |
Alexei Svitkine (slow)
2016/08/12 23:14:36
Can you provide more context? I would hope we can
bcwhite
2016/08/15 19:43:10
There's a DCHECK that it's running on BrowserThrea
Alexei Svitkine (slow)
2016/08/18 07:21:19
See: https://groups.google.com/a/chromium.org/foru
Alexei Svitkine (slow)
2016/08/19 15:10:51
Ping on this. I think you should be able to use th
bcwhite
2016/08/19 15:55:21
Yep. Was just addressing the design issues quickl
| |
42 void EnableSubprocessTracking(); | |
43 | |
36 private: | 44 private: |
37 friend class SubprocessMetricsProviderTest; | 45 friend class SubprocessMetricsProviderTest; |
38 | 46 |
39 // Indicates subprocess to be monitored with unique id for later reference. | 47 // Indicates subprocess to be monitored with unique id for later reference. |
40 // Metrics reporting will read histograms from it and upload them to UMA. | 48 // Metrics reporting will read histograms from it and upload them to UMA. |
41 void RegisterSubprocessAllocator( | 49 void RegisterSubprocessAllocator( |
42 int id, | 50 int id, |
43 std::unique_ptr<base::PersistentHistogramAllocator> allocator); | 51 std::unique_ptr<base::PersistentHistogramAllocator> allocator); |
44 | 52 |
45 // Indicates that a subprocess has exited and is thus finished with the | 53 // Indicates that a subprocess has exited and is thus finished with the |
46 // allocator it was using. | 54 // allocator it was using. |
47 void DeregisterSubprocessAllocator(int id); | 55 void DeregisterSubprocessAllocator(int id); |
48 | 56 |
49 // Merge all histograms of a given allocator to the global StatisticsRecorder. | 57 // Merge all histograms of a given allocator to the global StatisticsRecorder. |
50 // This is called periodically during UMA metrics collection (if enabled) and | 58 // This is called periodically during UMA metrics collection (if enabled) and |
51 // possibly on-demand for other purposes. | 59 // possibly on-demand for other purposes. |
52 void MergeHistogramDeltasFromAllocator( | 60 void MergeHistogramDeltasFromAllocator( |
53 int id, | 61 int id, |
54 base::PersistentHistogramAllocator* allocator); | 62 base::PersistentHistogramAllocator* allocator); |
55 | 63 |
56 // metrics::MetricsProvider: | 64 // metrics::MetricsProvider: |
57 void MergeHistogramDeltas() override; | 65 void MergeHistogramDeltas() override; |
58 | 66 |
67 // content::BrowserChildProcessObserver: | |
68 void BrowserChildProcessHostConnected( | |
69 const content::ChildProcessData& data) override; | |
70 void BrowserChildProcessHostDisconnected( | |
71 const content::ChildProcessData& data) override; | |
72 void BrowserChildProcessCrashed( | |
73 const content::ChildProcessData& data, | |
74 int exit_code) override; | |
75 void BrowserChildProcessKilled( | |
76 const content::ChildProcessData& data, | |
77 int exit_code) override; | |
78 | |
59 // content::NotificationObserver: | 79 // content::NotificationObserver: |
60 void Observe(int type, | 80 void Observe(int type, |
61 const content::NotificationSource& source, | 81 const content::NotificationSource& source, |
62 const content::NotificationDetails& details) override; | 82 const content::NotificationDetails& details) override; |
63 | 83 |
64 // content::RenderProcessHostObserver: | 84 // content::RenderProcessHostObserver: |
65 void RenderProcessReady(content::RenderProcessHost* host) override; | 85 void RenderProcessReady(content::RenderProcessHost* host) override; |
66 void RenderProcessExited(content::RenderProcessHost* host, | 86 void RenderProcessExited(content::RenderProcessHost* host, |
67 base::TerminationStatus status, | 87 base::TerminationStatus status, |
68 int exit_code) override; | 88 int exit_code) override; |
69 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; | 89 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; |
70 | 90 |
91 // Indicates a browser child process to be monitored. This must be called on | |
92 // the IO thread. The |provider| is used for calling Register on the UI | |
93 // thread. | |
94 static void RegisterBrowserChildProcessAllocatorFromIOThread( | |
95 base::WeakPtr<SubprocessMetricsProvider> provider, | |
96 int id); | |
97 | |
71 base::ThreadChecker thread_checker_; | 98 base::ThreadChecker thread_checker_; |
72 | 99 |
73 // Object for registing notification requests. | 100 // Object for registing notification requests. |
74 content::NotificationRegistrar registrar_; | 101 content::NotificationRegistrar registrar_; |
75 | 102 |
76 // All of the shared-persistent-allocators for known sub-processes. | 103 // All of the shared-persistent-allocators for known sub-processes. |
77 using AllocatorByIdMap = | 104 using AllocatorByIdMap = |
78 IDMap<base::PersistentHistogramAllocator, IDMapOwnPointer, int>; | 105 IDMap<base::PersistentHistogramAllocator, IDMapOwnPointer, int>; |
79 AllocatorByIdMap allocators_by_id_; | 106 AllocatorByIdMap allocators_by_id_; |
80 | 107 |
81 // Track all observed render processes to un-observe them on exit. | 108 // Track all observed render processes to un-observe them on exit. |
82 ScopedObserver<content::RenderProcessHost, SubprocessMetricsProvider> | 109 ScopedObserver<content::RenderProcessHost, SubprocessMetricsProvider> |
83 scoped_observer_; | 110 scoped_observer_; |
84 | 111 |
112 base::WeakPtrFactory<SubprocessMetricsProvider> weak_ptr_factory_; | |
113 | |
85 DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProvider); | 114 DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProvider); |
86 }; | 115 }; |
87 | 116 |
88 #endif // CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ | 117 #endif // CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ |
OLD | NEW |