Initial external logging API

New API to accept a file stream for logging

Co-authored-by: David Yat Sin <David.YatSin@amd.com>

Change-Id: Ie09c35ae14ca86a97eb25f61251be287c55d7169
Signed-off-by: Chris Freehill <cfreehil@amd.com>
Cette révision appartient à :
Saleel Kudchadker
2024-07-22 17:27:41 +00:00
révisé par David Yat Sin
Parent 64af2d71ef
révision 26e105d9ab
16 fichiers modifiés avec 209 ajouts et 56 suppressions
+18 -1
Voir le fichier
@@ -3,7 +3,7 @@
// The University of Illinois/NCSA
// Open Source License (NCSA)
//
// Copyright (c) 2021-2021, Advanced Micro Devices, Inc. All rights reserved.
// Copyright (c) 2021-2024, Advanced Micro Devices, Inc. All rights reserved.
//
// Developed by:
//
@@ -42,6 +42,7 @@
#include "core/util/flag.h"
#include "core/util/utils.h"
#include "core/util/os.h"
#include <vector>
#include <map>
@@ -50,6 +51,22 @@
#include <locale>
namespace rocr {
FILE* log_file = stderr;
uint8_t log_flags[8];
void log_printf(const char* file, int line, const char* format, ...) {
va_list ap;
std::stringstream str_thrd_id;
str_thrd_id << std::hex << std::this_thread::get_id();
va_start(ap, format);
char message[4096];
vsnprintf(message, sizeof(message), format, ap);
va_end(ap);
fprintf(log_file, ":%-25s:%-4d: %010lld us: [pid:%-5d tid:0x%s] [***rocr***] %s\n",
file, line, os::ReadAccurateClock()/1000ULL, os::GetProcessId(),
str_thrd_id.str().c_str(), message);
fflush(log_file);
}
// split at separators
static std::vector<std::string> split(std::string& str, char sep) {