mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-19 04:15:57 +00:00
Log the memory commit charge with every fatal error
#94 ended on a realloc of 1 MiB that failed with 64 GB of commit allowed, and the log could not tell whether the process had grown towards the limit or the system ran short. rt_fatal now adds one line with the process's private bytes and the system's commit in use and limit (plat_commit_info). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f958a5ef71
commit
31fff74776
3 files changed
+21
No files matched your search
@@ -12,6 +12,7 @@
|
||||
// is also fixed at init; they are looked up only after the flat table misses.
|
||||
#include "dispatch.h"
|
||||
#include "host.h"
|
||||
#include "platform/platform.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
@@ -51,6 +52,11 @@ void rt_fatal(const char *fmt, ...) {
|
||||
rt_vlogf(fmt, ap);
|
||||
rt_log_raw("\n", 1);
|
||||
va_end(ap);
|
||||
// A failed allocation (malloc, realloc, VirtualAlloc) means the commit limit was reached: this line tells a leak of
|
||||
// ours (process private bytes near the limit) from a machine short of page file.
|
||||
double proc, used, limit;
|
||||
plat_commit_info(&proc, &used, &limit);
|
||||
rt_log("fatal: memory commit: this process %.0f MB, the system %.0f of %.0f MB", proc, used, limit);
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
_Exit(70);
|
||||
|
||||
@@ -116,6 +116,9 @@ void plat_cpu_load(PlatLoad *l, float *total_pct, float *proc_pct, float *temp_c
|
||||
void plat_gpu_load(PlatLoad *l, float *load_pct, float *vram_used_mb);
|
||||
// Physical memory in MB: in use and installed on the machine, and this process's working set.
|
||||
void plat_mem_info(float *used_mb, float *total_mb, float *proc_mb);
|
||||
// Commit charge in MB: this process's private bytes, the system's commit in use and its limit (RAM plus page files).
|
||||
// An allocation fails when the system's reaches the limit, however much physical memory is free. -1 when unknown.
|
||||
void plat_commit_info(double *proc_mb, double *used_mb, double *limit_mb);
|
||||
|
||||
// ---- child processes: a program with stdin and stdout piped to us (stderr discarded), no console window.
|
||||
typedef struct PlatChild PlatChild;
|
||||
|
||||
@@ -613,6 +613,18 @@ void plat_mem_info(float *used_mb, float *total_mb, float *proc_mb) {
|
||||
if (K32GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof pmc)) *proc_mb = (float)(pmc.WorkingSetSize >> 20);
|
||||
}
|
||||
|
||||
void plat_commit_info(double *proc_mb, double *used_mb, double *limit_mb) {
|
||||
*proc_mb = *used_mb = *limit_mb = -1;
|
||||
MEMORYSTATUSEX ms = {.dwLength = sizeof ms};
|
||||
if (GlobalMemoryStatusEx(&ms)) {
|
||||
*limit_mb = (double)(ms.ullTotalPageFile >> 20);
|
||||
*used_mb = (double)((ms.ullTotalPageFile - ms.ullAvailPageFile) >> 20);
|
||||
}
|
||||
PROCESS_MEMORY_COUNTERS_EX pmc;
|
||||
if (K32GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS *)&pmc, sizeof pmc))
|
||||
*proc_mb = (double)(pmc.PrivateUsage >> 20);
|
||||
}
|
||||
|
||||
// ---- child processes
|
||||
|
||||
struct PlatChild {
|
||||
|
||||
Reference in new issue
Block a user