Refactor tracing

This commit is contained in:
Thraix
2023-04-13 22:03:06 +02:00
parent d9e7fd7019
commit 0246e89039
31 changed files with 132 additions and 130 deletions
+12 -11
View File
@@ -4,6 +4,7 @@
#include "copium/util/VulkanException.h"
#include <iostream>
#include <iomanip>
#define CP_TERM_RED "\x1B[31m"
#define CP_TERM_GREEN "\x1B[32m"
@@ -11,16 +12,16 @@
#define CP_TERM_GRAY "\x1B[90m"
#define CP_TERM_CLEAR "\033[0m"
#define CP_DEBUG(format, ...) std::cout << CP_TERM_GRAY << "[DBG] " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_INFO(format, ...) std::cout << "[INF] " << Copium::String::Format(format, __VA_ARGS__) << std::endl
#define CP_WARN(format, ...) std::cout << CP_TERM_YELLOW << "[WRN] " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_ERR(format, ...) std::cout << CP_TERM_RED << "[ERR] " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_DEBUG(format, ...) std::cout << CP_TERM_GRAY << "[DBG] " << __func__ << " : " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_INFO(format, ...) std::cout << "[INF] " << __func__ << " : " << Copium::String::Format(format, __VA_ARGS__) << std::endl
#define CP_WARN(format, ...) std::cout << CP_TERM_YELLOW << "[WRN] " << __func__ << " : " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_ERR(format, ...) std::cout << CP_TERM_RED << "[ERR] " << __func__ << " : " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
// Continue traces, will not print the [XXX] tag before the log
#define CP_DEBUG_CONT(format, ...) std::cout << CP_TERM_GRAY << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_INFO_CONT(format, ...) std::cout << " " << Copium::String::Format(format, __VA_ARGS__) << std::endl
#define CP_WARN_CONT(format, ...) std::cout << CP_TERM_YELLOW << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_ERR_CONT(format, ...) std::cout << CP_TERM_RED << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_DEBUG_CONT(format, ...) std::cout << CP_TERM_GRAY << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_INFO_CONT(format, ...) std::cout << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(format, __VA_ARGS__) << std::endl
#define CP_WARN_CONT(format, ...) std::cout << CP_TERM_YELLOW << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_ERR_CONT(format, ...) std::cout << CP_TERM_RED << " " << std::setfill(' ') << std::setw(sizeof(__func__)) << " " << Copium::String::Format(format, __VA_ARGS__) << CP_TERM_CLEAR << std::endl
#define CP_ABORT(format, ...) \
do \
@@ -35,7 +36,7 @@
if(!(Function)) \
{ \
CP_ERR("Assertion failed at %s:%d", __FILE__, __LINE__); \
CP_ERR_CONT(format, __VA_ARGS__); \
CP_ERR_CONT("%s : %s", #Function, Copium::String::Format(format, __VA_ARGS__).c_str()); \
throw Copium::RuntimeException(Copium::String::Format(format, __VA_ARGS__)); \
} \
} while(false)
@@ -45,7 +46,7 @@
if(Function != VK_SUCCESS) \
{ \
CP_ERR("Assertion failed at %s:%d", __FILE__, __LINE__); \
CP_ERR_CONT(format, __VA_ARGS__); \
CP_ERR_CONT("%s : %s", #Function, Copium::String::Format(format, __VA_ARGS__).c_str()); \
throw Copium::VulkanException(Copium::String::Format(format, __VA_ARGS__)); \
} \
} while(false)
@@ -71,7 +72,7 @@ namespace Copium
static std::string Format(const std::string& format, Args... args)
{
int size = std::snprintf(nullptr, 0, format.c_str(), args...) + 1;
CP_ASSERT(size > 0, "Format : Error during formatting");
CP_ASSERT(size > 0, "Error during formatting");
std::unique_ptr<char[]> buf(new char[size]);
std::snprintf(buf.get(), size, format.c_str(), args...);
return std::string(buf.get(), buf.get() + size - 1);
+7 -7
View File
@@ -5,7 +5,7 @@ namespace Copium
std::vector<char> FileSystem::ReadFile(const std::string& filename)
{
std::ifstream file(filename, std::ios::ate | std::ios::binary);
CP_ASSERT(file.is_open(), "ReadFile : Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file");
size_t fileSize = (size_t)file.tellg();
std::vector<char> buffer(fileSize);
@@ -19,10 +19,10 @@ namespace Copium
std::vector<uint32_t> FileSystem::ReadFile32(const std::string& filename)
{
std::ifstream file(filename, std::ios::ate | std::ios::binary);
CP_ASSERT(file.is_open(), "ReadFile32 : Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file");
size_t fileSize = (size_t)file.tellg();
CP_ASSERT(fileSize % 4 == 0, "ReadFile32 : byte size is not divisible by 4");
CP_ASSERT(fileSize % 4 == 0, "byte size is not divisible by 4");
std::vector<uint32_t> buffer(fileSize / 4);
file.seekg(0);
@@ -34,7 +34,7 @@ namespace Copium
std::string FileSystem::ReadFileStr(const std::string& filename)
{
std::ifstream file(filename, std::ios::ate | std::ios::binary);
CP_ASSERT(file.is_open(), "ReadFileStr : Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file");
size_t fileSize = (size_t)file.tellg();
std::string buffer;
@@ -51,7 +51,7 @@ namespace Copium
std::filesystem::path path{filename};
std::filesystem::create_directories(path.parent_path());
std::ofstream file(filename, std::ios::binary);
CP_ASSERT(file.is_open(), "WriteFile : Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file");
file.write(data.c_str(), data.size());
}
@@ -61,7 +61,7 @@ namespace Copium
std::filesystem::path path{filename};
std::filesystem::create_directories(path.parent_path());
std::ofstream file(filename, std::ios::binary);
CP_ASSERT(file.is_open(), "WriteFile : Failed to open file");
CP_ASSERT(file.is_open(), "Failed to open file");
file.write(data, size);
}
@@ -75,7 +75,7 @@ namespace Copium
int64_t FileSystem::DateModified(const std::string& filename)
{
struct stat result;
CP_ASSERT(stat(filename.c_str(), &result) == 0, "DataModified : Cannot stat file %s", filename.c_str());
CP_ASSERT(stat(filename.c_str(), &result) == 0, "Cannot stat file %s", filename.c_str());
return (int64_t)result.st_mtime;
}
}
+9 -9
View File
@@ -23,7 +23,7 @@ namespace Copium
const std::string& MetaFileClass::GetValue(const std::string& key) const
{
auto it = values.find(key);
CP_ASSERT(it != values.end(), "GetValue : Value does not exist: %s", key.c_str());
CP_ASSERT(it != values.end(), "Value does not exist: %s", key.c_str());
return it->second;
}
@@ -52,7 +52,7 @@ namespace Copium
{
std::ifstream stream(filepath);
CP_ASSERT(stream.is_open(), "MetaFile : Could not find meta file: %s", filepath.c_str());
CP_ASSERT(stream.is_open(), "Could not find meta file: %s", filepath.c_str());
LoadMetaFile(stream);
}
@@ -69,14 +69,14 @@ namespace Copium
MetaFileClass& MetaFile::GetMetaClass(const std::string& className)
{
auto it = classes.find(className);
CP_ASSERT(it != classes.end(), "GetMetaClass : class does not exist: %s", className.c_str());
CP_ASSERT(it != classes.end(), "class does not exist: %s", className.c_str());
return it->second;
}
const MetaFileClass& MetaFile::GetMetaClass(const std::string& className) const
{
auto it = classes.find(className);
CP_ASSERT(it != classes.end(), "GetMetaClass : class does not exist: ", className.c_str());
CP_ASSERT(it != classes.end(), "class does not exist: ", className.c_str());
return it->second;
}
@@ -128,7 +128,7 @@ namespace Copium
currentClass = StringUtil::Trim(line);
currentClass = currentClass.substr(1, currentClass.size() - 2);
metaClassIt = classes.find(currentClass);
CP_ASSERT(metaClassIt == classes.end(), "LoadMetaFile : Meta file contains two of the same class: %s", currentClass.c_str());
CP_ASSERT(metaClassIt == classes.end(), "Meta file contains two of the same class: %s", currentClass.c_str());
metaClassIt = classes.emplace(currentClass, MetaFileClass{}).first;
continue;
}
@@ -136,7 +136,7 @@ namespace Copium
size_t pos = line.find("=");
if(pos == std::string::npos)
{
CP_WARN("LoadMetaFile : Meta file line does not contain \'=\'");
CP_WARN("Meta file line does not contain \'=\'");
continue;
}
@@ -144,15 +144,15 @@ namespace Copium
std::string_view value = StringUtil::Trim(std::string_view(line.c_str() + pos + 1));
if(key.length() == 0)
{
CP_WARN("LoadMetaFile : MetaFile key is empty");
CP_WARN("MetaFile key is empty");
continue;
}
CP_ASSERT(metaClassIt != classes.end(), "LoadMetaFile : No meta file header specified: ", filepath.c_str());
CP_ASSERT(metaClassIt != classes.end(), "No meta file header specified: ", filepath.c_str());
auto res = metaClassIt->second.values.emplace(key, value);
if(!res.second)
{
CP_WARN("LoadMetaFile : Meta file key is defined twice: %s", std::string(key).c_str());
CP_WARN("Meta file key is defined twice: %s", std::string(key).c_str());
}
}
}
+3 -3
View File
@@ -20,7 +20,7 @@ namespace Copium
UUID::UUID(const std::string& uuidString)
: msb{0}, lsb{0}
{
CP_ASSERT(uuidString.size() == 36, "UUID : Invalid UUID string size: %s", uuidString.c_str());
CP_ASSERT(uuidString.size() == 36, "Invalid UUID string size: %s", uuidString.c_str());
for (int i = 0; i < 18; i++)
{
if (i == 8 || i == 13) // skip "-"
@@ -81,13 +81,13 @@ namespace Copium
{
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
CP_ABORT("HexToDec : Invalid char value: %c (%d)", c, (int)c);
CP_ABORT("Invalid char value: %c (%d)", c, (int)c);
}
char UUID::DecToHex(uint8_t nibble) const
{
if (nibble >= 0 && nibble <= 9) return '0' + nibble;
if (nibble >= 10 && nibble <= 15) return 'a' + nibble - 10;
CP_ABORT("DecToHex : Invalid nibble value: %d", (int)nibble);
CP_ABORT("Invalid nibble value: %d", (int)nibble);
}
}