OLD | NEW |
| (Empty) |
1 // Copyright 2010 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 // | |
16 // A log writer that is controlled, and outputs to Event Tracing for Windows. | |
17 | |
18 #ifndef OMAHA_BASE_ETW_LOG_WRITER_H_ | |
19 #define OMAHA_BASE_ETW_LOG_WRITER_H_ | |
20 | |
21 #include "omaha/base/event_trace_provider.h" | |
22 #include "omaha/base/logging.h" | |
23 | |
24 namespace omaha { | |
25 | |
26 class EtwLogWriter : public LogWriter, public EtwTraceProvider { | |
27 public: | |
28 // The Omaha trace provider's GUID. | |
29 static const GUID kOmahaTraceGuid; | |
30 | |
31 // The event ID for the event types below. | |
32 static const GUID kLogEventId; | |
33 | |
34 // The event type for a simple UTF-8 zero-terminated message event. | |
35 static const EtwEventType kLogMessageType = 10; | |
36 | |
37 // The event type for a log message with a stack trace, followed by the | |
38 // zero-terminated UTF-8 message text. | |
39 static const EtwEventType kLogMessageWithStackTraceType = 11; | |
40 | |
41 // The lowest-order enable flags bit turn on stack trace capture. | |
42 // The remaining enable bits correspond to log categories, starting | |
43 // from LC_LOGGING through LC_MAX_CAT - 1. | |
44 static const EtwEventFlags kCaptureStackTraceMask = 0x0001; | |
45 | |
46 // LogWriter overrides. | |
47 virtual bool WantsToLogRegardless() const; | |
48 virtual bool IsCatLevelEnabled(LogCategory category, LogLevel level) const; | |
49 virtual void OutputMessage(const OutputInfo* output_info); | |
50 | |
51 // Factory for new instances. | |
52 static EtwLogWriter* Create(); | |
53 | |
54 // Convert a log category to the corresponding ETW enable flag. | |
55 static EtwEventFlags CategoryToEnableFlag(LogCategory category); | |
56 | |
57 // Convert from a log level to the corresponding ETW trace level. | |
58 static EtwEventLevel LogLevelToTraceLevel(LogLevel level); | |
59 | |
60 protected: | |
61 explicit EtwLogWriter(const GUID& provider_guid); | |
62 virtual void Cleanup(); | |
63 | |
64 // Override from EtwTraceProvider. | |
65 virtual void OnEventsEnabled(); | |
66 virtual void OnEventsDisabled(); | |
67 | |
68 private: | |
69 // The CaptureStackBackTrace function is only available as of Windows XP, | |
70 // and is only declared in SDK headers as of the Vista SDK. To uncomplicate | |
71 // things we get at the function through GetProcAddress. | |
72 typedef WORD (NTAPI* RtlCaptureStackBackTraceFunc)(DWORD frames_to_skip, | |
73 DWORD frames_to_capture, | |
74 PVOID* backtrace, | |
75 PDWORD backtrace_hash); | |
76 | |
77 RtlCaptureStackBackTraceFunc rtl_capture_stack_backtrace_; | |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(EtwLogWriter); | |
80 }; | |
81 | |
82 } // namespace omaha | |
83 | |
84 #endif // OMAHA_BASE_ETW_LOG_WRITER_H_ | |
OLD | NEW |