2020-02-04 09:26:14 -08:00
|
|
|
/* Copyright (c) 2008-present Advanced Micro Devices, Inc.
|
|
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE. */
|
2014-07-04 16:17:05 -04:00
|
|
|
|
|
|
|
|
#include "top.hpp"
|
|
|
|
|
#include "utils/debug.hpp"
|
|
|
|
|
#include "os/os.hpp"
|
|
|
|
|
|
2020-05-18 18:01:21 -04:00
|
|
|
#if !defined(AMD_LOG_LEVEL)
|
2017-04-13 13:56:38 -04:00
|
|
|
#include "utils/flags.hpp"
|
2014-07-04 16:17:05 -04:00
|
|
|
#endif
|
|
|
|
|
|
2020-06-11 05:33:40 -04:00
|
|
|
#include <mutex>
|
2014-07-04 16:17:05 -04:00
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstdarg>
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
#include <windows.h>
|
2017-04-13 13:56:38 -04:00
|
|
|
#endif // _WIN32
|
2014-07-04 16:17:05 -04:00
|
|
|
|
|
|
|
|
namespace amd {
|
|
|
|
|
|
|
|
|
|
//! \cond ignore
|
2017-04-13 13:56:38 -04:00
|
|
|
extern "C" void breakpoint(void) {
|
2014-07-04 16:17:05 -04:00
|
|
|
#ifdef _MSC_VER
|
2017-04-13 13:56:38 -04:00
|
|
|
DebugBreak();
|
|
|
|
|
#endif // _MSC_VER
|
2014-07-04 16:17:05 -04:00
|
|
|
}
|
|
|
|
|
//! \endcond
|
|
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
void report_fatal(const char* file, int line, const char* message) {
|
|
|
|
|
// FIXME_lmoriche: Obfuscate the message string
|
|
|
|
|
fprintf(stderr, "%s:%d: %s\n", file, line, message);
|
|
|
|
|
::abort();
|
2014-07-04 16:17:05 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
void report_warning(const char* message) { fprintf(stderr, "Warning: %s\n", message); }
|
2014-07-04 16:17:05 -04:00
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
void log_entry(LogLevel level, const char* file, int line, const char* message) {
|
|
|
|
|
if (level == LOG_NONE) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr, ":%d:%s:%d: %s\n", level, file, line, message);
|
2014-07-04 16:17:05 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
void log_timestamped(LogLevel level, const char* file, int line, const char* message) {
|
|
|
|
|
static bool gotstart = false; // not thread-safe, but not scary if fails
|
|
|
|
|
static uint64_t start;
|
|
|
|
|
|
|
|
|
|
if (!gotstart) {
|
|
|
|
|
start = Os::timeNanos();
|
|
|
|
|
gotstart = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t time = Os::timeNanos() - start;
|
|
|
|
|
if (level == LOG_NONE) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-07-04 16:17:05 -04:00
|
|
|
#if 0
|
|
|
|
|
fprintf(stderr, ":%d:%s:%d: (%010lld) %s\n", level, file, line, time, message);
|
2017-04-13 13:56:38 -04:00
|
|
|
#else // if you prefer fixed-width fields
|
|
|
|
|
fprintf(stderr, ":% 2d:%15s:% 5d: (%010lld) %s\n", level, file, line, time / 100ULL,
|
|
|
|
|
message); // timestamp is 100ns units
|
2014-07-04 16:17:05 -04:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-11 05:33:40 -04:00
|
|
|
FILE* g_pLogFile = nullptr;
|
|
|
|
|
std::once_flag g_iLogFileInitialized;
|
|
|
|
|
|
|
|
|
|
void createLogFile() {
|
|
|
|
|
if (!flagIsDefault(AMD_LOG_FILE) && g_pLogFile == nullptr) {
|
|
|
|
|
g_pLogFile = fopen("rocclr-trace.log", "w");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
void log_printf(LogLevel level, const char* file, int line, const char* format, ...) {
|
|
|
|
|
va_list ap;
|
2014-07-04 16:17:05 -04:00
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
va_start(ap, format);
|
2019-11-08 13:54:34 -05:00
|
|
|
char message[4096];
|
|
|
|
|
vsnprintf(message, sizeof(message), format, ap);
|
2017-04-13 13:56:38 -04:00
|
|
|
va_end(ap);
|
2014-07-04 16:17:05 -04:00
|
|
|
|
2020-06-11 05:33:40 -04:00
|
|
|
if (!flagIsDefault(AMD_LOG_FILE)) {
|
|
|
|
|
std::call_once(amd::g_iLogFileInitialized, amd::createLogFile);
|
|
|
|
|
|
|
|
|
|
if (g_pLogFile) {
|
|
|
|
|
fprintf(g_pLogFile, ":%d:%-25s:%-4d: %010lld: %s\n", level, file, line, Os::timeNanos() / 100ULL, message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fprintf(stderr, ":%d:%-25s:%-4d: %010lld: %s\n", level, file, line, Os::timeNanos() / 100ULL, message);
|
|
|
|
|
}
|
2014-07-04 16:17:05 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-13 13:56:38 -04:00
|
|
|
} // namespace amd
|