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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef SERVICES_BLAMER_PUBLIC_CPP_BLAME_NODE_H_
6 #define SERVICES_BLAMER_PUBLIC_CPP_BLAME_NODE_H_
7
8 #include "base/memory/ref_counted.h"
9
10 #include <vector>
11
12 #include "services/blamer/public/cpp/blame_classes.h"
13
14 namespace blamer {
15
16 struct FlatBlameNode;
17
18 // A node is a logical unit to which we want to attribute resource consumption
19 // (CPU, network, memory usage, power, disk, etc). An example of a node is an
20 // <iframe> element on a web page, or a "tab" on in a browser window. The
21 // collection of all nodes implicitly creates a DAG (nodes may have multiple
22 // parents) with a single implicit common root (the browser).
23 //
24 // A BlameNode should be constructed, attached to parents, attached to
25 // equivalence classes, etc, and then finalized. Once it has been finalized it
26 // will be committed to the shared memory buffer, visible by other processes and
27 // able to be used to start collecting metrics.
28 class BlameNode : public base::RefCounted<BlameNode> {
29 public:
30 // Constructs a blame node with the given class ID and object ID.
31 BlameNode(BlameClassId class_id, uint32_t object_id);
32
33 // Adds a parent to this BlameNode. This can be called repeatedly. Can only
34 // be called prior to committing this node.
35 void AddParent(scoped_refptr<BlameNode> parent);
36
37 // Adds an equivalence class to this BlameNode. Can only be called prior to
38 // committing this node.
39 void AddEquivalence(BlameClassId class_id, uint32_t equivalence_key);
40
41 // Commits this node.
42 void Commit();
43
44 FlatBlameNode* flat_blame_node() const { return flat_blame_node_; }
45 //FlatBlameData* flat_blame_data() const { return flat_blame_data_; }
46
47 private:
48 friend class base::RefCounted<BlameNode>;
49 using Equivalence = std::pair<BlameClassId, uint32_t>;
50
51 ~BlameNode();
52
53 std::vector<scoped_refptr<BlameNode>> parents_;
54 std::vector<Equivalence> equivalences_;
55
56 // Pointer to the exported blame node description for this node. This is
57 // initially null and only populated when committed.
58 FlatBlameNode* flat_blame_node_;
59
60 // Pointer to the exported blame data associated with this node. This is
61 // initially null and only populated when committed.
62 //FlatBlameData* flat_blame_data_;
63 };
64
65 // This acts as a lightweight reference to another blame node.
66 struct FlatBlameNodeReference {
67 // The class ID to which the node belongs. Actually a BlameClassId.
68 uint32_t blame_class_id;
69 // The ID of the node. This is namespaced by |blame_class_id|.
70 uint32_t object_id;
71 };
72
73 // This describes an equivalence for a blame node.
74 struct FlatBlameNodeEquivalence {
75 // The class ID to which the node belongs. Actually a BlameClassId.
76 uint32_t blame_class_id;
77 // The common key used by the remote object instance in order to tie the
78 // objects together. This is user defined.
79 uint32_t equivalence_key;
80 };
81
82 // This is a flat POD description of a blame node.
83 struct FlatBlameNode {
84 // The class ID to which this node belongs. Actually a BlameClassId.
85 uint32_t blame_class_id;
86
87 // The proess-stable ID of the object this node represents. This is namespaced
88 // by |blame_class_id|.
89 uint32_t object_id;
90
91 // The number of parents this node has.
92 uint16_t parent_count;
93
94 // The number of equivalences this node has.
95 uint16_t equivalence_count;
96
97 // TODO
98 };
99
100 } // namespace blamer
101
102 #endif // SERVICES_BLAMER_PUBLIC_CPP_BLAME_NODE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698