From ac467734a014a94ced1d7e2255904be885d13e3e Mon Sep 17 00:00:00 2001 From: Reece Date: Fri, 21 Jan 2022 16:26:35 +0000 Subject: [PATCH] [*] Preparing to work on extending the console api and telemetry subsystems --- .../Aurora/Console/{README.md => README.txt} | 0 Include/Aurora/Telemetry/BlackBox.hpp | 6 +- .../Telemetry/ITelemetryStreamConsumer.hpp | 0 .../Telemetry/ITelemetryStreamProvider.hpp | 0 Source/Console/Logging/Logger.cpp | 0 Source/Console/Logging/Logger.hpp | 0 Source/Console/Logging/Sinks.cpp | 0 Source/Console/Logging/Sinks.hpp | 0 Source/Debug/Debug.cpp | 93 ++++++++++++------- Source/Debug/Debug.hpp | 2 +- Source/Debug/ExceptionWatcher.Win32.cpp | 2 +- Source/Processes/Open.Unix.cpp | 1 + Source/Telemetry/Telemetry.cpp | 19 +++- Source/Telemetry/Telemetry.hpp | 3 + Source/Threading/Threads/OSThread.cpp | 9 +- 15 files changed, 99 insertions(+), 36 deletions(-) rename Include/Aurora/Console/{README.md => README.txt} (100%) create mode 100644 Include/Aurora/Telemetry/ITelemetryStreamConsumer.hpp create mode 100644 Include/Aurora/Telemetry/ITelemetryStreamProvider.hpp create mode 100644 Source/Console/Logging/Logger.cpp create mode 100644 Source/Console/Logging/Logger.hpp create mode 100644 Source/Console/Logging/Sinks.cpp create mode 100644 Source/Console/Logging/Sinks.hpp diff --git a/Include/Aurora/Console/README.md b/Include/Aurora/Console/README.txt similarity index 100% rename from Include/Aurora/Console/README.md rename to Include/Aurora/Console/README.txt diff --git a/Include/Aurora/Telemetry/BlackBox.hpp b/Include/Aurora/Telemetry/BlackBox.hpp index c6b7dfba..0931bc54 100644 --- a/Include/Aurora/Telemetry/BlackBox.hpp +++ b/Include/Aurora/Telemetry/BlackBox.hpp @@ -38,6 +38,7 @@ namespace Aurora::Telemetry struct NewBlockBoxEntryStackReport { Debug::StackTrace backtrace; + AuUInt32 fenceId; }; struct NewBlackboxEntryUpdateMapEntry @@ -73,6 +74,7 @@ namespace Aurora::Telemetry { NewBlockBoxEntryStackReport stack; AuString str; + AuUInt32 fenceId; }; struct NewBlockboxEntryBasicMessage @@ -124,7 +126,9 @@ namespace Aurora::Telemetry Aurora::HWInfo::CpuInfo cpuInfo; Aurora::HWInfo::RamStat sysMem; - Aurora::HWInfo::RamStat procMem; + Aurora::HWInfo::RamStat ramMem; + Aurora::HWInfo::RamStat procCommitMem; + Aurora::HWInfo::RamStat procLowerMem; }; struct NewBlackBoxEntryReportApplication diff --git a/Include/Aurora/Telemetry/ITelemetryStreamConsumer.hpp b/Include/Aurora/Telemetry/ITelemetryStreamConsumer.hpp new file mode 100644 index 00000000..e69de29b diff --git a/Include/Aurora/Telemetry/ITelemetryStreamProvider.hpp b/Include/Aurora/Telemetry/ITelemetryStreamProvider.hpp new file mode 100644 index 00000000..e69de29b diff --git a/Source/Console/Logging/Logger.cpp b/Source/Console/Logging/Logger.cpp new file mode 100644 index 00000000..e69de29b diff --git a/Source/Console/Logging/Logger.hpp b/Source/Console/Logging/Logger.hpp new file mode 100644 index 00000000..e69de29b diff --git a/Source/Console/Logging/Sinks.cpp b/Source/Console/Logging/Sinks.cpp new file mode 100644 index 00000000..e69de29b diff --git a/Source/Console/Logging/Sinks.hpp b/Source/Console/Logging/Sinks.hpp new file mode 100644 index 00000000..e69de29b diff --git a/Source/Debug/Debug.cpp b/Source/Debug/Debug.cpp index 4f197318..67e07c4b 100644 --- a/Source/Debug/Debug.cpp +++ b/Source/Debug/Debug.cpp @@ -15,6 +15,8 @@ namespace Aurora::Debug { + static thread_local AuUInt32 tlsLastBackTrace = 0xFFFFFFFF; + static StackTrace gLastStackTrace; static AuUInt32 gStackTraceFence; static AuUInt32 gFenceId; @@ -170,18 +172,19 @@ namespace Aurora::Debug return tempError; } - void ReportStackTrace(const StackTrace& trace, const AuString& message) + AuUInt32 ReportStackTrace(const StackTrace& trace, const AuString& message) { AU_LOCK_GUARD(gLock); gLastStackTrace = trace; gLastExceptionMessage = message; - gStackTraceFence++; + tlsLastBackTrace = gStackTraceFence++; gFenceId++; + return tlsLastBackTrace; } AuUInt32 GetFenceId() { - return gFenceId; + return gFenceId++; } AUKN_SYM AuString GetLastErrorStack() @@ -210,36 +213,54 @@ namespace Aurora::Debug { AuUInt32 rng = GetFenceId(); - Telemetry::InsertManualFence(rng); - - static AuUInt32 cLastFence = 0; - auto cFence = GetCErrorFence(); - auto cError = TryGetOrFetchCError(); - if ((cError) && (cFence != cLastFence)) + Telemetry::BeginBlock(); + try { - LogWarn("Language Error: {} ({})", strerror(*cError), *cError); - cLastFence = cFence; - } - - static AuUInt32 osLastFence = 0; - auto osFence = GetOSErrorFence(); - auto osError = TryGetOrFetchOSError(); - if ((osError) && (osFence != osLastFence)) - { - LogWarn("Operating System Error: {} (0x{:x})", osError->second, osError->first); - osLastFence = osFence; - } + Telemetry::InsertManualFence(rng); - Telemetry::InsertManualFence(rng); + static AuUInt32 cLastFence = 0; + auto cFence = GetCErrorFence(); + auto cError = TryGetOrFetchCError(); + if ((cError) && (cFence != cLastFence)) + { + LogWarn("Language Error: {} ({})", strerror(*cError), *cError); + cLastFence = cFence; + } + + static AuUInt32 osLastFence = 0; + auto osFence = GetOSErrorFence(); + auto osError = TryGetOrFetchOSError(); + if ((osError) && (osFence != osLastFence)) + { + LogWarn("Operating System Error: {} (0x{:x})", osError->second, osError->first); + osLastFence = osFence; + } + + Telemetry::InsertBackTrace(tlsLastBackTrace); + Telemetry::InsertManualFence(rng); + } + catch (...) + { + } + Telemetry::EndBlock(); } void CheckErrors() { AuUInt32 rng = GetFenceId(); - Telemetry::InsertManualFence(rng); - TryGetOrFetchCError(); - TryGetOrFetchOSError(); - Telemetry::InsertManualFence(rng); + Telemetry::BeginBlock(); + try + { + Telemetry::InsertManualFence(rng); + TryGetOrFetchCError(); + TryGetOrFetchOSError(); + Telemetry::InsertBackTrace(tlsLastBackTrace); + Telemetry::InsertManualFence(rng); + } + catch (...) + { + } + Telemetry::EndBlock(); } AUKN_SYM void _PushError(AuUInt address, EFailureCategory category, const char *msg) @@ -253,11 +274,21 @@ namespace Aurora::Debug // Cry about it to telemetry with other errors if available AuUInt32 rng = GetFenceId(); - Telemetry::InsertManualFence(rng); - Telemetry::InsertMsgError(error); - TryGetOrFetchCError(); - TryGetOrFetchOSError(); - Telemetry::InsertManualFence(rng); + Telemetry::BeginBlock(); + try + { + Telemetry::InsertManualFence(rng); + Telemetry::InsertMsgError(error); + TryGetOrFetchCError(); + TryGetOrFetchOSError(); + Telemetry::InsertBackTrace(tlsLastBackTrace); + Telemetry::InsertManualFence(rng); + } + catch (...) + { + + } + Telemetry::EndBlock(); // Is anyone listening? // Print to console if internal diff --git a/Source/Debug/Debug.hpp b/Source/Debug/Debug.hpp index 6792a22a..c6d6639f 100644 --- a/Source/Debug/Debug.hpp +++ b/Source/Debug/Debug.hpp @@ -24,7 +24,7 @@ namespace Aurora::Debug AuOptional TryGetOrFetchCError(); - void ReportStackTrace(const StackTrace &trace, const AuString &message); + AuUInt32 ReportStackTrace(const StackTrace &trace, const AuString &message); AuOptional TryFetchOSError(); diff --git a/Source/Debug/ExceptionWatcher.Win32.cpp b/Source/Debug/ExceptionWatcher.Win32.cpp index 9a0705f5..4172acf0 100644 --- a/Source/Debug/ExceptionWatcher.Win32.cpp +++ b/Source/Debug/ExceptionWatcher.Win32.cpp @@ -326,7 +326,7 @@ namespace Aurora::Debug } - ReportStackTrace(entry.wincxx.stack.backtrace, entry.wincxx.str); + entry.wincxx.fenceId = ReportStackTrace(entry.wincxx.stack.backtrace, entry.wincxx.str); #if defined(STAGING) || defined(DEBUG) bool isInternal = true; diff --git a/Source/Processes/Open.Unix.cpp b/Source/Processes/Open.Unix.cpp index 97411fee..01512491 100644 --- a/Source/Processes/Open.Unix.cpp +++ b/Source/Processes/Open.Unix.cpp @@ -17,6 +17,7 @@ namespace Aurora::Processes { static void UnixOpenAsync(const AuString &open) { + // TODO: mac os is special if (fork() == 0) { setsid(); diff --git a/Source/Telemetry/Telemetry.cpp b/Source/Telemetry/Telemetry.cpp index 12a010dc..d1535efd 100644 --- a/Source/Telemetry/Telemetry.cpp +++ b/Source/Telemetry/Telemetry.cpp @@ -11,6 +11,18 @@ namespace Aurora::Telemetry { + static AuThreadPrimitives::CriticalSectionUnique_t gGroupLock; + + void BeginBlock() + { + gGroupLock->Lock(); + } + + void EndBlock() + { + gGroupLock->Unlock(); + } + void InsertOSError(const Debug::OSError_t &osError) { @@ -30,7 +42,12 @@ namespace Aurora::Telemetry { } - + + void InsertBackTrace(AuUInt32 fence) + { + + } + void Report(Telemetry::NewBlockboxEntry &entry) { diff --git a/Source/Telemetry/Telemetry.hpp b/Source/Telemetry/Telemetry.hpp index 10c10437..1efe5128 100644 --- a/Source/Telemetry/Telemetry.hpp +++ b/Source/Telemetry/Telemetry.hpp @@ -12,7 +12,10 @@ namespace Aurora::Telemetry void InsertOSError(const Debug::OSError_t &osError); void InsertMsgError(const Debug::LastError &error); void InsertCError(AuSInt cError); + void BeginBlock(); + void EndBlock(); void InsertManualFence(AuUInt32 fence); + void InsertBackTrace(AuUInt32 fence); void ReportSysInfo(); void Report(Telemetry::NewBlockboxEntry &entry); void Init(); diff --git a/Source/Threading/Threads/OSThread.cpp b/Source/Threading/Threads/OSThread.cpp index 3fdb1543..7b52f330 100644 --- a/Source/Threading/Threads/OSThread.cpp +++ b/Source/Threading/Threads/OSThread.cpp @@ -409,7 +409,14 @@ namespace Aurora::Threading::Threads this->tlsReferenceThread_ = osThread; OSAttach(); - task_(); + try + { + task_(); + } + catch (...) + { + SysPushErrorHAL("OS Thread Aborted"); + } Exit(true); }