| 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 <memory> | |
| 9 #include <set> | |
| 10 | |
| 11 #include "base/gtest_prod_util.h" | |
| 12 #include "base/id_map.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 { | |
| 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 std::unique_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 RenderProcessExited(content::RenderProcessHost* host, | |
| 67 base::TerminationStatus status, | |
| 68 int exit_code) override; | |
| 69 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; | |
| 70 | |
| 71 base::ThreadChecker thread_checker_; | |
| 72 | |
| 73 // Object for registing notification requests. | |
| 74 content::NotificationRegistrar registrar_; | |
| 75 | |
| 76 // All of the shared-persistent-allocators for known sub-processes. | |
| 77 using AllocatorByIdMap = | |
| 78 IDMap<base::PersistentHistogramAllocator, IDMapOwnPointer, int>; | |
| 79 AllocatorByIdMap allocators_by_id_; | |
| 80 | |
| 81 // Allocators that are no longer attached to a subprocess, to be released | |
| 82 // once the last data contained therein has been reported. | |
| 83 std::vector<std::unique_ptr<base::PersistentHistogramAllocator>> | |
| 84 allocators_to_release_; | |
| 85 | |
| 86 // Track all observed render processes to un-observe them on exit. | |
| 87 ScopedObserver<content::RenderProcessHost, SubprocessMetricsProvider> | |
| 88 scoped_observer_; | |
| 89 | |
| 90 // Flag indicating if metrics recording is enabled. Allocators will not | |
| 91 // live past the death of the subprocess if it is not. | |
| 92 bool metrics_recording_enabled_ = false; | |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProvider); | |
| 95 }; | |
| 96 | |
| 97 #endif // CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ | |
| OLD | NEW |