| 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/timer/timer.h" |
| 13 #include "base/trace_event/trace_event_impl.h" | 14 #include "base/trace_event/trace_event_impl.h" |
| 14 | 15 |
| 15 // Fwd. | 16 // Fwd. |
| 16 template <typename Type> | 17 template <typename Type> |
| 17 struct StaticMemorySingletonTraits; | 18 struct StaticMemorySingletonTraits; |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 namespace trace_event { | 21 namespace trace_event { |
| 21 | 22 |
| 22 class BASE_EXPORT TraceEventETWExport { | 23 class BASE_EXPORT TraceEventETWExport { |
| 23 public: | 24 public: |
| 24 ~TraceEventETWExport(); | 25 ~TraceEventETWExport(); |
| 25 | 26 |
| 26 // Retrieves the singleton. | 27 // Retrieves the singleton. |
| 27 // Note that this may return NULL post-AtExit processing. | 28 // Note that this may return NULL post-AtExit processing. |
| 28 static TraceEventETWExport* GetInstance(); | 29 static TraceEventETWExport* GetInstance(); |
| 29 | 30 |
| 30 // Enables/disables exporting of events to ETW. If disabled, | 31 // Enables/disables exporting of events to ETW. If disabled, |
| 31 // AddEvent and AddCustomEvent will simply return when called. | 32 // AddEvent and AddCustomEvent will simply return when called. |
| 32 static void EnableETWExport(); | 33 static void EnableETWExport(); |
| 33 static void DisableETWExport(); | 34 static void DisableETWExport(); |
| 34 | 35 |
| 35 static bool IsETWExportEnabled() { | 36 // Returns true if ETW is enabled. For now, this is true if the command line |
| 36 return (GetInstance() && GetInstance()->etw_match_any_keyword_); | 37 // flag is specified. |
| 37 } | 38 static bool IsETWExportEnabled(); |
| 38 | 39 |
| 39 // Exports an event to ETW. This is mainly used in | 40 // Exports an event to ETW. This is mainly used in |
| 40 // TraceLog::AddTraceEventWithThreadIdAndTimestamp to export internal events. | 41 // TraceLog::AddTraceEventWithThreadIdAndTimestamp to export internal events. |
| 41 static void AddEvent( | 42 static void AddEvent( |
| 42 char phase, | 43 char phase, |
| 43 const unsigned char* category_group_enabled, | 44 const unsigned char* category_group_enabled, |
| 44 const char* name, | 45 const char* name, |
| 45 unsigned long long id, | 46 unsigned long long id, |
| 46 int num_args, | 47 int num_args, |
| 47 const char** arg_names, | 48 const char** arg_names, |
| 48 const unsigned char* arg_types, | 49 const unsigned char* arg_types, |
| 49 const unsigned long long* arg_values, | 50 const unsigned long long* arg_values, |
| 50 const scoped_refptr<ConvertableToTraceFormat>* convertable_values); | 51 const scoped_refptr<ConvertableToTraceFormat>* convertable_values); |
| 51 | 52 |
| 52 // Exports an event to ETW. This should be used when exporting an event only | 53 // Exports an event to ETW. This should be used when exporting an event only |
| 53 // to ETW. Supports three arguments to be passed to ETW. | 54 // to ETW. Supports three arguments to be passed to ETW. |
| 54 // TODO(georgesak): Allow different providers. | 55 // TODO(georgesak): Allow different providers. |
| 55 static void AddCustomEvent(const char* name, | 56 static void AddCustomEvent(const char* name, |
| 56 const char* phase, | 57 const char* phase, |
| 57 const char* arg_name_1, | 58 const char* arg_name_1, |
| 58 const char* arg_value_1, | 59 const char* arg_value_1, |
| 59 const char* arg_name_2, | 60 const char* arg_name_2, |
| 60 const char* arg_value_2, | 61 const char* arg_value_2, |
| 61 const char* arg_name_3, | 62 const char* arg_name_3, |
| 62 const char* arg_value_3); | 63 const char* arg_value_3); |
| 63 | 64 |
| 64 // Returns true if any category in the group is enabled. | 65 // Returns true if any category in the group is enabled. |
| 65 static bool IsCategoryGroupEnabled(const char* category_group_name); | 66 static bool IsCategoryGroupEnabled(const char* category_group_name); |
| 66 | 67 |
| 68 // Starts the timer that keeps polls the keyword for changes. |
| 69 static void StartKeywordUpdateTimer(); |
| 70 |
| 71 // Exposed for unittesting only, allows resurrecting our |
| 72 // singleton instance post-AtExit processing |
| 67 void Resurrect(); | 73 void Resurrect(); |
| 68 | 74 |
| 69 private: | 75 private: |
| 70 // Ensure only the provider can construct us. | 76 // Ensure only the provider can construct us. |
| 71 friend struct StaticMemorySingletonTraits<TraceEventETWExport>; | 77 friend struct StaticMemorySingletonTraits<TraceEventETWExport>; |
| 72 TraceEventETWExport(); | 78 TraceEventETWExport(); |
| 73 | 79 |
| 74 // Updates the list of enabled categories by consulting the ETW keyword. | 80 // Updates the list of enabled categories by consulting the ETW keyword. |
| 75 void UpdateEnabledCategories(); | 81 // Returns true if there was a change, false if unchanged. |
| 82 bool UpdateEnabledCategories(); |
| 76 | 83 |
| 77 // Returns true if the category is enabled. | 84 // Returns true if the category is enabled. |
| 78 bool IsCategoryEnabled(const char* category_name) const; | 85 bool IsCategoryEnabled(const char* category_name) const; |
| 79 | 86 |
| 87 // Called back by the timer to check for potential changes to the keyword. |
| 88 static void KeywordUpdateTimerCallback(); |
| 89 |
| 80 // True if ETW is enabled. Allows hiding the exporting behind a flag. | 90 // True if ETW is enabled. Allows hiding the exporting behind a flag. |
| 81 bool etw_export_enabled_; | 91 bool etw_export_enabled_; |
| 82 | 92 |
| 83 // Maps category names to their status (enabled/disabled). | 93 // Maps category names to their status (enabled/disabled). |
| 84 std::map<base::StringPiece, bool> categories_status_; | 94 std::map<base::StringPiece, bool> categories_status_; |
| 85 | 95 |
| 86 // Local copy of the ETW keyword. | 96 // Local copy of the ETW keyword. |
| 87 uint64 etw_match_any_keyword_; | 97 uint64 etw_match_any_keyword_; |
| 88 | 98 |
| 99 // Repeating timer that is responsible for polling the keyword for changes. |
| 100 base::RepeatingTimer<TraceEventETWExport> keyword_update_timer_; |
| 101 |
| 89 DISALLOW_COPY_AND_ASSIGN(TraceEventETWExport); | 102 DISALLOW_COPY_AND_ASSIGN(TraceEventETWExport); |
| 90 }; | 103 }; |
| 91 | 104 |
| 92 } // namespace trace_event | 105 } // namespace trace_event |
| 93 } // namespace base | 106 } // namespace base |
| 94 | 107 |
| 95 #endif // BASE_TRACE_EVENT_TRACE_EVENT_ETW_EXPORT_WIN_H_ | 108 #endif // BASE_TRACE_EVENT_TRACE_EVENT_ETW_EXPORT_WIN_H_ |
| OLD | NEW |