OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ | |
6 #define CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ | |
7 | |
8 #include <set> | |
9 | |
10 #include "base/gtest_prod_util.h" | |
11 #include "base/id_map.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/scoped_observer.h" | |
14 #include "base/threading/thread_checker.h" | |
15 #include "components/metrics/metrics_provider.h" | |
16 #include "content/public/browser/notification_observer.h" | |
17 #include "content/public/browser/notification_registrar.h" | |
18 #include "content/public/browser/render_process_host_observer.h" | |
19 | |
20 namespace base { | |
21 class SharedPersistentMemoryAllocator; | |
22 } | |
23 | |
24 namespace metrics { | |
25 | |
26 // SubprocessMetricsProvider gathers and logs histograms stored in shared | |
27 // memory segments between processes. | |
28 class SubprocessMetricsProvider : public metrics::MetricsProvider, | |
29 public content::NotificationObserver, | |
30 public content::RenderProcessHostObserver { | |
31 public: | |
32 SubprocessMetricsProvider(); | |
33 ~SubprocessMetricsProvider() override; | |
34 | |
35 private: | |
36 friend class SubprocessMetricsProviderTest; | |
37 FRIEND_TEST_ALL_PREFIXES(SubprocessMetricsProviderTest, SnapshotMetrics); | |
38 | |
39 // Indicates subprocess to be monitored with unique id for later reference. | |
40 void RegisterSubprocessAllocator( | |
41 int id, | |
42 scoped_ptr<base::SharedPersistentMemoryAllocator> allocator); | |
43 | |
44 // Indicates that a subprocess has exited and is thus finished with the | |
45 // allocator it was using. | |
46 void DeregisterSubprocessAllocator(int id); | |
47 | |
48 // Report all histograms of a given allocator to the snapshot-manager. | |
49 void RecordHistogramSnapshotsFromAllocator( | |
50 base::HistogramSnapshotManager* snapshot_manager, | |
51 int id, | |
52 base::SharedPersistentMemoryAllocator* allocator); | |
53 | |
54 // metrics::MetricsDataProvider: | |
55 void RecordHistogramSnapshots( | |
56 base::HistogramSnapshotManager* snapshot_manager) override; | |
57 | |
58 // content::NotificationObserver overrides: | |
Alexei Svitkine (slow)
2016/03/24 17:29:53
Nit: Remove " overrides" here and on line 63.
bcwhite
2016/03/29 11:53:27
Done.
| |
59 void Observe(int type, | |
60 const content::NotificationSource& source, | |
61 const content::NotificationDetails& details) override; | |
62 | |
63 // content::RenderProcessHostObserver overrides: | |
64 void RenderProcessReady(content::RenderProcessHost* host) override; | |
65 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; | |
66 | |
67 // Object for registing notification requests. | |
68 content::NotificationRegistrar registrar_; | |
69 | |
70 // All of the shared-persistent-allocators for known sub-processes. | |
71 using AllocatorByIdMap = | |
72 IDMap<base::SharedPersistentMemoryAllocator, IDMapOwnPointer, int>; | |
73 AllocatorByIdMap allocators_by_id_; | |
74 | |
75 // Allocators that are no longer attached to a subprocess, to be released | |
76 // once the last data contained therein has been reported. | |
77 std::vector<scoped_ptr<base::SharedPersistentMemoryAllocator>> | |
78 allocators_to_release_; | |
79 | |
80 // Track all observed render processes to un-observe them on exit. | |
81 ScopedObserver<content::RenderProcessHost, SubprocessMetricsProvider> | |
82 scoped_observer_; | |
83 | |
84 base::ThreadChecker thread_checker_; | |
Alexei Svitkine (slow)
2016/03/24 17:29:53
Nit: Make this the first param.
bcwhite
2016/03/29 11:53:27
First param? To what? Or do you mean the first m
Alexei Svitkine (slow)
2016/03/29 17:51:24
Sorry, I did mean first member.
bcwhite
2016/03/30 21:25:55
Done. Though like I said, there doesn't seem to b
| |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProvider); | |
87 }; | |
88 | |
89 } // namespace metrics | |
90 | |
91 #endif // CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ | |
OLD | NEW |