summaryrefslogtreecommitdiffstats
path: root/base/trace_event_win.cc
diff options
context:
space:
mode:
authorsiggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 20:25:49 +0000
committersiggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 20:25:49 +0000
commit3e56955fa25579255bb139dd1c33804c4a7fee14 (patch)
tree4696e27fe553913b5eba1c84b844c7729ab9b0e4 /base/trace_event_win.cc
parent57f41723adadcd22c72674d413fee54a581ad6cc (diff)
downloadchromium_src-3e56955fa25579255bb139dd1c33804c4a7fee14.zip
chromium_src-3e56955fa25579255bb139dd1c33804c4a7fee14.tar.gz
chromium_src-3e56955fa25579255bb139dd1c33804c4a7fee14.tar.bz2
Divert TRACE_EVENT macros to use Event Tracing for Windows on Windows builds.
This is in preparation for instrumenting Chrome and Chrome Frame for performance measurements with ETW. BUG=none TEST=Unittests in this CL. Review URL: http://codereview.chromium.org/2020002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46734 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/trace_event_win.cc')
-rw-r--r--base/trace_event_win.cc114
1 files changed, 114 insertions, 0 deletions
diff --git a/base/trace_event_win.cc b/base/trace_event_win.cc
new file mode 100644
index 0000000..eae6782
--- /dev/null
+++ b/base/trace_event_win.cc
@@ -0,0 +1,114 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+#include "base/trace_event_win.h"
+
+#include "base/atomicops.h"
+#include "base/logging_win.h"
+#include "base/singleton.h"
+#include <initguid.h> // NOLINT
+
+namespace base {
+
+// {3DADA31D-19EF-4dc1-B345-037927193422}
+const GUID kChromeTraceProviderName = {
+ 0x3dada31d, 0x19ef, 0x4dc1, 0xb3, 0x45, 0x3, 0x79, 0x27, 0x19, 0x34, 0x22 };
+
+// {B967AE67-BB22-49d7-9406-55D91EE1D560}
+const GUID kTraceEventClass32 = {
+ 0xb967ae67, 0xbb22, 0x49d7, 0x94, 0x6, 0x55, 0xd9, 0x1e, 0xe1, 0xd5, 0x60 };
+
+// {97BE602D-2930-4ac3-8046-B6763B631DFE}
+const GUID kTraceEventClass64 = {
+ 0x97be602d, 0x2930, 0x4ac3, 0x80, 0x46, 0xb6, 0x76, 0x3b, 0x63, 0x1d, 0xfe};
+
+
+TraceLog::TraceLog() : EtwTraceProvider(base::kChromeTraceProviderName) {
+ Register();
+}
+
+TraceLog* TraceLog::Get() {
+ return Singleton<TraceLog, StaticMemorySingletonTraits<TraceLog>>::get();
+}
+
+bool TraceLog::StartTracing() {
+ return true;
+}
+
+void TraceLog::TraceEvent(const char* name,
+ size_t name_len,
+ base::TraceLog::EventType type,
+ const void* id,
+ const char* extra,
+ size_t extra_len) {
+ // Make sure we don't touch NULL.
+ if (name == NULL)
+ name = "";
+ if (extra == NULL)
+ extra = "";
+
+ EtwEventType etw_type = 0;
+ switch (type) {
+ case base::TraceLog::EVENT_BEGIN:
+ etw_type = base::kTraceEventTypeBegin;
+ break;
+ case base::TraceLog::EVENT_END:
+ etw_type = base::kTraceEventTypeEnd;
+ break;
+
+ case base::TraceLog::EVENT_INSTANT:
+ etw_type = base::kTraceEventTypeInstant;
+ break;
+
+ default:
+ NOTREACHED() << "Unknown event type";
+ etw_type = base::kTraceEventTypeInstant;
+ break;
+ }
+
+ EtwMofEvent<5> event(base::kTraceEventClass32,
+ etw_type,
+ TRACE_LEVEL_INFORMATION);
+ event.SetField(0, name_len + 1, name);
+ event.SetField(1, sizeof(id), &id);
+ event.SetField(2, extra_len + 1, extra);
+
+ // See whether we're to capture a backtrace.
+ void* backtrace[32];
+ if (enable_flags() & base::CAPTURE_STACK_TRACE) {
+ DWORD hash = 0;
+ DWORD depth = CaptureStackBackTrace(0,
+ arraysize(backtrace),
+ backtrace,
+ &hash);
+ event.SetField(3, sizeof(depth), &depth);
+ event.SetField(4, sizeof(backtrace[0]) * depth, backtrace);
+ }
+
+ // Trace the event.
+ Log(event.get());
+}
+
+void TraceLog::Trace(const char* name,
+ size_t name_len,
+ EventType type,
+ const void* id,
+ const char* extra,
+ size_t extra_len) {
+ TraceLog* provider = TraceLog::Get();
+ if (provider && provider->IsTracing()) {
+ // Compute the name & extra lengths if not supplied already.
+ if (name_len == -1)
+ name_len = (name == NULL) ? 0 : strlen(name);
+ if (extra_len == -1)
+ extra_len = (extra == NULL) ? 0 : strlen(extra);
+
+ provider->TraceEvent(name, name_len, type, id, extra, extra_len);
+ }
+}
+
+void TraceLog::Resurrect() {
+ StaticMemorySingletonTraits<TraceLog>::Resurrect();
+}
+
+} // namespace base