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

Side by Side Diff: services/blamer/public/cpp/blame_classes.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 // Defines all known classes of nodes for attribution, as well as descriptions
6 // of their equivalence classes and possible relationships.
7
8 #ifndef SERVICES_BLAMER_PUBLIC_CPP_BLAME_CLASSES_H_
9 #define SERVICES_BLAMER_PUBLIC_CPP_BLAME_CLASSES_H_
10
11 #include "base/hash.h"
12
13 namespace blamer {
14
15 // An enumeration of all known classes. New ones should strictly be added to
16 // the end. Retired classes should be marked as deprecated, and their slots
17 // should not be reused. This ensures that IDs are stable across Chrome
18 // versions.
19 enum class BlameClassId : uint32_t {
20 // This is reserved and used as a sentinel value.
21 UNDEFINED = 0,
22
23 V8_ISOLATE,
24 CONTENT_WEBVIEW,
25 CONTENT_FRAME_TREE_NODE,
26 CONTENT_RENDER_FRAME,
27 BLINK_LOCAL_FRAME,
28 BLINK_REMOTE_FRAME,
29 // New classes should be added here.
30
31 // This should always be last.
32 MAX
33 };
34
35 // TODO(chrisha): Build "class descriptions", which allow the class to be
36 // introspected at runtime. This could include valid parent types, valid child
37 // types, valid equivalent class types, etc. This should be present in all
38 // process types.
39
40 // Templated class for generating IDs given an instance of an object. Each
41 // process is expected to have defined one of these for any blame classes that
42 // occur in the context of that process. It should satisfy the following
43 // interface:
44 //
45 // // Generate an ID for the given object type. Two equivalent objects in
46 // // distinct processes should generate the same ID.
47 // static uint32_t GenerateId(const ObjectType& object);
48 //
49 // By default the implementation of GenerateId will make a call to the following
50 // function:
51 //
52 // static void SerializeObject(const ObjectType& object,
53 // std::vector<uint8_t>* buffer);
54 //
55 // Specializations of this class may choose to implement SerializeObject, or
56 // to override GenerateId directly.
57 template<typename ObjectType>
58 class BlameClassIdGenerator {
59 public:
60 // Generate an ID for the given object type. Does so by hashing the results of
61 // SerializeObject().
62 static uint32_t GenerateId(const ObjectType& object) {
63 std::vector<uint8_t> buffer;
64 SerializeObject(object, &buffer);
65 return base::SuperFastHash(buffer.data(), buffer.size());
66 }
67 };
68
69 } // namespace blamer
70
71 #endif // SERVICES_BLAMER_PUBLIC_CPP_BLAME_CLASSES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698