Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| 13 namespace base { | |
| 14 namespace trace_event { | |
| 15 | |
| 16 class TraceCategory; | |
| 17 class TraceLog; | |
| 18 | |
| 19 // Keeps track of the state of all tracing categories. The reason why this | |
| 20 // is a fully static class with global state is to allow to statically define | |
| 21 // known categories as global linker-initialized structs, without requiring | |
| 22 // static initializers. | |
| 23 class BASE_EXPORT CategoryRegistry { | |
| 24 public: | |
| 25 // Allows for-each iterations over a slice of the categories array. | |
| 26 class Range { | |
| 27 public: | |
| 28 Range(TraceCategory* begin, TraceCategory* end) | |
| 29 : begin_(begin), end_(end) {} | |
|
oystein (OOO til 10th of July)
2016/10/28 06:28:00
Can we DCHECK(begin_ <= end_)?
Primiano Tucci (use gerrit)
2016/10/28 15:28:39
Done.
| |
| 30 TraceCategory* begin() const { return begin_; } | |
| 31 TraceCategory* end() const { return end_; } | |
| 32 | |
| 33 private: | |
| 34 TraceCategory* const begin_; | |
| 35 TraceCategory* const end_; | |
| 36 }; | |
| 37 | |
| 38 // Known categories. | |
| 39 static TraceCategory* const kCategoryExhausted; | |
| 40 static TraceCategory* const kCategoryMetadata; | |
| 41 static TraceCategory* const kCategoryAlreadyShutdown; | |
| 42 | |
| 43 // Returns a category entry from the Category.state_ptr() pointer. | |
| 44 // TODO(primiano): trace macros should just keep a pointer to the entire | |
| 45 // TraceCategory, not just the enabled state pointer. That would remove the | |
| 46 // need for this function and make everything cleaner at no extra cost (as | |
| 47 // long as the |state_| is the first field of the struct, which can be | |
| 48 // guaranteed via static_assert, see TraceCategory ctor). | |
| 49 static const TraceCategory* GetCategoryByStatePtr( | |
| 50 const uint8_t* category_state); | |
| 51 | |
| 52 static bool IsBuiltinCategory(const TraceCategory*); | |
| 53 | |
| 54 private: | |
| 55 friend class TraceLog; | |
| 56 | |
| 57 // Only for debugging/testing purposes, is a no-op on release builds. | |
| 58 static void Initialize(); | |
| 59 | |
| 60 // Resets the state of all categories, to clear up the state between tests. | |
| 61 static void ResetForTesting(); | |
| 62 | |
| 63 // The output |category| argument is an undefinitely lived pointer to the | |
| 64 // TraceCategory owned by the registry. TRACE_EVENTx macros will cache this | |
| 65 // pointer and use it for checks in their fast-paths. | |
| 66 // Returns false if the category was already present, true if the category | |
| 67 // has just been added and hence requires initialization. | |
| 68 static bool GetOrCreateCategoryByName(const char* category_name, | |
| 69 TraceCategory** category); | |
| 70 | |
| 71 // Allows to iterate over the valid categories in a for-each loop. | |
| 72 // This includes builtin categories such as __metadata. | |
| 73 static Range GetAllCategories(); | |
| 74 }; | |
| 75 | |
| 76 } // namespace trace_event | |
| 77 } // namespace base | |
| 78 | |
| 79 #endif // BASE_TRACE_EVENT_CATEGORY_H_ | |
| OLD | NEW |