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 { |
| 30 public: |
| 31 SubprocessMetricsProvider(); |
| 32 ~SubprocessMetricsProvider() override; |
| 33 |
| 34 private: |
| 35 friend class SubprocessMetricsProviderTest; |
| 36 FRIEND_TEST_ALL_PREFIXES(SubprocessMetricsProviderTest, SnapshotMetrics); |
| 37 |
| 38 // Indicates subprocess to be monitored with unique id for later reference. |
| 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::MetricsDataProvider: |
| 54 void RecordHistogramSnapshots( |
| 55 base::HistogramSnapshotManager* snapshot_manager) override; |
| 56 |
| 57 // content::NotificationObserver: |
| 58 void Observe(int type, |
| 59 const content::NotificationSource& source, |
| 60 const content::NotificationDetails& details) override; |
| 61 |
| 62 // content::RenderProcessHostObserver: |
| 63 void RenderProcessReady(content::RenderProcessHost* host) override; |
| 64 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; |
| 65 |
| 66 // Object for registing notification requests. |
| 67 content::NotificationRegistrar registrar_; |
| 68 |
| 69 // All of the shared-persistent-allocators for known sub-processes. |
| 70 using AllocatorByIdMap = |
| 71 IDMap<base::PersistentHistogramAllocator, IDMapOwnPointer, int>; |
| 72 AllocatorByIdMap allocators_by_id_; |
| 73 |
| 74 // Allocators that are no longer attached to a subprocess, to be released |
| 75 // once the last data contained therein has been reported. |
| 76 std::vector<scoped_ptr<base::PersistentHistogramAllocator>> |
| 77 allocators_to_release_; |
| 78 |
| 79 // Track all observed render processes to un-observe them on exit. |
| 80 ScopedObserver<content::RenderProcessHost, SubprocessMetricsProvider> |
| 81 scoped_observer_; |
| 82 |
| 83 base::ThreadChecker thread_checker_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProvider); |
| 86 }; |
| 87 |
| 88 #endif // CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ |
OLD | NEW |