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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_TRACING_ETW_SYSTEM_EVENT_CONSUMER_WIN_H_
6 #define CONTENT_BROWSER_TRACING_ETW_SYSTEM_EVENT_CONSUMER_WIN_H_
9 #include "base/memory/ref_counted_memory.h"
10 #include "base/threading/thread.h"
11 #include "base/values.h"
12 #include "base/win/event_trace_consumer.h"
13 #include "base/win/event_trace_controller.h"
16 template <typename Type
>
17 struct DefaultSingletonTraits
;
22 class EtwSystemEventConsumer
:
23 public base::win::EtwTraceConsumerBase
<EtwSystemEventConsumer
> {
25 typedef base::Callback
<void(const scoped_refptr
<base::RefCountedString
>&)>
28 bool StartSystemTracing();
29 void StopSystemTracing(const OutputCallback
& callback
);
31 // Retrieve the ETW consumer instance.
32 static EtwSystemEventConsumer
* GetInstance();
35 // This allows constructor and destructor to be private and usable only
36 // by the Singleton class.
37 friend struct base::DefaultSingletonTraits
<EtwSystemEventConsumer
>;
40 EtwSystemEventConsumer();
41 virtual ~EtwSystemEventConsumer();
43 void AddSyncEventToBuffer();
44 void AppendEventToBuffer(EVENT_TRACE
* event
);
46 // Static override of EtwTraceConsumerBase::ProcessEvent.
47 // @param event the raw ETW event to process.
48 friend class base::win::EtwTraceConsumerBase
<EtwSystemEventConsumer
>;
49 static void ProcessEvent(EVENT_TRACE
* event
);
51 // Request the ETW trace controller to activate the kernel tracing.
52 // returns true on success, false if the kernel tracing isn't activated.
53 bool StartKernelSessionTracing();
55 // Request the ETW trace controller to deactivate the kernel tracing.
56 // @param callback the callback to call with the consumed events.
57 // @returns true on success, false if an error occurred.
58 bool StopKernelSessionTracing();
60 void OnStopSystemTracingDone(
61 const OutputCallback
& callback
,
62 const scoped_refptr
<base::RefCountedString
>& result
);
64 void TraceAndConsumeOnThread();
65 void FlushOnThread(const OutputCallback
& callback
);
67 scoped_ptr
<base::ListValue
> events_
;
69 TRACEHANDLE session_handle_
;
70 base::win::EtwTraceProperties properties_
;
72 DISALLOW_COPY_AND_ASSIGN(EtwSystemEventConsumer
);
75 } // namespace content
77 #endif // CONTENT_BROWSER_TRACING_ETW_SYSTEM_EVENT_CONSUMER_WIN_H_