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

Side by Side Diff: base/trace_event/category_registry.h

Issue 2452063003: tracing: split out the CategoryRegistry from the TraceLog (Closed)
Patch Set: add tests, rebase Created 4 years, 1 month 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
« no previous file with comments | « base/BUILD.gn ('k') | base/trace_event/category_registry.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 BASE_TRACE_EVENT_CATEGORY_H_
6 #define BASE_TRACE_EVENT_CATEGORY_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include "base/base_export.h"
12 #include "base/logging.h"
13
14 namespace base {
15 namespace trace_event {
16
17 struct TraceCategory;
18 class TraceCategoryTest;
19 class TraceLog;
20
21 // Keeps track of the state of all tracing categories. The reason why this
22 // is a fully static class with global state is to allow to statically define
23 // known categories as global linker-initialized structs, without requiring
24 // static initializers.
25 class BASE_EXPORT CategoryRegistry {
26 public:
27 // Allows for-each iterations over a slice of the categories array.
28 class Range {
29 public:
30 Range(TraceCategory* begin, TraceCategory* end) : begin_(begin), end_(end) {
31 DCHECK_LE(begin, end);
32 }
33 TraceCategory* begin() const { return begin_; }
34 TraceCategory* end() const { return end_; }
35
36 private:
37 TraceCategory* const begin_;
38 TraceCategory* const end_;
39 };
40
41 // Known categories.
42 static TraceCategory* const kCategoryExhausted;
43 static TraceCategory* const kCategoryMetadata;
44 static TraceCategory* const kCategoryAlreadyShutdown;
45
46 // Returns a category entry from the Category.state_ptr() pointer.
47 // TODO(primiano): trace macros should just keep a pointer to the entire
48 // TraceCategory, not just the enabled state pointer. That would remove the
49 // need for this function and make everything cleaner at no extra cost (as
50 // long as the |state_| is the first field of the struct, which can be
51 // guaranteed via static_assert, see TraceCategory ctor).
52 static const TraceCategory* GetCategoryByStatePtr(
53 const uint8_t* category_state);
54
55 static bool IsBuiltinCategory(const TraceCategory*);
56
57 private:
58 friend class TraceCategoryTest;
59 friend class TraceLog;
60
61 // Only for debugging/testing purposes, is a no-op on release builds.
62 static void Initialize();
63
64 // Resets the state of all categories, to clear up the state between tests.
65 static void ResetForTesting();
66
67 // The output |category| argument is an undefinitely lived pointer to the
68 // TraceCategory owned by the registry. TRACE_EVENTx macros will cache this
69 // pointer and use it for checks in their fast-paths.
70 // Returns false if the category was already present, true if the category
71 // has just been added and hence requires initialization.
72 static bool GetOrCreateCategoryByName(const char* category_name,
73 TraceCategory** category);
74
75 // Allows to iterate over the valid categories in a for-each loop.
76 // This includes builtin categories such as __metadata.
77 static Range GetAllCategories();
78 };
79
80 } // namespace trace_event
81 } // namespace base
82
83 #endif // BASE_TRACE_EVENT_CATEGORY_H_
OLDNEW
« no previous file with comments | « base/BUILD.gn ('k') | base/trace_event/category_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698