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
3 // found in the LICENSE file.
5 // This file contains the Windows-specific exporting to ETW.
6 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_ETW_EXPORT_WIN_H_
7 #define BASE_TRACE_EVENT_TRACE_EVENT_ETW_EXPORT_WIN_H_
11 #include "base/base_export.h"
12 #include "base/strings/string_piece.h"
13 #include "base/trace_event/trace_event_impl.h"
16 template <typename Type
>
17 struct StaticMemorySingletonTraits
;
20 namespace trace_event
{
22 class BASE_EXPORT TraceEventETWExport
{
24 ~TraceEventETWExport();
26 // Retrieves the singleton.
27 // Note that this may return NULL post-AtExit processing.
28 static TraceEventETWExport
* GetInstance();
30 // Enables/disables exporting of events to ETW. If disabled,
31 // AddEvent and AddCustomEvent will simply return when called.
32 static void EnableETWExport();
33 static void DisableETWExport();
35 // Returns true if ETW is enabled. For now, this is true if the command line
37 static bool IsETWExportEnabled();
39 // Exports an event to ETW. This is mainly used in
40 // TraceLog::AddTraceEventWithThreadIdAndTimestamp to export internal events.
43 const unsigned char* category_group_enabled
,
45 unsigned long long id
,
47 const char** arg_names
,
48 const unsigned char* arg_types
,
49 const unsigned long long* arg_values
,
50 const scoped_refptr
<ConvertableToTraceFormat
>* convertable_values
);
52 // 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 // TODO(georgesak): Allow different providers.
55 static void AddCustomEvent(const char* name
,
57 const char* arg_name_1
,
58 const char* arg_value_1
,
59 const char* arg_name_2
,
60 const char* arg_value_2
,
61 const char* arg_name_3
,
62 const char* arg_value_3
);
64 // Returns true if any category in the group is enabled.
65 static bool IsCategoryGroupEnabled(const char* category_group_name
);
68 // Ensure only the provider can construct us.
69 friend struct StaticMemorySingletonTraits
<TraceEventETWExport
>;
70 // To have access to UpdateKeyword().
71 class ETWKeywordUpdateThread
;
72 TraceEventETWExport();
74 // Updates the list of enabled categories by consulting the ETW keyword.
75 // Returns true if there was a change, false otherwise.
76 bool UpdateEnabledCategories();
78 // Returns true if the category is enabled.
79 bool IsCategoryEnabled(const char* category_name
) const;
81 // Called back by the update thread to check for potential changes to the
83 static void UpdateETWKeyword();
85 // True if ETW is enabled. Allows hiding the exporting behind a flag.
86 bool etw_export_enabled_
;
88 // Maps category names to their status (enabled/disabled).
89 std::map
<base::StringPiece
, bool> categories_status_
;
91 // Local copy of the ETW keyword.
92 uint64 etw_match_any_keyword_
;
94 // Background thread that monitors changes to the ETW keyword and updates
95 // the enabled categories when a change occurs.
96 scoped_ptr
<ETWKeywordUpdateThread
> keyword_update_thread_
;
97 PlatformThreadHandle keyword_update_thread_handle_
;
99 DISALLOW_COPY_AND_ASSIGN(TraceEventETWExport
);
102 } // namespace trace_event
105 #endif // BASE_TRACE_EVENT_TRACE_EVENT_ETW_EXPORT_WIN_H_