2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
7 // debug.cpp: Debugging utilities.
9 #include "common/debug.h"
10 #include "common/platform.h"
11 #include "common/angleutils.h"
20 #if defined(ANGLE_ENABLE_PERF)
21 typedef void (WINAPI *PerfOutputFunction)(D3DCOLOR, LPCWSTR);
23 typedef void (*PerfOutputFunction)(unsigned int, const wchar_t*);
26 static void output(bool traceFileDebugOnly, PerfOutputFunction perfFunc, const char *format, va_list vararg)
28 #if defined(ANGLE_ENABLE_PERF) || defined(ANGLE_ENABLE_TRACE)
29 std::string formattedMessage = FormatString(format, vararg);
32 #if defined(ANGLE_ENABLE_PERF)
35 // The perf function only accepts wide strings, widen the ascii message
36 static std::wstring wideMessage;
37 if (wideMessage.capacity() < formattedMessage.length())
39 wideMessage.reserve(formattedMessage.size());
42 wideMessage.assign(formattedMessage.begin(), formattedMessage.end());
44 perfFunc(0, wideMessage.c_str());
46 #endif // ANGLE_ENABLE_PERF
48 #if defined(ANGLE_ENABLE_TRACE)
50 if (traceFileDebugOnly)
56 static std::ofstream file(TRACE_OUTPUT_FILE, std::ofstream::app);
59 file.write(formattedMessage.c_str(), formattedMessage.length());
63 #endif // ANGLE_ENABLE_TRACE
66 void trace(bool traceFileDebugOnly, const char *format, ...)
69 va_start(vararg, format);
70 #if defined(ANGLE_ENABLE_PERF)
71 output(traceFileDebugOnly, D3DPERF_SetMarker, format, vararg);
73 output(traceFileDebugOnly, NULL, format, vararg);
80 #if defined(ANGLE_ENABLE_PERF)
81 static bool active = D3DPERF_GetStatus() != 0;
88 ScopedPerfEventHelper::ScopedPerfEventHelper(const char* format, ...)
90 #if defined(ANGLE_ENABLE_PERF)
91 #if !defined(ANGLE_ENABLE_TRACE)
96 #endif // !ANGLE_ENABLE_TRACE
98 va_start(vararg, format);
99 output(true, reinterpret_cast<PerfOutputFunction>(D3DPERF_BeginEvent), format, vararg);
101 #endif // ANGLE_ENABLE_PERF
104 ScopedPerfEventHelper::~ScopedPerfEventHelper()
106 #if defined(ANGLE_ENABLE_PERF)