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

Unified Diff: services/resource_coordinator/memory/coordinator/process_map.h

Issue 2883693002: [Memory-UMA] Implement basic working prototype. (Closed)
Patch Set: Respecify dependent CL, which had somehow gotten lost. Created 3 years, 7 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: services/resource_coordinator/memory/coordinator/process_map.h
diff --git a/services/resource_coordinator/memory/coordinator/process_map.h b/services/resource_coordinator/memory/coordinator/process_map.h
new file mode 100644
index 0000000000000000000000000000000000000000..f349e7a1d67f3f965d3aecd4d4b2b0b4d88e0213
--- /dev/null
+++ b/services/resource_coordinator/memory/coordinator/process_map.h
@@ -0,0 +1,68 @@
+// Copyright 2017 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 SERVICES_RESOURCE_COORDINATOR_MEMORY_COORDINATOR_PROCESS_MAP_H_
+#define SERVICES_RESOURCE_COORDINATOR_MEMORY_COORDINATOR_PROCESS_MAP_H_
+
+#include <unordered_map>
Primiano Tucci (use gerrit) 2017/05/15 03:48:10 s/unordered_map/map/ (see other comment below)
erikchen 2017/05/15 17:29:15 Done.
+#include <vector>
+
+#include "base/gtest_prod_util.h"
+#include "base/hash.h"
+#include "base/process/process_handle.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "services/resource_coordinator/public/interfaces/memory/memory_instrumentation.mojom.h"
+#include "services/service_manager/public/cpp/identity.h"
+#include "services/service_manager/public/interfaces/service_manager.mojom.h"
+
+namespace memory_instrumentation {
+
+struct IdentityHasher {
Primiano Tucci (use gerrit) 2017/05/15 03:48:10 no need of this. Use a std::map (see brett's post
erikchen 2017/05/15 17:29:15 Done.
+ std::size_t operator()(const service_manager::Identity& identity) const {
+ return base::Hash(identity.name() + identity.user_id() +
+ identity.instance());
+ }
+};
+
+// Maintains an unordered_map from service_manager::Identity to
+// base::ProcessId pid. This allows |pid| lookup by service_manager::Identity.
+class ProcessMap : public service_manager::mojom::ServiceManagerListener {
+ public:
+ ProcessMap();
+ ~ProcessMap() override;
+
+ // Must be called exactly once to start receiving callbacks.
+ void BindRequest(
+ service_manager::mojom::ServiceManagerListenerRequest request);
Primiano Tucci (use gerrit) 2017/05/15 03:48:10 if you just pass the Connector in the ctor there i
erikchen 2017/05/15 17:29:15 Done.
+
+ base::ProcessId GetProcessId(service_manager::Identity identity) const;
+
+ protected:
+ private:
+ FRIEND_TEST_ALL_PREFIXES(ProcessMapTest, TypicalCase);
+ FRIEND_TEST_ALL_PREFIXES(ProcessMapTest, PresentInInit);
+
+ using RunningServiceInfoPtr = service_manager::mojom::RunningServiceInfoPtr;
+
+ // Overridden from service_manager::mojom::ServiceManagerListener:
+ void OnInit(std::vector<RunningServiceInfoPtr> instances) override;
+
+ void OnServiceCreated(RunningServiceInfoPtr instance) override;
+
+ void OnServiceStarted(const service_manager::Identity& identity,
+ uint32_t pid) override;
+ void OnServiceFailedToStart(
+ const service_manager::Identity& identity) override {}
+
+ void OnServiceStopped(const service_manager::Identity& identity) override;
+
+ mojo::Binding<service_manager::mojom::ServiceManagerListener> binding_;
+ std::unordered_map<service_manager::Identity, base::ProcessId, IdentityHasher>
+ instances_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProcessMap);
+};
+
+} // namespace memory_instrumentation
+#endif // SERVICES_RESOURCE_COORDINATOR_MEMORY_COORDINATOR_PROCESS_MAP_H_

Powered by Google App Engine
This is Rietveld 408576698