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

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

Issue 2224063002: Use persistent memory for receiving metrics from sub-processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/metrics/subprocess_metrics_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/memory/weak_ptr.h"
13 #include "base/scoped_observer.h" 14 #include "base/scoped_observer.h"
14 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
15 #include "components/metrics/metrics_provider.h" 16 #include "components/metrics/metrics_provider.h"
17 #include "content/public/browser/browser_child_process_observer.h"
16 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
18 #include "content/public/browser/render_process_host_observer.h" 20 #include "content/public/browser/render_process_host_observer.h"
19 21
20 namespace base { 22 namespace base {
21 class PersistentHistogramAllocator; 23 class PersistentHistogramAllocator;
22 class SharedPersistentMemoryAllocator; 24 class SharedPersistentMemoryAllocator;
23 } 25 }
24 26
25 // SubprocessMetricsProvider gathers and merges histograms stored in shared 27 // SubprocessMetricsProvider gathers and merges histograms stored in shared
26 // memory segments between processes. Merging occurs when a process exits, 28 // memory segments between processes. Merging occurs when a process exits,
27 // when metrics are being collected for upload, or when something else needs 29 // when metrics are being collected for upload, or when something else needs
28 // combined metrics (such as the chrome://histograms page). 30 // combined metrics (such as the chrome://histograms page).
29 class SubprocessMetricsProvider : public metrics::MetricsProvider, 31 class SubprocessMetricsProvider : public metrics::MetricsProvider,
32 public content::BrowserChildProcessObserver,
30 public content::NotificationObserver, 33 public content::NotificationObserver,
31 public content::RenderProcessHostObserver { 34 public content::RenderProcessHostObserver {
32 public: 35 public:
33 SubprocessMetricsProvider(); 36 SubprocessMetricsProvider();
34 ~SubprocessMetricsProvider() override; 37 ~SubprocessMetricsProvider() override;
35 38
36 private: 39 private:
37 friend class SubprocessMetricsProviderTest; 40 friend class SubprocessMetricsProviderTest;
38 41
39 // Indicates subprocess to be monitored with unique id for later reference. 42 // Indicates subprocess to be monitored with unique id for later reference.
40 // Metrics reporting will read histograms from it and upload them to UMA. 43 // Metrics reporting will read histograms from it and upload them to UMA.
41 void RegisterSubprocessAllocator( 44 void RegisterSubprocessAllocator(
42 int id, 45 int id,
43 std::unique_ptr<base::PersistentHistogramAllocator> allocator); 46 std::unique_ptr<base::PersistentHistogramAllocator> allocator);
44 47
45 // Indicates that a subprocess has exited and is thus finished with the 48 // Indicates that a subprocess has exited and is thus finished with the
46 // allocator it was using. 49 // allocator it was using.
47 void DeregisterSubprocessAllocator(int id); 50 void DeregisterSubprocessAllocator(int id);
48 51
49 // Merge all histograms of a given allocator to the global StatisticsRecorder. 52 // Merge all histograms of a given allocator to the global StatisticsRecorder.
50 // This is called periodically during UMA metrics collection (if enabled) and 53 // This is called periodically during UMA metrics collection (if enabled) and
51 // possibly on-demand for other purposes. 54 // possibly on-demand for other purposes.
52 void MergeHistogramDeltasFromAllocator( 55 void MergeHistogramDeltasFromAllocator(
53 int id, 56 int id,
54 base::PersistentHistogramAllocator* allocator); 57 base::PersistentHistogramAllocator* allocator);
55 58
56 // metrics::MetricsProvider: 59 // metrics::MetricsProvider:
57 void MergeHistogramDeltas() override; 60 void MergeHistogramDeltas() override;
58 61
62 // content::BrowserChildProcessObserver:
63 void BrowserChildProcessHostConnected(
64 const content::ChildProcessData& data) override;
65 void BrowserChildProcessHostDisconnected(
66 const content::ChildProcessData& data) override;
67 void BrowserChildProcessCrashed(
68 const content::ChildProcessData& data,
69 int exit_code) override;
70 void BrowserChildProcessKilled(
71 const content::ChildProcessData& data,
72 int exit_code) override;
73
59 // content::NotificationObserver: 74 // content::NotificationObserver:
60 void Observe(int type, 75 void Observe(int type,
61 const content::NotificationSource& source, 76 const content::NotificationSource& source,
62 const content::NotificationDetails& details) override; 77 const content::NotificationDetails& details) override;
63 78
64 // content::RenderProcessHostObserver: 79 // content::RenderProcessHostObserver:
65 void RenderProcessReady(content::RenderProcessHost* host) override; 80 void RenderProcessReady(content::RenderProcessHost* host) override;
66 void RenderProcessExited(content::RenderProcessHost* host, 81 void RenderProcessExited(content::RenderProcessHost* host,
67 base::TerminationStatus status, 82 base::TerminationStatus status,
68 int exit_code) override; 83 int exit_code) override;
69 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; 84 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
70 85
86 // Gets a histogram allocator from a subprocess. This must be called on
87 // the IO thread.
88 static std::unique_ptr<base::PersistentHistogramAllocator>
89 GetSubprocessHistogramAllocatorOnIOThread(int id);
90
71 base::ThreadChecker thread_checker_; 91 base::ThreadChecker thread_checker_;
72 92
73 // Object for registing notification requests. 93 // Object for registing notification requests.
74 content::NotificationRegistrar registrar_; 94 content::NotificationRegistrar registrar_;
75 95
76 // All of the shared-persistent-allocators for known sub-processes. 96 // All of the shared-persistent-allocators for known sub-processes.
77 using AllocatorByIdMap = 97 using AllocatorByIdMap =
78 IDMap<base::PersistentHistogramAllocator, IDMapOwnPointer, int>; 98 IDMap<base::PersistentHistogramAllocator, IDMapOwnPointer, int>;
79 AllocatorByIdMap allocators_by_id_; 99 AllocatorByIdMap allocators_by_id_;
80 100
81 // Track all observed render processes to un-observe them on exit. 101 // Track all observed render processes to un-observe them on exit.
82 ScopedObserver<content::RenderProcessHost, SubprocessMetricsProvider> 102 ScopedObserver<content::RenderProcessHost, SubprocessMetricsProvider>
83 scoped_observer_; 103 scoped_observer_;
84 104
105 base::WeakPtrFactory<SubprocessMetricsProvider> weak_ptr_factory_;
106
85 DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProvider); 107 DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProvider);
86 }; 108 };
87 109
88 #endif // CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ 110 #endif // CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/metrics/subprocess_metrics_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698