OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CONTENT_BROWSER_TRACING_ETW_SYSTEM_EVENT_CONSUMER_WIN_H_ | 5 #ifndef CONTENT_BROWSER_TRACING_ETW_TRACING_AGENT_H_ |
6 #define CONTENT_BROWSER_TRACING_ETW_SYSTEM_EVENT_CONSUMER_WIN_H_ | 6 #define CONTENT_BROWSER_TRACING_ETW_TRACING_AGENT_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "base/trace_event/tracing_agent.h" | 14 #include "base/trace_event/tracing_agent.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "base/win/event_trace_consumer.h" | 16 #include "base/win/event_trace_consumer.h" |
17 #include "base/win/event_trace_controller.h" | 17 #include "base/win/event_trace_controller.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 template <typename Type> | 20 template <typename Type> |
21 struct DefaultSingletonTraits; | 21 struct DefaultSingletonTraits; |
22 } | 22 } |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 | 25 |
26 class EtwSystemEventConsumer | 26 class EtwTracingAgent |
27 : public base::win::EtwTraceConsumerBase<EtwSystemEventConsumer>, | 27 : public base::win::EtwTraceConsumerBase<EtwTracingAgent>, |
28 public base::trace_event::TracingAgent { | 28 public base::trace_event::TracingAgent { |
29 public: | 29 public: |
30 // base::trace_event::TracingAgent implementation. | 30 // base::trace_event::TracingAgent implementation. |
31 std::string GetTracingAgentName() override; | 31 std::string GetTracingAgentName() override; |
32 std::string GetTraceEventLabel() override; | 32 std::string GetTraceEventLabel() override; |
33 void StartAgentTracing(const base::trace_event::TraceConfig& trace_config, | 33 void StartAgentTracing(const base::trace_event::TraceConfig& trace_config, |
34 const StartAgentTracingCallback& callback) override; | 34 const StartAgentTracingCallback& callback) override; |
35 void StopAgentTracing(const StopAgentTracingCallback& callback) override; | 35 void StopAgentTracing(const StopAgentTracingCallback& callback) override; |
36 | 36 |
37 // Retrieve the ETW consumer instance. | 37 // Retrieve the ETW consumer instance. |
38 static EtwSystemEventConsumer* GetInstance(); | 38 static EtwTracingAgent* GetInstance(); |
39 | 39 |
40 private: | 40 private: |
41 // This allows constructor and destructor to be private and usable only | 41 // This allows constructor and destructor to be private and usable only |
42 // by the Singleton class. | 42 // by the Singleton class. |
43 friend struct base::DefaultSingletonTraits<EtwSystemEventConsumer>; | 43 friend struct base::DefaultSingletonTraits<EtwTracingAgent>; |
44 | 44 |
45 // Constructor. | 45 // Constructor. |
46 EtwSystemEventConsumer(); | 46 EtwTracingAgent(); |
47 ~EtwSystemEventConsumer() override; | 47 ~EtwTracingAgent() override; |
48 | 48 |
49 void AddSyncEventToBuffer(); | 49 void AddSyncEventToBuffer(); |
50 void AppendEventToBuffer(EVENT_TRACE* event); | 50 void AppendEventToBuffer(EVENT_TRACE* event); |
51 | 51 |
52 // Static override of EtwTraceConsumerBase::ProcessEvent. | 52 // Static override of EtwTraceConsumerBase::ProcessEvent. |
53 // @param event the raw ETW event to process. | 53 // @param event the raw ETW event to process. |
54 friend class base::win::EtwTraceConsumerBase<EtwSystemEventConsumer>; | 54 friend class base::win::EtwTraceConsumerBase<EtwTracingAgent>; |
55 static void ProcessEvent(EVENT_TRACE* event); | 55 static void ProcessEvent(EVENT_TRACE* event); |
56 | 56 |
57 // Request the ETW trace controller to activate the kernel tracing. | 57 // Request the ETW trace controller to activate the kernel tracing. |
58 // returns true on success, false if the kernel tracing isn't activated. | 58 // returns true on success, false if the kernel tracing isn't activated. |
59 bool StartKernelSessionTracing(); | 59 bool StartKernelSessionTracing(); |
60 | 60 |
61 // Request the ETW trace controller to deactivate the kernel tracing. | 61 // Request the ETW trace controller to deactivate the kernel tracing. |
62 // @param callback the callback to call with the consumed events. | 62 // @param callback the callback to call with the consumed events. |
63 // @returns true on success, false if an error occurred. | 63 // @returns true on success, false if an error occurred. |
64 bool StopKernelSessionTracing(); | 64 bool StopKernelSessionTracing(); |
65 | 65 |
66 void OnStopSystemTracingDone( | 66 void OnStopSystemTracingDone( |
67 const StopAgentTracingCallback& callback, | 67 const StopAgentTracingCallback& callback, |
68 const scoped_refptr<base::RefCountedString>& result); | 68 const scoped_refptr<base::RefCountedString>& result); |
69 | 69 |
70 void TraceAndConsumeOnThread(); | 70 void TraceAndConsumeOnThread(); |
71 void FlushOnThread(const StopAgentTracingCallback& callback); | 71 void FlushOnThread(const StopAgentTracingCallback& callback); |
72 | 72 |
73 std::unique_ptr<base::ListValue> events_; | 73 std::unique_ptr<base::ListValue> events_; |
74 base::Thread thread_; | 74 base::Thread thread_; |
75 TRACEHANDLE session_handle_; | 75 TRACEHANDLE session_handle_; |
76 base::win::EtwTraceProperties properties_; | 76 base::win::EtwTraceProperties properties_; |
77 | 77 |
78 DISALLOW_COPY_AND_ASSIGN(EtwSystemEventConsumer); | 78 DISALLOW_COPY_AND_ASSIGN(EtwTracingAgent); |
79 }; | 79 }; |
80 | 80 |
81 } // namespace content | 81 } // namespace content |
82 | 82 |
83 #endif // CONTENT_BROWSER_TRACING_ETW_SYSTEM_EVENT_CONSUMER_WIN_H_ | 83 #endif // CONTENT_BROWSER_TRACING_ETW_TRACING_AGENT_H_ |
OLD | NEW |