Index: chrome/browser/metrics/subprocess_metrics_provider.h |
diff --git a/chrome/browser/metrics/subprocess_metrics_provider.h b/chrome/browser/metrics/subprocess_metrics_provider.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..538b0031c44e907cb4907cd53c29d93fb2b70e1e |
--- /dev/null |
+++ b/chrome/browser/metrics/subprocess_metrics_provider.h |
@@ -0,0 +1,91 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ |
+#define CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ |
+ |
+#include <set> |
+ |
+#include "base/gtest_prod_util.h" |
+#include "base/id_map.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/scoped_observer.h" |
+#include "base/threading/thread_checker.h" |
+#include "components/metrics/metrics_provider.h" |
+#include "content/public/browser/notification_observer.h" |
+#include "content/public/browser/notification_registrar.h" |
+#include "content/public/browser/render_process_host_observer.h" |
+ |
+namespace base { |
+class SharedPersistentMemoryAllocator; |
+} |
+ |
+namespace metrics { |
+ |
+// SubprocessMetricsProvider gathers and logs histograms stored in shared |
+// memory segments between processes. |
+class SubprocessMetricsProvider : public metrics::MetricsProvider, |
+ public content::NotificationObserver, |
+ public content::RenderProcessHostObserver { |
+ public: |
+ SubprocessMetricsProvider(); |
+ ~SubprocessMetricsProvider() override; |
+ |
+ private: |
+ friend class SubprocessMetricsProviderTest; |
+ FRIEND_TEST_ALL_PREFIXES(SubprocessMetricsProviderTest, SnapshotMetrics); |
+ |
+ // Indicates subprocess to be monitored with unique id for later reference. |
+ void RegisterSubprocessAllocator( |
+ int id, |
+ scoped_ptr<base::SharedPersistentMemoryAllocator> allocator); |
+ |
+ // Indicates that a subprocess has exited and is thus finished with the |
+ // allocator it was using. |
+ void DeregisterSubprocessAllocator(int id); |
+ |
+ // Report all histograms of a given allocator to the snapshot-manager. |
+ void RecordHistogramSnapshotsFromAllocator( |
+ base::HistogramSnapshotManager* snapshot_manager, |
+ int id, |
+ base::SharedPersistentMemoryAllocator* allocator); |
+ |
+ // metrics::MetricsDataProvider: |
+ void RecordHistogramSnapshots( |
+ base::HistogramSnapshotManager* snapshot_manager) override; |
+ |
+ // content::NotificationObserver overrides: |
Alexei Svitkine (slow)
2016/03/24 17:29:53
Nit: Remove " overrides" here and on line 63.
bcwhite
2016/03/29 11:53:27
Done.
|
+ void Observe(int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) override; |
+ |
+ // content::RenderProcessHostObserver overrides: |
+ void RenderProcessReady(content::RenderProcessHost* host) override; |
+ void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; |
+ |
+ // Object for registing notification requests. |
+ content::NotificationRegistrar registrar_; |
+ |
+ // All of the shared-persistent-allocators for known sub-processes. |
+ using AllocatorByIdMap = |
+ IDMap<base::SharedPersistentMemoryAllocator, IDMapOwnPointer, int>; |
+ AllocatorByIdMap allocators_by_id_; |
+ |
+ // Allocators that are no longer attached to a subprocess, to be released |
+ // once the last data contained therein has been reported. |
+ std::vector<scoped_ptr<base::SharedPersistentMemoryAllocator>> |
+ allocators_to_release_; |
+ |
+ // Track all observed render processes to un-observe them on exit. |
+ ScopedObserver<content::RenderProcessHost, SubprocessMetricsProvider> |
+ scoped_observer_; |
+ |
+ base::ThreadChecker thread_checker_; |
Alexei Svitkine (slow)
2016/03/24 17:29:53
Nit: Make this the first param.
bcwhite
2016/03/29 11:53:27
First param? To what? Or do you mean the first m
Alexei Svitkine (slow)
2016/03/29 17:51:24
Sorry, I did mean first member.
bcwhite
2016/03/30 21:25:55
Done. Though like I said, there doesn't seem to b
|
+ |
+ DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProvider); |
+}; |
+ |
+} // namespace metrics |
+ |
+#endif // CHROME_BROWSER_METRICS_SUBPROCESS_METRICS_PROVIDER_H_ |