creport: optimize ScopedFile performance

This commit is contained in:
Michael Scire
2024-09-23 02:41:57 -07:00
parent 027e209073
commit 009f581721
4 changed files with 56 additions and 11 deletions

View File

@@ -26,6 +26,8 @@ namespace ams::creport {
static_assert(DyingMessageAddressOffset == AMS_OFFSETOF(ams::svc::aarch64::ProcessLocalRegion, dying_message_region_address));
static_assert(DyingMessageAddressOffset == AMS_OFFSETOF(ams::svc::aarch32::ProcessLocalRegion, dying_message_region_address));
constexpr size_t CrashReportDataCacheSize = 256_KB;
/* Helper functions. */
bool TryGetCurrentTimestamp(u64 *out) {
/* Clear output. */
@@ -307,7 +309,15 @@ namespace ams::creport {
/* Save crash report. */
util::SNPrintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/%011lu_%016lx.log", timestamp, m_process_info.program_id);
{
ScopedFile file(file_path);
/* Try to allocate data cache. */
void * const data_cache = lmem::AllocateFromExpHeap(m_heap_handle, CrashReportDataCacheSize + os::MemoryPageSize);
ON_SCOPE_EXIT { if (data_cache != nullptr) { lmem::FreeToExpHeap(m_heap_handle, data_cache); } };
/* Align up the data cache. This is safe because null will align up to null. */
void * const aligned_cache = reinterpret_cast<void *>(util::AlignUp(reinterpret_cast<uintptr_t>(data_cache), os::MemoryPageSize));
/* Open and save the file using the cache. */
ScopedFile file(file_path, aligned_cache, aligned_cache != nullptr ? CrashReportDataCacheSize : 0);
if (file.IsOpen()) {
this->SaveToFile(file);
}