[*] Prevent WriteLater from entering a deadlock condition. OnFlushs are no longer atomic

[*] Fix up gen1 copypasta
[+] ConsoleMessage::ToPersistentString
[*] Adjust ConsoleMessage formatting
This commit is contained in:
Reece Wilson 2022-01-27 20:25:04 +00:00
parent b1c4e26f91
commit d8e000b5c3
16 changed files with 165 additions and 84 deletions

View File

@ -48,8 +48,10 @@ namespace Aurora::Console
}
AUKN_SYM AuString StringifyTime(bool simple = false) const;
AUKN_SYM AuString StringifyTimeUTC() const;
AUKN_SYM AuString GetWrappedTag() const;
AUKN_SYM AuString ToConsole() const;
AUKN_SYM AuString ToPersistentString() const;
AUKN_SYM AuString ToSimplified() const;
};
}

View File

@ -29,6 +29,7 @@ namespace Aurora::HWInfo
inline CpuBitId Not() const;
inline CpuBitId And(const CpuBitId &id) const;
inline CpuBitId Xor(const CpuBitId &id) const;
inline CpuBitId Or(const CpuBitId &id) const;
inline bool CpuBitScanForward(AuUInt8 &index, AuUInt8 offset) const;

View File

@ -117,6 +117,18 @@ namespace Aurora::HWInfo
return ret;
}
CpuBitId CpuBitId::Or(const CpuBitId &id) const
{
CpuBitId ret = *this;
ret.lower |= id.lower;
ret.upper |= id.upper;
#if defined(_AU_MASSIVE_CPUID)
ret.upper2 |= id.upper2;
ret.upper3 |= id.upper3;
#endif
return ret;
}
CpuBitId &CpuBitId::operator=(const CpuBitId &id)
{
lower = id.lower;

View File

@ -437,12 +437,12 @@ namespace Aurora::IO::Net
AUE_DEFINE(ENetworkPoolModel, (
// Do not attach to a thread subsystem
eNoHooks,
/// given a group id, uses prespawned async application event queues
eAsyncApp,
///
eAsyncThreadPool,
/// it just werks
eInternalThreadPool,
@ -456,7 +456,7 @@ namespace Aurora::IO::Net
ENetworkPoolModel mode;
AuUInt8 asyncWorkGroup;
AuUInt8 asyncWorkGroup {};
AuUInt8 asyncWorkerIdOffset {};
AuSPtr<Async::IThreadPool> threadPool;

View File

@ -16,7 +16,7 @@ namespace Aurora::Console::ConsoleFIO
static const auto &gLogConfig = gRuntimeConfig.console.fio;
AuString GetLogDirectory()
static AuString GetLogDirectory(const AuString &type)
{
AuString path;
AuString procName;
@ -26,17 +26,31 @@ namespace Aurora::Console::ConsoleFIO
path = ".";
}
if (!Process::GetProcName(procName))
path += "/" + type + "/";
if (Process::GetProcName(procName))
{
procName = "Unknown";
path += procName;
path.push_back('/');
}
else
{
path += "Unknown/";
}
path += "/Logs/";
path += procName;
return path;
}
AuString GetLogDirectory()
{
return GetLogDirectory("Logs");
}
AuString GetTelemetryDirectory()
{
return GetLogDirectory("Telemetry");
}
static void EraseFilesByTimestamp(const AuString &path, /*const its not worth reallocation*/ AuList<AuString> &files)
{
if (files.size() <= gLogConfig.maxLogs)

View File

@ -14,5 +14,6 @@ namespace Aurora::Console::ConsoleFIO
void Exit();
void Flush();
AuString GetLogDirectory();
AuString GetTelemetryDirectory();
void FIOCleanup();
}

View File

@ -25,7 +25,7 @@ namespace Aurora::Console::ConsoleFIO
void FIOSink::OnMessageBlocking(AuUInt8 level, const ConsoleMessage &msg)
{
AU_LOCK_GUARD(logMutex_->AsWritable());
auto str = msg.ToSimplified();
auto str = msg.ToPersistentString();
logBuffer_.reserve(logBuffer_.size() + str.size() + 2);

View File

@ -28,13 +28,13 @@ namespace Aurora::Console
"\033[0m"
};
AuString ConsoleMessage::StringifyTime(bool simple) const
static AuString StringifyTimeEx(const ConsoleMessage &msg, bool simple, bool utc)
{
try
{
std::tm localized;
Aurora::Time::ToCivilTime(time, false).CopyTo(localized);
Aurora::Time::ToCivilTime(msg.time, utc).CopyTo(localized);
if (simple)
{
@ -51,6 +51,30 @@ namespace Aurora::Console
}
}
AuString ConsoleMessage::StringifyTime(bool simple) const
{
try
{
return StringifyTimeEx(*this, simple, false);
}
catch (...)
{
return {};
}
}
AuString ConsoleMessage::StringifyTimeUTC() const
{
try
{
return StringifyTimeEx(*this, false, true);
}
catch (...)
{
return {};
}
}
AuString ConsoleMessage::GetWrappedTag() const
{
return "[" + prefix + "]";
@ -60,11 +84,11 @@ namespace Aurora::Console
{
try
{
return fmt::format("{}[{}] {:<7} | {}{}",
return fmt::format("{}[{}] {:<8} | {}{}",
static_cast<EAnsiColor>(color) <= EAnsiColor::eCount ?
kAnsiCheats[static_cast<size_t>(color)] :
"",
StringifyTime(),
StringifyTime(true),
GetWrappedTag(),
line,
kAnsiCheats[static_cast<size_t>(EAnsiColor::eReset)]);
@ -75,12 +99,30 @@ namespace Aurora::Console
}
}
AuString ConsoleMessage::ToPersistentString() const
{
try
{
return fmt::format("[{}] {:<7} | {}",
StringifyTimeUTC(),
GetWrappedTag(),
line);
}
catch (...)
{
return {};
}
}
AuString ConsoleMessage::ToSimplified() const
{
try
{
return fmt::format("{:<9} {:<7} | {}", StringifyTime(true), GetWrappedTag(), line);
return fmt::format("{:<9} {:<8} | {}", StringifyTime(true), GetWrappedTag(), line);
}
catch (...)
{

View File

@ -121,22 +121,26 @@ namespace Aurora::Console::Logging
void ForceFlushLoggers()
{
AU_LOCK_GUARD(gGlobalSpin);
decltype(gLogTasks) logTasks;
try
{
AU_LOCK_GUARD(gGlobalSpin);
logTasks = AuExchange(gLogTasks, {});
}
catch (...)
{
try
{
}
logTasks = AuExchange(gLogTasks, {});
}
catch (...)
{
if (logTasks.empty())
{
return;
}
if (logTasks.empty())
{
return;
}
}
try
@ -156,17 +160,21 @@ namespace Aurora::Console::Logging
}
for (const auto &logger : gFlushableLoggers)
{
for (const auto &sink : logger->sinks)
AU_LOCK_GUARD(gGlobalSpin);
for (const auto &logger : gFlushableLoggers)
{
try
for (const auto &sink : logger->sinks)
{
sink->OnFlush();
}
catch (...)
{
SysPushErrorGeneric("...");
try
{
sink->OnFlush();
}
catch (...)
{
SysPushErrorGeneric("...");
}
}
}
}

View File

@ -80,7 +80,6 @@ namespace Aurora::Debug
return lastError = ret;
}
AuOptional<OSError_t> TryGetOrFetchOSError()
{
static AuOptional<OSError_t> lastErrorError;

View File

@ -16,20 +16,17 @@ namespace Aurora::Debug
AuString dbg;
};
AuUInt32 GetOSErrorFence();
AuOptional<OSError_t> TryGetOrFetchOSError();
AuUInt32 GetCErrorFence();
AuOptional<AuUInt32> TryGetOrFetchCError();
AuUInt32 ReportStackTrace(const StackTrace &trace, const AuString &message);
AuOptional<OSError_t> TryFetchOSError();
AuOptional<AuUInt32> TryFetchCError();
AuUInt32 ReportStackTrace(const StackTrace &trace, const AuString &message);
void CheckErrors();
void PlatformHandleFatal(bool fatal);
void InitDebug();

View File

@ -143,11 +143,6 @@ namespace Aurora::Debug
{
static bool handlingFatal = false;
if (std::exchange(handlingFatal, true))
{
std::terminate();
}
#if defined(DEBUG) || defined(INTERNAL)
if (!fatal)
{
@ -156,7 +151,7 @@ namespace Aurora::Debug
}
else
{
SaveMinidump(pExceptionInfo);
SaveMinidump(pExceptionInfo, true);
}
#else
BlackboxReport(pExceptionInfo, true);
@ -194,8 +189,15 @@ static thread_local AuUInt tlsThrowCounter;
extern "C" AUKN_SYM void __stdcall _ReportMSVCSEH(void *exception, const void *throwInfo, void *caller)
{
if (!throwInfo) return;
if (!exception) return;
if (!throwInfo)
{
return;
}
if (!exception)
{
return;
}
HMODULE handle = 0;

View File

@ -24,6 +24,8 @@
#include <Source/Process/ProcessMap.hpp>
#include <Source/IO/FS/FS.hpp>
#include <Source/Console/Flusher.hpp>
static thread_local int gDebugLocked = 0;
namespace Aurora::Debug
@ -112,7 +114,6 @@ namespace Aurora::Debug
return EXCEPTION_CONTINUE_SEARCH;
}
auto minimal = gDebugLocked++;
if (minimal >= 5)
@ -194,6 +195,8 @@ namespace Aurora::Debug
{
PlatformHandleFatal(true);
}
Console::ForceFlush();
}
catch (...)
{
@ -219,9 +222,9 @@ namespace Aurora::Debug
try
{
auto tm = Time::ToCivilTime(Time::CurrentClockMS());
return fmt::format("{}-{}-{}T{}-{}-{}Z_{}.dmp", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec,
exeName);
return fmt::format("{}-{}-{}T{}-{}-{}Z_{}.dmp", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec,
exeName);
}
catch (...)
{
@ -230,7 +233,7 @@ namespace Aurora::Debug
}
#if defined(DEBUG) || defined(INTERNAL)
void SaveMinidump(_EXCEPTION_POINTERS *ExceptionInfo)
void SaveMinidump(_EXCEPTION_POINTERS *ExceptionInfo, bool isFatal)
{
bool ok {};
MINIDUMP_EXCEPTION_INFORMATION info;
@ -288,9 +291,10 @@ namespace Aurora::Debug
{
}
__debugbreak();
__fastfail('fokd');
if (isFatal)
{
__fastfail('fokd');
}
}
#endif

View File

@ -12,7 +12,7 @@ namespace Aurora::Debug
void InitWin32();
#if defined(DEBUG) || defined(INTERNAL)
void SaveMinidump(_EXCEPTION_POINTERS *ExceptionInfo);
void SaveMinidump(_EXCEPTION_POINTERS *ExceptionInfo, bool isFatal);
#endif
void BlackboxReport(_EXCEPTION_POINTERS *ExceptionInfo, bool isFatal);
}

View File

@ -320,32 +320,32 @@ namespace Aurora::HWInfo
AuString CpuId::ToString() const
{
return fmt::format(
"FMA {}\t\tFSGSBASE {}\t\tCLFSH {}\t\tERMS {}{}"
"CMPXCHG16B {}\t\tAVX512PF {}\t\tMOVBE {}\t\tRTM {}{}"
"POPCNT {}\t\tAVX512ER {}\t\tMONITOR {}\t\tLAHF {}{}"
"SSE {}\t\tAVX512CD {}\t\tF16C {}\t\tABM {}{}"
"SSE2 {}\t\tSYSCALL {}\t\tRDRAND {}\t\tXOP {}{}"
"SSE3 {}\t\tAES {}\t\tMSR {}\t\tTBM {}{}"
"SSSE3 {}\t\tRDTSCP {}\t\tCX8 {}\t\tMMXEXT {}{}"
"SSE41 {}\t\tXSAVE {}\t\tSEP {}\t\tRDSEED {}{}"
"SSE42 {}\t\tOSXSAVE {}\t\tCMOV {}\t\tPREFETCHWT1 {}{}"
"SSE4a {}\t\tSHA {}\t\tFXSR {}\t\tPCLMULQDQ {}{}"
"AVX {}\t\tAVX512F {}\t\tBMI1 {}\t\tINVPCID {}{}"
"AVX2 {}\t\tLZCNT {}\t\tHLE {}\t\t_3DNOWEXT {}{}"
"MMX {}\t\tADX {}\t\tBMI2 {}\t\t_3DNOW {}",
FMA(), FSGSBASE(), CLFSH(), ERMS(), Aurora::Locale::NewLine(),
CMPXCHG16B(), AVX512PF(), MOVBE(), RTM(), Aurora::Locale::NewLine(),
POPCNT(), AVX512ER(), MONITOR(), LAHF(), Aurora::Locale::NewLine(),
SSE(), AVX512CD(), F16C(), ABM(), Aurora::Locale::NewLine(),
SSE2(), SYSCALL(), RDRAND(), XOP(), Aurora::Locale::NewLine(),
SSE3(), AES(), MSR(), TBM(), Aurora::Locale::NewLine(),
SSSE3(), RDTSCP(), CX8(), MMXEXT(), Aurora::Locale::NewLine(),
SSE41(), XSAVE(), SEP(), RDSEED(), Aurora::Locale::NewLine(),
SSE42(), OSXSAVE(), CMOV(), PREFETCHWT1(), Aurora::Locale::NewLine(),
SSE4a(), SHA(), FXSR(), PCLMULQDQ(), Aurora::Locale::NewLine(),
AVX(), AVX512F(), BMI1(), INVPCID(), Aurora::Locale::NewLine(),
AVX2(), LZCNT(), HLE(), _3DNOWEXT(), Aurora::Locale::NewLine(),
MMX(), ADX(), BMI2(), _3DNOW()
"FMA {}\t\tFSGSBASE {}\t\tCLFSH {}\t\t\tERMS {}{}"
"CMPXCHG16B {}\t\tAVX512PF {}\t\tMOVBE {}\t\t\tRTM {}{}"
"POPCNT {}\t\tAVX512ER {}\t\tMONITOR {}\t\t\tLAHF {}{}"
"SSE {}\t\tAVX512CD {}\t\tF16C {}\t\t\tABM {}{}"
"SSE2 {}\t\tSYSCALL {}\t\tRDRAND {}\t\t\tXOP {}{}"
"SSE3 {}\t\tAES {}\t\tMSR {}\t\t\tTBM {}{}"
"SSSE3 {}\t\tRDTSCP {}\t\tCX8 {}\t\t\tMMXEXT {}{}"
"SSE41 {}\t\tXSAVE {}\t\tSEP {}\t\t\tRDSEED {}{}"
"SSE42 {}\t\tOSXSAVE {}\t\tCMOV {}\t\t\tPREFETCHWT1 {}{}"
"SSE4a {}\t\tSHA {}\t\tFXSR {}\t\t\tPCLMULQDQ {}{}"
"AVX {}\t\tAVX512F {}\t\tBMI1 {}\t\t\tINVPCID {}{}"
"AVX2 {}\t\tLZCNT {}\t\tHLE {}\t\t\t_3DNOWEXT {}{}"
"MMX {}\t\tADX {}\t\tBMI2 {}\t\t\t_3DNOW {}",
FMA(), FSGSBASE(), CLFSH(), ERMS(), Aurora::Locale::NewLine(),
CMPXCHG16B(), AVX512PF(), MOVBE(), RTM(), Aurora::Locale::NewLine(),
POPCNT(), AVX512ER(), MONITOR(), LAHF(), Aurora::Locale::NewLine(),
SSE(), AVX512CD(), F16C(), ABM(), Aurora::Locale::NewLine(),
SSE2(), SYSCALL(), RDRAND(), XOP(), Aurora::Locale::NewLine(),
SSE3(), AES(), MSR(), TBM(), Aurora::Locale::NewLine(),
SSSE3(), RDTSCP(), CX8(), MMXEXT(), Aurora::Locale::NewLine(),
SSE41(), XSAVE(), SEP(), RDSEED(), Aurora::Locale::NewLine(),
SSE42(), OSXSAVE(), CMOV(), PREFETCHWT1(), Aurora::Locale::NewLine(),
SSE4a(), SHA(), FXSR(), PCLMULQDQ(), Aurora::Locale::NewLine(),
AVX(), AVX512F(), BMI1(), INVPCID(), Aurora::Locale::NewLine(),
AVX2(), LZCNT(), HLE(), _3DNOWEXT(), Aurora::Locale::NewLine(),
MMX(), ADX(), BMI2(), _3DNOW()
);
}

View File

@ -129,7 +129,6 @@ namespace Aurora::HWInfo
gCpuInfo.cores = 0;
gCpuInfo.threads = 0;
bool sparse = false;
for (auto i = 0; i < length; i++)
{