Chromium Code Reviews| 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 PersistentHistogramAllocator; | |
| 22 class SharedPersistentMemoryAllocator; | |
| 23 } | |
| 24 | |
| 25 // SubprocessMetricsProvider gathers and logs histograms stored in shared | |
| 26 // memory segments between processes. | |
| 27 class SubprocessMetricsProvider : public metrics::MetricsProvider, | |
| 28 public content::NotificationObserver, | |
| 29 public content::RenderProcessHostObserver { | |
|
grt (UTC plus 2)
2016/04/01 14:22:48
rather than being a generic subprocess metrics pro
bcwhite
2016/04/01 16:50:26
It doesn't apply only to renderers. It's just tha
| |
| 30 public: | |
| 31 SubprocessMetricsProvider(); | |
| 32 ~SubprocessMetricsProvider() override; | |
| 33 | |
| 34 private: | |
| 35 friend class SubprocessMetricsProviderTest; | |
| 36 | |
| 37 // Indicates subprocess to be monitored with unique id for later reference. | |
| 38 // Metrics reporting will read histograms from it and upload them to UMA. | |
| 39 void RegisterSubprocessAllocator( | |
| 40 int id, | |
| 41 scoped_ptr<base::PersistentHistogramAllocator> allocator); | |
| 42 | |
| 43 // Indicates that a subprocess has exited and is thus finished with the | |
| 44 // allocator it was using. | |
| 45 void DeregisterSubprocessAllocator(int id); | |
| 46 | |
| 47 // Report all histograms of a given allocator to the snapshot-manager. | |
| 48 void RecordHistogramSnapshotsFromAllocator( | |
| 49 base::HistogramSnapshotManager* snapshot_manager, | |
| 50 int id, | |
| 51 base::PersistentHistogramAllocator* allocator); | |
| 52 | |
| 53 // metrics::MetricsProvider: | |
| 54 void OnRecordingEnabled() override; | |
| 55 void OnRecordingDisabled() override; | |
| 56 void RecordHistogramSnapshots( | |
| 57 base::HistogramSnapshotManager* snapshot_manager) override; | |
| 58 | |
| 59 // content::NotificationObserver: | |
| 60 void Observe(int type, | |
| 61 const content::NotificationSource& source, | |
| 62 const content::NotificationDetails& details) override; | |
| 63 | |
| 64 // content::RenderProcessHostObserver: | |
| 65 void RenderProcessReady(content::RenderProcessHost* host) override; | |
| 66 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; | |
| 67 | |
| 68 base::ThreadChecker thread_checker_; | |
| 69 | |
| 70 // Object for registing notification requests. | |
| 71 content::NotificationRegistrar registrar_; | |
| 72 | |
| 73 // All of the shared-persistent-allocators for known sub-processes. | |
| 74 using AllocatorByIdMap = | |
| 75 IDMap<base::PersistentHistogramAllocator, IDMapOwnPointer, int>; | |
| 76 AllocatorByIdMap allocators_by_id_; | |
| 77 | |
| 78 // Allocators that are no longer attached to a subprocess, to be released | |
| 79 // once the last data contained therein has been reported. | |
| 80 std::vector<scoped_ptr<base::PersistentHistogramAllocator>> | |
| 81 allocators_to_release_; | |
| 82 | |
| 83 // Track all observed render processes to un-observe them on exit. | |
| 84 ScopedObserver<content::RenderProcessHost, SubprocessMetricsProvider> | |
| 85 scoped_observer_; | |
| 86 | |
| 87 // Flag indicating if metrics recording is enabled. Allocators will not | |
| 88 // live past the death of the subprocess if it is not. | |
| 89 bool metrics_recording_enabled_ = false; | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProvider); | |
| 92 }; | |
| 93 | |
| 94 #endif // CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ | |
| OLD | NEW |