Hash :
b60fe31f
Author :
Date :
2014-09-26T14:56:41
Fix the ANGLE_ENABLE_TRACE build. We needed to include angleutils.cpp in libtranslator for this to compile. Also allow the event helpers to record API calls even if ANGLE_ENABLE_PERF is off. BUG=angle:513 Change-Id: I2646d5ebeae536a4a7f1cd7ecaf0ce019ce5ff76 Reviewed-on: https://chromium-review.googlesource.com/219756 Tested-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Shannon Woods <shannonwoods@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// debug.cpp: Debugging utilities.
#include "common/debug.h"
#include "common/platform.h"
#include "common/angleutils.h"
#include <stdarg.h>
#include <vector>
#include <fstream>
#include <cstdio>
namespace gl
{
#if defined(ANGLE_ENABLE_PERF)
typedef void (WINAPI *PerfOutputFunction)(D3DCOLOR, LPCWSTR);
#else
typedef void (*PerfOutputFunction)(unsigned int, const wchar_t*);
#endif
static void output(bool traceFileDebugOnly, PerfOutputFunction perfFunc, const char *format, va_list vararg)
{
#if defined(ANGLE_ENABLE_PERF) || defined(ANGLE_ENABLE_TRACE)
std::string formattedMessage = FormatString(format, vararg);
#endif
#if defined(ANGLE_ENABLE_PERF)
if (perfActive())
{
// The perf function only accepts wide strings, widen the ascii message
static std::wstring wideMessage;
if (wideMessage.capacity() < formattedMessage.length())
{
wideMessage.reserve(formattedMessage.size());
}
wideMessage.assign(formattedMessage.begin(), formattedMessage.end());
perfFunc(0, wideMessage.c_str());
}
#endif // ANGLE_ENABLE_PERF
#if defined(ANGLE_ENABLE_TRACE)
#if defined(NDEBUG)
if (traceFileDebugOnly)
{
return;
}
#endif // NDEBUG
static std::ofstream file(TRACE_OUTPUT_FILE, std::ofstream::app);
if (file)
{
file.write(formattedMessage.c_str(), formattedMessage.length());
file.flush();
}
#endif // ANGLE_ENABLE_TRACE
}
void trace(bool traceFileDebugOnly, const char *format, ...)
{
va_list vararg;
va_start(vararg, format);
#if defined(ANGLE_ENABLE_PERF)
output(traceFileDebugOnly, D3DPERF_SetMarker, format, vararg);
#else
output(traceFileDebugOnly, NULL, format, vararg);
#endif
va_end(vararg);
}
bool perfActive()
{
#if defined(ANGLE_ENABLE_PERF)
static bool active = D3DPERF_GetStatus() != 0;
return active;
#else
return false;
#endif
}
ScopedPerfEventHelper::ScopedPerfEventHelper(const char* format, ...)
{
#if !defined(ANGLE_ENABLE_TRACE)
if (!perfActive())
{
return;
}
#endif // !ANGLE_ENABLE_TRACE
va_list vararg;
va_start(vararg, format);
#if defined(ANGLE_ENABLE_PERF)
output(true, reinterpret_cast<PerfOutputFunction>(D3DPERF_BeginEvent), format, vararg);
#else
output(true, NULL, format, vararg);
#endif // ANGLE_ENABLE_PERF
va_end(vararg);
}
ScopedPerfEventHelper::~ScopedPerfEventHelper()
{
#if defined(ANGLE_ENABLE_PERF)
if (perfActive())
{
D3DPERF_EndEvent();
}
#endif
}
}