Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / base / trace_event / trace_event_etw_export_win.h
blob9f73d781f73585c3d42c6da1a9abe733c59f83cb
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_
9 #include <map>
11 #include "base/base_export.h"
12 #include "base/strings/string_piece.h"
13 #include "base/trace_event/trace_event_impl.h"
15 // Fwd.
16 template <typename Type>
17 struct StaticMemorySingletonTraits;
19 namespace base {
20 namespace trace_event {
22 class BASE_EXPORT TraceEventETWExport {
23 public:
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
36 // flag is specified.
37 static bool IsETWExportEnabled();
39 // Exports an event to ETW. This is mainly used in
40 // TraceLog::AddTraceEventWithThreadIdAndTimestamp to export internal events.
41 static void AddEvent(
42 char phase,
43 const unsigned char* category_group_enabled,
44 const char* name,
45 unsigned long long id,
46 int num_args,
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,
56 const char* phase,
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);
67 private:
68 // Ensure only the provider can construct us.
69 friend struct StaticMemorySingletonTraits<TraceEventETWExport>;
70 TraceEventETWExport();
72 // Updates the list of enabled categories by consulting the ETW keyword.
73 // Returns true if there was a change, false otherwise.
74 bool UpdateEnabledCategories();
76 // Returns true if the category is enabled.
77 bool IsCategoryEnabled(const char* category_name) const;
79 // True if ETW is enabled. Allows hiding the exporting behind a flag.
80 bool etw_export_enabled_;
82 // Maps category names to their status (enabled/disabled).
83 std::map<base::StringPiece, bool> categories_status_;
85 // Local copy of the ETW keyword.
86 uint64 etw_match_any_keyword_;
88 DISALLOW_COPY_AND_ASSIGN(TraceEventETWExport);
91 } // namespace trace_event
92 } // namespace base
94 #endif // BASE_TRACE_EVENT_TRACE_EVENT_ETW_EXPORT_WIN_H_