logging improvements
This commit is contained in:
@@ -17,6 +17,7 @@ namespace
|
|||||||
{
|
{
|
||||||
char LineBuffer[LogInternal::MaxLineSize]{0};
|
char LineBuffer[LogInternal::MaxLineSize]{0};
|
||||||
char OutBuffer[LogInternal::MaxLineSize]{0};
|
char OutBuffer[LogInternal::MaxLineSize]{0};
|
||||||
|
char OutBufferUI[LogInternal::MaxLineSize]{0};
|
||||||
bx::HandleHashMapT<1024> OnceMap;
|
bx::HandleHashMapT<1024> OnceMap;
|
||||||
LogHistory History;
|
LogHistory History;
|
||||||
|
|
||||||
@@ -36,11 +37,13 @@ void Log(ELogType logType, const char* file, uint32_t line, const char* format,
|
|||||||
bx::snprintf(LineBuffer, sizeof(LineBuffer), LineFormat, format);
|
bx::snprintf(LineBuffer, sizeof(LineBuffer), LineFormat, format);
|
||||||
bx::vprintf(LineBuffer, args);
|
bx::vprintf(LineBuffer, args);
|
||||||
bx::vsnprintf(OutBuffer, sizeof(OutBuffer), LineBuffer, args);
|
bx::vsnprintf(OutBuffer, sizeof(OutBuffer), LineBuffer, args);
|
||||||
|
bx::vsnprintf(OutBufferUI, sizeof(OutBufferUI), format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
OutputDebugStringA(OutBuffer);
|
OutputDebugStringA(OutBuffer);
|
||||||
|
|
||||||
bx::strCopy(&History.LogBuffer[History.WriteIdx * LogInternal::MaxLineSize], LogInternal::MaxLineSize, OutBuffer);
|
bx::strCopy(&History.LogBuffer[History.WriteIdx * LogInternal::MaxLineSize], LogInternal::MaxLineSize, OutBufferUI);
|
||||||
History.WriteTime[History.WriteIdx] = bx::getHPCounter();
|
History.WriteTime[History.WriteIdx] = bx::getHPCounter();
|
||||||
|
History.WriteType[History.WriteIdx] = logType;
|
||||||
bx::strCopy(&History.FileBuffer[History.WriteIdx * LogInternal::MaxLineSize], LogInternal::MaxLineSize, file);
|
bx::strCopy(&History.FileBuffer[History.WriteIdx * LogInternal::MaxLineSize], LogInternal::MaxLineSize, file);
|
||||||
History.LineBuffer[History.WriteIdx] = line;
|
History.LineBuffer[History.WriteIdx] = line;
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ struct LogHistory
|
|||||||
uint32_t LineBuffer[LogInternal::LogHistorySize]{0};
|
uint32_t LineBuffer[LogInternal::LogHistorySize]{0};
|
||||||
int32_t WriteIdx = 0;
|
int32_t WriteIdx = 0;
|
||||||
int64_t WriteTime[LogInternal::LogHistorySize]{0};
|
int64_t WriteTime[LogInternal::LogHistorySize]{0};
|
||||||
|
ELogType WriteType[LogInternal::LogHistorySize]{ELogType::Log};
|
||||||
};
|
};
|
||||||
|
|
||||||
void Log(ELogType logType, const char* file, uint32_t line, const char* format, ...);
|
void Log(ELogType logType, const char* file, uint32_t line, const char* format, ...);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "Gen.h"
|
#include "Gen.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Instance.h"
|
#include "Instance.h"
|
||||||
|
#include "Log.h"
|
||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
#include "Puzzle.h"
|
#include "Puzzle.h"
|
||||||
#include "Tools.h"
|
#include "Tools.h"
|
||||||
@@ -153,27 +154,45 @@ namespace Tools
|
|||||||
if (ImGui::Begin("Log"))
|
if (ImGui::Begin("Log"))
|
||||||
{
|
{
|
||||||
ImGui::Checkbox("Shorten File Names", &debug.ShortenLogFileNames);
|
ImGui::Checkbox("Shorten File Names", &debug.ShortenLogFileNames);
|
||||||
ImGui::BeginTable(
|
ImGui::BeginTable("tbl",
|
||||||
"tbl", 4, ImGuiTableFlags_Resizable | ImGuiTableFlags_Hideable | ImGuiTableFlags_SizingFixedFit);
|
4,
|
||||||
|
ImGuiTableFlags_Resizable | ImGuiTableFlags_Hideable |
|
||||||
|
ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg);
|
||||||
ImGui::TableSetupColumn("Time", ImGuiTableColumnFlags_NoResize);
|
ImGui::TableSetupColumn("Time", ImGuiTableColumnFlags_NoResize);
|
||||||
ImGui::TableSetupColumn("Log");
|
ImGui::TableSetupColumn("Log");
|
||||||
ImGui::TableSetupColumn("Line", ImGuiTableColumnFlags_NoResize);
|
ImGui::TableSetupColumn("Line", ImGuiTableColumnFlags_NoResize);
|
||||||
ImGui::TableSetupColumn("File", ImGuiTableColumnFlags_NoResize);
|
ImGui::TableSetupColumn("File", ImGuiTableColumnFlags_NoResize);
|
||||||
ImGui::TableHeadersRow();
|
ImGui::TableHeadersRow();
|
||||||
|
|
||||||
|
auto& logs = GetLogHistory();
|
||||||
for (int32_t i = 0; i < bx::min(100, LogInternal::LogHistorySize); ++i)
|
for (int32_t i = 0; i < bx::min(100, LogInternal::LogHistorySize); ++i)
|
||||||
{
|
{
|
||||||
int32_t idx = GetLogHistory().WriteIdx - i - 1;
|
int32_t idx = logs.WriteIdx - i - 1;
|
||||||
if (idx < 0) idx += LogInternal::LogHistorySize;
|
if (idx < 0) idx += LogInternal::LogHistorySize;
|
||||||
const char* line = &GetLogHistory().LogBuffer[idx * LogInternal::MaxLineSize];
|
const char* line = &logs.LogBuffer[idx * LogInternal::MaxLineSize];
|
||||||
if (line[0] != 0)
|
if (line[0] != 0)
|
||||||
{
|
{
|
||||||
int64_t timeOffset = GetLogHistory().WriteTime[idx] - time.StartTime;
|
int64_t timeOffset = logs.WriteTime[idx] - time.StartTime;
|
||||||
double writeTime = (double)timeOffset / bx::getHPFrequency();
|
double writeTime = (double)timeOffset / bx::getHPFrequency();
|
||||||
uint32_t fileLine = GetLogHistory().LineBuffer[idx];
|
uint32_t fileLine = logs.LineBuffer[idx];
|
||||||
const char* filePath = &GetLogHistory().FileBuffer[idx * LogInternal::MaxLineSize];
|
const char* filePath = &logs.FileBuffer[idx * LogInternal::MaxLineSize];
|
||||||
const char* filePathRes =
|
const char* filePathRes =
|
||||||
debug.ShortenLogFileNames ? bx::FilePath{filePath}.getFileName().getPtr() : filePath;
|
debug.ShortenLogFileNames ? bx::FilePath{filePath}.getFileName().getPtr() : filePath;
|
||||||
|
|
||||||
|
// ImVec4 texCol = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
|
// if (logs.WriteType[idx] == ELogType::Warn)
|
||||||
|
// texCol = {1.0f, 1.0f, 0.8f, 1.0f};
|
||||||
|
// else if (logs.WriteType[idx] == ELogType::Error)
|
||||||
|
// texCol = {1.0f, 0.8f, 0.8f, 1.0f};
|
||||||
|
// ImGui::PushStyleColor(ImGuiCol_Text, texCol);
|
||||||
|
ImVec4 bgCol = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
|
if (logs.WriteType[idx] == ELogType::Warn)
|
||||||
|
bgCol = {0.2f, 0.2f, 0.0f, 1.0f};
|
||||||
|
else if (logs.WriteType[idx] == ELogType::Error)
|
||||||
|
bgCol = {0.2f, 0.0f, 0.0f, 1.0f};
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_TableRowBg, bgCol);
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_TableRowBgAlt, bgCol);
|
||||||
|
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Text("%.01f", writeTime);
|
ImGui::Text("%.01f", writeTime);
|
||||||
@@ -187,6 +206,8 @@ namespace Tools
|
|||||||
|
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Text("%s", filePathRes);
|
ImGui::Text("%s", filePathRes);
|
||||||
|
|
||||||
|
ImGui::PopStyleColor(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
|
|||||||
Reference in New Issue
Block a user