Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1015)

Side by Side Diff: chrome/browser/metrics/subprocess_metrics_provider.h

Issue 2023253002: Merge subprocess metrics into global StatisticsRecorder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: improved comment about when merges occur Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/scoped_observer.h" 13 #include "base/scoped_observer.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "components/metrics/metrics_provider.h" 15 #include "components/metrics/metrics_provider.h"
16 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 17 #include "content/public/browser/notification_registrar.h"
18 #include "content/public/browser/render_process_host_observer.h" 18 #include "content/public/browser/render_process_host_observer.h"
19 19
20 namespace base { 20 namespace base {
21 class PersistentHistogramAllocator; 21 class PersistentHistogramAllocator;
22 class SharedPersistentMemoryAllocator; 22 class SharedPersistentMemoryAllocator;
23 } 23 }
24 24
25 // SubprocessMetricsProvider gathers and logs histograms stored in shared 25 // SubprocessMetricsProvider gathers and merges histograms stored in shared
26 // memory segments between processes. 26 // memory segments between processes. Merging occurs when a process exits,
27 // when metrics are being collected for upload, or when something else needs
28 // combined metrics (such as the chrome://histograms page).
27 class SubprocessMetricsProvider : public metrics::MetricsProvider, 29 class SubprocessMetricsProvider : public metrics::MetricsProvider,
28 public content::NotificationObserver, 30 public content::NotificationObserver,
29 public content::RenderProcessHostObserver { 31 public content::RenderProcessHostObserver {
30 public: 32 public:
31 SubprocessMetricsProvider(); 33 SubprocessMetricsProvider();
32 ~SubprocessMetricsProvider() override; 34 ~SubprocessMetricsProvider() override;
33 35
34 private: 36 private:
35 friend class SubprocessMetricsProviderTest; 37 friend class SubprocessMetricsProviderTest;
36 38
37 // Indicates subprocess to be monitored with unique id for later reference. 39 // Indicates subprocess to be monitored with unique id for later reference.
38 // Metrics reporting will read histograms from it and upload them to UMA. 40 // Metrics reporting will read histograms from it and upload them to UMA.
39 void RegisterSubprocessAllocator( 41 void RegisterSubprocessAllocator(
40 int id, 42 int id,
41 std::unique_ptr<base::PersistentHistogramAllocator> allocator); 43 std::unique_ptr<base::PersistentHistogramAllocator> allocator);
42 44
43 // Indicates that a subprocess has exited and is thus finished with the 45 // Indicates that a subprocess has exited and is thus finished with the
44 // allocator it was using. 46 // allocator it was using.
45 void DeregisterSubprocessAllocator(int id); 47 void DeregisterSubprocessAllocator(int id);
46 48
47 // Report all histograms of a given allocator to the snapshot-manager. 49 // Merge all histograms of a given allocator to the global StatisticsRecorder.
48 void RecordHistogramSnapshotsFromAllocator( 50 // This is called periodically during UMA metrics collection (if enabled) and
49 base::HistogramSnapshotManager* snapshot_manager, 51 // possibly on-demand for other purposes.
52 void MergeHistogramDeltasFromAllocator(
50 int id, 53 int id,
51 base::PersistentHistogramAllocator* allocator); 54 base::PersistentHistogramAllocator* allocator);
52 55
53 // metrics::MetricsProvider: 56 // metrics::MetricsProvider:
54 void OnDidCreateMetricsLog() override; 57 void MergeHistogramDeltas() override;
55 void OnRecordingEnabled() override;
56 void OnRecordingDisabled() override;
57 void RecordHistogramSnapshots(
58 base::HistogramSnapshotManager* snapshot_manager) override;
59 58
60 // content::NotificationObserver: 59 // content::NotificationObserver:
61 void Observe(int type, 60 void Observe(int type,
62 const content::NotificationSource& source, 61 const content::NotificationSource& source,
63 const content::NotificationDetails& details) override; 62 const content::NotificationDetails& details) override;
64 63
65 // content::RenderProcessHostObserver: 64 // content::RenderProcessHostObserver:
66 void RenderProcessReady(content::RenderProcessHost* host) override; 65 void RenderProcessReady(content::RenderProcessHost* host) override;
67 void RenderProcessExited(content::RenderProcessHost* host, 66 void RenderProcessExited(content::RenderProcessHost* host,
68 base::TerminationStatus status, 67 base::TerminationStatus status,
69 int exit_code) override; 68 int exit_code) override;
70 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; 69 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
71 70
72 base::ThreadChecker thread_checker_; 71 base::ThreadChecker thread_checker_;
73 72
74 // Object for registing notification requests. 73 // Object for registing notification requests.
75 content::NotificationRegistrar registrar_; 74 content::NotificationRegistrar registrar_;
76 75
77 // All of the shared-persistent-allocators for known sub-processes. 76 // All of the shared-persistent-allocators for known sub-processes.
78 using AllocatorByIdMap = 77 using AllocatorByIdMap =
79 IDMap<base::PersistentHistogramAllocator, IDMapOwnPointer, int>; 78 IDMap<base::PersistentHistogramAllocator, IDMapOwnPointer, int>;
80 AllocatorByIdMap allocators_by_id_; 79 AllocatorByIdMap allocators_by_id_;
81 80
82 // Allocators that are no longer attached to a subprocess, to be released
83 // once the last data contained therein has been reported.
84 std::vector<std::unique_ptr<base::PersistentHistogramAllocator>>
85 allocators_for_exited_processes_;
86 std::vector<std::unique_ptr<base::PersistentHistogramAllocator>>
87 allocators_to_release_;
88
89 // Track all observed render processes to un-observe them on exit. 81 // Track all observed render processes to un-observe them on exit.
90 ScopedObserver<content::RenderProcessHost, SubprocessMetricsProvider> 82 ScopedObserver<content::RenderProcessHost, SubprocessMetricsProvider>
91 scoped_observer_; 83 scoped_observer_;
92 84
93 // Flag indicating if metrics recording is enabled. Allocators will not
94 // live past the death of the subprocess if it is not.
95 bool metrics_recording_enabled_ = false;
96
97 DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProvider); 85 DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProvider);
98 }; 86 };
99 87
100 #endif // CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ 88 #endif // CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_
OLDNEW
« no previous file with comments | « base/metrics/statistics_recorder.h ('k') | chrome/browser/metrics/subprocess_metrics_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698