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

Unified Diff: services/blamer/public/cpp/blame_node.h

Issue 2885363004: [Hacky prototype] Create a shared-memory high-performance reporting service.
Patch Set: 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/blamer/public/cpp/blame_node.h
diff --git a/services/blamer/public/cpp/blame_node.h b/services/blamer/public/cpp/blame_node.h
new file mode 100644
index 0000000000000000000000000000000000000000..1d92dcc2bb08770e9c7394838963180952ca7ac0
--- /dev/null
+++ b/services/blamer/public/cpp/blame_node.h
@@ -0,0 +1,102 @@
+// 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_BLAMER_PUBLIC_CPP_BLAME_NODE_H_
+#define SERVICES_BLAMER_PUBLIC_CPP_BLAME_NODE_H_
+
+#include "base/memory/ref_counted.h"
+
+#include <vector>
+
+#include "services/blamer/public/cpp/blame_classes.h"
+
+namespace blamer {
+
+struct FlatBlameNode;
+
+// A node is a logical unit to which we want to attribute resource consumption
+// (CPU, network, memory usage, power, disk, etc). An example of a node is an
+// <iframe> element on a web page, or a "tab" on in a browser window. The
+// collection of all nodes implicitly creates a DAG (nodes may have multiple
+// parents) with a single implicit common root (the browser).
+//
+// A BlameNode should be constructed, attached to parents, attached to
+// equivalence classes, etc, and then finalized. Once it has been finalized it
+// will be committed to the shared memory buffer, visible by other processes and
+// able to be used to start collecting metrics.
+class BlameNode : public base::RefCounted<BlameNode> {
+ public:
+ // Constructs a blame node with the given class ID and object ID.
+ BlameNode(BlameClassId class_id, uint32_t object_id);
+
+ // Adds a parent to this BlameNode. This can be called repeatedly. Can only
+ // be called prior to committing this node.
+ void AddParent(scoped_refptr<BlameNode> parent);
+
+ // Adds an equivalence class to this BlameNode. Can only be called prior to
+ // committing this node.
+ void AddEquivalence(BlameClassId class_id, uint32_t equivalence_key);
+
+ // Commits this node.
+ void Commit();
+
+ FlatBlameNode* flat_blame_node() const { return flat_blame_node_; }
+ //FlatBlameData* flat_blame_data() const { return flat_blame_data_; }
+
+ private:
+ friend class base::RefCounted<BlameNode>;
+ using Equivalence = std::pair<BlameClassId, uint32_t>;
+
+ ~BlameNode();
+
+ std::vector<scoped_refptr<BlameNode>> parents_;
+ std::vector<Equivalence> equivalences_;
+
+ // Pointer to the exported blame node description for this node. This is
+ // initially null and only populated when committed.
+ FlatBlameNode* flat_blame_node_;
+
+ // Pointer to the exported blame data associated with this node. This is
+ // initially null and only populated when committed.
+ //FlatBlameData* flat_blame_data_;
+};
+
+// This acts as a lightweight reference to another blame node.
+struct FlatBlameNodeReference {
+ // The class ID to which the node belongs. Actually a BlameClassId.
+ uint32_t blame_class_id;
+ // The ID of the node. This is namespaced by |blame_class_id|.
+ uint32_t object_id;
+};
+
+// This describes an equivalence for a blame node.
+struct FlatBlameNodeEquivalence {
+ // The class ID to which the node belongs. Actually a BlameClassId.
+ uint32_t blame_class_id;
+ // The common key used by the remote object instance in order to tie the
+ // objects together. This is user defined.
+ uint32_t equivalence_key;
+};
+
+// This is a flat POD description of a blame node.
+struct FlatBlameNode {
+ // The class ID to which this node belongs. Actually a BlameClassId.
+ uint32_t blame_class_id;
+
+ // The proess-stable ID of the object this node represents. This is namespaced
+ // by |blame_class_id|.
+ uint32_t object_id;
+
+ // The number of parents this node has.
+ uint16_t parent_count;
+
+ // The number of equivalences this node has.
+ uint16_t equivalence_count;
+
+ // TODO
+};
+
+} // namespace blamer
+
+#endif // SERVICES_BLAMER_PUBLIC_CPP_BLAME_NODE_H_

Powered by Google App Engine
This is Rietveld 408576698