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

Unified Diff: chrome/browser/metrics/subprocess_metrics_provider.h

Issue 1671933002: Create and pass shared-histogram-allocator from browser to renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hsm-merge
Patch Set: cleanup on RenderProcessHostDestroyed instead of RenderProcessExited; use existing ScopedObserver c… Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698