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

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

Issue 1880803003: Display histograms from subprocesses in chrome://histograms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 8 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 <map>
8 #include <memory> 9 #include <memory>
9 #include <set> 10 #include <vector>
10 11
11 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
12 #include "base/id_map.h" 13 #include "base/metrics/statistics_recorder.h"
13 #include "base/scoped_observer.h" 14 #include "base/scoped_observer.h"
14 #include "base/threading/thread_checker.h" 15 #include "base/synchronization/lock.h"
Ilya Sherman 2016/04/25 20:53:15 On the subject of locks: I've now researched how t
bcwhite 2016/04/26 19:51:54 I'll look into it. There are two calls, one from
Ilya Sherman 2016/04/26 20:21:58 Which base/ code are you thinking of, specifically
bcwhite 2016/04/26 21:03:30 base/metrics/statistics_recorder, which is the com
15 #include "components/metrics/metrics_provider.h" 16 #include "components/metrics/metrics_provider.h"
16 #include "content/public/browser/notification_observer.h" 17 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 18 #include "content/public/browser/notification_registrar.h"
18 #include "content/public/browser/render_process_host_observer.h" 19 #include "content/public/browser/render_process_host_observer.h"
19 20
20 namespace base { 21 namespace base {
21 class PersistentHistogramAllocator; 22 class PersistentHistogramAllocator;
22 class SharedPersistentMemoryAllocator; 23 class SharedPersistentMemoryAllocator;
23 } 24 }
24 25
25 // SubprocessMetricsProvider gathers and logs histograms stored in shared 26 // SubprocessMetricsProvider gathers and logs histograms stored in shared
26 // memory segments between processes. 27 // memory segments between processes.
27 class SubprocessMetricsProvider : public metrics::MetricsProvider, 28 class SubprocessMetricsProvider
28 public content::NotificationObserver, 29 : public metrics::MetricsProvider,
29 public content::RenderProcessHostObserver { 30 public base::StatisticsRecorder::MetricsDisplayer,
31 public content::NotificationObserver,
32 public content::RenderProcessHostObserver {
30 public: 33 public:
31 SubprocessMetricsProvider(); 34 SubprocessMetricsProvider();
32 ~SubprocessMetricsProvider() override; 35 ~SubprocessMetricsProvider() override;
33 36
34 private: 37 private:
35 friend class SubprocessMetricsProviderTest; 38 friend class SubprocessMetricsProviderTest;
36 39
37 // Indicates subprocess to be monitored with unique id for later reference. 40 // Indicates subprocess to be monitored with unique id for later reference.
38 // Metrics reporting will read histograms from it and upload them to UMA. 41 // Metrics reporting will read histograms from it and upload them to UMA.
39 void RegisterSubprocessAllocator( 42 void RegisterSubprocessAllocator(
40 int id, 43 int id,
41 std::unique_ptr<base::PersistentHistogramAllocator> allocator); 44 std::unique_ptr<base::PersistentHistogramAllocator> allocator);
42 45
43 // Indicates that a subprocess has exited and is thus finished with the 46 // Indicates that a subprocess has exited and is thus finished with the
44 // allocator it was using. 47 // allocator it was using.
45 void DeregisterSubprocessAllocator(int id); 48 void DeregisterSubprocessAllocator(int id);
46 49
47 // Report all histograms of a given allocator to the snapshot-manager. 50 // Report histograms of a given allocator to the snapshot-manager. If
51 // |query| is not empty, only histograms that contain that string will
52 // be recorded. If |absolute| is true, no delta from the previous snapshot
53 // will be done. Only one caller, the caller that uploads to UMA, is
54 // allowed to calcuate deltas because they are not independent.
48 void RecordHistogramSnapshotsFromAllocator( 55 void RecordHistogramSnapshotsFromAllocator(
49 base::HistogramSnapshotManager* snapshot_manager, 56 base::HistogramSnapshotManager* snapshot_manager,
57 const std::string& query,
58 bool absolute,
50 int id, 59 int id,
51 base::PersistentHistogramAllocator* allocator); 60 base::PersistentHistogramAllocator* allocator);
52 61
53 // metrics::MetricsProvider: 62 // metrics::MetricsProvider:
54 void OnDidCreateMetricsLog() override; 63 void OnDidCreateMetricsLog() override;
55 void OnRecordingEnabled() override; 64 void OnRecordingEnabled() override;
56 void OnRecordingDisabled() override; 65 void OnRecordingDisabled() override;
57 void RecordHistogramSnapshots( 66 void RecordHistogramSnapshots(
58 base::HistogramSnapshotManager* snapshot_manager) override; 67 base::HistogramSnapshotManager* snapshot_manager) override;
59 68
69 // base::StatisticsRecorder::MetricsDisplay:
Ilya Sherman 2016/04/25 20:53:15 nit: displayer
bcwhite 2016/04/26 19:51:54 Done.
70 void WriteTitleString(std::string* output) override;
71 void WriteGraphs(const std::string& query,
72 DisplayType format,
73 std::string* output) override;
74
60 // content::NotificationObserver: 75 // content::NotificationObserver:
61 void Observe(int type, 76 void Observe(int type,
62 const content::NotificationSource& source, 77 const content::NotificationSource& source,
63 const content::NotificationDetails& details) override; 78 const content::NotificationDetails& details) override;
64 79
65 // content::RenderProcessHostObserver: 80 // content::RenderProcessHostObserver:
66 void RenderProcessReady(content::RenderProcessHost* host) override; 81 void RenderProcessReady(content::RenderProcessHost* host) override;
67 void RenderProcessExited(content::RenderProcessHost* host, 82 void RenderProcessExited(content::RenderProcessHost* host,
68 base::TerminationStatus status, 83 base::TerminationStatus status,
69 int exit_code) override; 84 int exit_code) override;
70 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; 85 void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
71 86
72 base::ThreadChecker thread_checker_; 87 // Lock for accessing objects. This is required because MetricsDisplay is
Ilya Sherman 2016/04/25 20:53:15 nit: displayer
bcwhite 2016/04/26 19:51:54 Done.
88 // typically called by a background thread.
89 base::Lock lock_;
73 90
74 // Object for registing notification requests. 91 // Object for registing notification requests.
75 content::NotificationRegistrar registrar_; 92 content::NotificationRegistrar registrar_;
76 93
77 // All of the shared-persistent-allocators for known sub-processes. 94 // All of the shared-persistent-allocators for known sub-processes.
78 using AllocatorByIdMap = 95 using AllocatorByIdMap =
79 IDMap<base::PersistentHistogramAllocator, IDMapOwnPointer, int>; 96 std::map<int, std::unique_ptr<base::PersistentHistogramAllocator>>;
Ilya Sherman 2016/04/25 20:53:15 This change seems unrelated to the rest of the CL.
bcwhite 2016/04/26 19:51:54 IDmap allows access only from a single thread. I
80 AllocatorByIdMap allocators_by_id_; 97 AllocatorByIdMap allocators_by_id_;
81 98
82 // Allocators that are no longer attached to a subprocess, to be released 99 // Allocators that are no longer attached to a subprocess, to be released
83 // once the last data contained therein has been reported. 100 // once the last data contained therein has been reported.
84 std::vector<std::unique_ptr<base::PersistentHistogramAllocator>> 101 std::vector<std::unique_ptr<base::PersistentHistogramAllocator>>
85 allocators_for_exited_processes_; 102 allocators_for_exited_processes_;
86 std::vector<std::unique_ptr<base::PersistentHistogramAllocator>> 103 std::vector<std::unique_ptr<base::PersistentHistogramAllocator>>
87 allocators_to_release_; 104 allocators_to_release_;
88 105
89 // Track all observed render processes to un-observe them on exit. 106 // Track all observed render processes to un-observe them on exit.
90 ScopedObserver<content::RenderProcessHost, SubprocessMetricsProvider> 107 ScopedObserver<content::RenderProcessHost, SubprocessMetricsProvider>
91 scoped_observer_; 108 scoped_observer_;
92 109
93 // Flag indicating if metrics recording is enabled. Allocators will not 110 // Flag indicating if metrics recording is enabled. Allocators will not
94 // live past the death of the subprocess if it is not. 111 // live past the death of the subprocess if it is not.
95 bool metrics_recording_enabled_ = false; 112 bool metrics_recording_enabled_ = false;
96 113
97 DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProvider); 114 DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProvider);
98 }; 115 };
99 116
100 #endif // CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ 117 #endif // CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698