OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file contains the Windows-specific exporting to ETW. | 5 // This file contains the Windows-specific exporting to ETW. |
6 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_ETW_EXPORT_WIN_H_ | 6 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_ETW_EXPORT_WIN_H_ |
7 #define BASE_TRACE_EVENT_TRACE_EVENT_ETW_EXPORT_WIN_H_ | 7 #define BASE_TRACE_EVENT_TRACE_EVENT_ETW_EXPORT_WIN_H_ |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
13 #include "base/trace_event/trace_event_impl.h" | 13 #include "base/trace_event/trace_event_impl.h" |
14 | 14 |
15 // Fwd. | 15 // Fwd. |
16 template <typename Type> | 16 template <typename Type> |
17 struct StaticMemorySingletonTraits; | 17 struct StaticMemorySingletonTraits; |
18 | 18 |
| 19 namespace { |
| 20 class ETWKeywordUpdateThread; |
| 21 } |
| 22 |
19 namespace base { | 23 namespace base { |
20 namespace trace_event { | 24 namespace trace_event { |
21 | 25 |
22 class BASE_EXPORT TraceEventETWExport { | 26 class BASE_EXPORT TraceEventETWExport { |
23 public: | 27 public: |
24 ~TraceEventETWExport(); | 28 ~TraceEventETWExport(); |
25 | 29 |
26 // Retrieves the singleton. | 30 // Retrieves the singleton. |
27 // Note that this may return NULL post-AtExit processing. | 31 // Note that this may return NULL post-AtExit processing. |
28 static TraceEventETWExport* GetInstance(); | 32 static TraceEventETWExport* GetInstance(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 const char* arg_value_2, | 64 const char* arg_value_2, |
61 const char* arg_name_3, | 65 const char* arg_name_3, |
62 const char* arg_value_3); | 66 const char* arg_value_3); |
63 | 67 |
64 // Returns true if any category in the group is enabled. | 68 // Returns true if any category in the group is enabled. |
65 static bool IsCategoryGroupEnabled(const char* category_group_name); | 69 static bool IsCategoryGroupEnabled(const char* category_group_name); |
66 | 70 |
67 private: | 71 private: |
68 // Ensure only the provider can construct us. | 72 // Ensure only the provider can construct us. |
69 friend struct StaticMemorySingletonTraits<TraceEventETWExport>; | 73 friend struct StaticMemorySingletonTraits<TraceEventETWExport>; |
| 74 // To have access to UpdateKeyword(). |
| 75 friend class ETWKeywordUpdateThread; |
70 TraceEventETWExport(); | 76 TraceEventETWExport(); |
71 | 77 |
72 // Updates the list of enabled categories by consulting the ETW keyword. | 78 // Updates the list of enabled categories by consulting the ETW keyword. |
73 // Returns true if there was a change, false otherwise. | 79 // Returns true if there was a change, false otherwise. |
74 bool UpdateEnabledCategories(); | 80 bool UpdateEnabledCategories(); |
75 | 81 |
76 // Returns true if the category is enabled. | 82 // Returns true if the category is enabled. |
77 bool IsCategoryEnabled(const char* category_name) const; | 83 bool IsCategoryEnabled(const char* category_name) const; |
78 | 84 |
| 85 // Called back by the update thread to check for potential changes to the |
| 86 // keyword. |
| 87 static void UpdateETWKeyword(); |
| 88 |
79 // True if ETW is enabled. Allows hiding the exporting behind a flag. | 89 // True if ETW is enabled. Allows hiding the exporting behind a flag. |
80 bool etw_export_enabled_; | 90 bool etw_export_enabled_; |
81 | 91 |
82 // Maps category names to their status (enabled/disabled). | 92 // Maps category names to their status (enabled/disabled). |
83 std::map<base::StringPiece, bool> categories_status_; | 93 std::map<base::StringPiece, bool> categories_status_; |
84 | 94 |
85 // Local copy of the ETW keyword. | 95 // Local copy of the ETW keyword. |
86 uint64 etw_match_any_keyword_; | 96 uint64 etw_match_any_keyword_; |
87 | 97 |
| 98 // Background thread that monitors changes to the ETW keyword and updates |
| 99 // the enabled categories when a change occurs. |
| 100 scoped_ptr<ETWKeywordUpdateThread> keyword_update_thread_; |
| 101 PlatformThreadHandle keyword_update_thread_handle_; |
| 102 |
88 DISALLOW_COPY_AND_ASSIGN(TraceEventETWExport); | 103 DISALLOW_COPY_AND_ASSIGN(TraceEventETWExport); |
89 }; | 104 }; |
90 | 105 |
91 } // namespace trace_event | 106 } // namespace trace_event |
92 } // namespace base | 107 } // namespace base |
93 | 108 |
94 #endif // BASE_TRACE_EVENT_TRACE_EVENT_ETW_EXPORT_WIN_H_ | 109 #endif // BASE_TRACE_EVENT_TRACE_EVENT_ETW_EXPORT_WIN_H_ |
OLD | NEW |