Write the session's reports when the window loses the focus in play, more often in play, and log every end of the game in the launcher.

The session of 2026-11-13 ended 8 s after its window lost the focus, after 7 minutes of play, with none of the game's exit lines: no frame-time summary of its last period, no stutter map of its last minute and no growth ranking at all, as the ranking came every 10 minutes. When the window loses the focus in play, the present thread now writes the frame-time summary so far (starting a new period), the stutter map and the growth ranking at its next present, at most once a minute; formatting only, nothing asks the device. The growth ranking comes every 2 minutes of play instead of 10, the stutter map every 5 instead of 10.

A process that ends through exit() rather than plat_exit now writes the log thread's queue last, after the frame-time summary's exit handler, instead of losing it.

The launcher logged a game's end only for a nonzero code, so the session's end with code 0 left no line anywhere. It now logs every end of a game it started, and when the game's log has no line of the game's own end (the window's close, the game's ExitProcess, a timed run's end, a FATAL or exit line), it notes the end there too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 12:41:44 -05:00
parent 00081be563
commit 7b0dbeb18d
11 changed files with 116 additions and 7 deletions

View File

@@ -75,6 +75,7 @@ void gfx_window_focus_changed(int in) {
plat_local_time(&t);
rt_log("gfx: window %s the focus at %04d-%02d-%02d %02d:%02d:%02d local time", in ? "gained" : "lost",
t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
if (!in) perf_focus_lost(); // the session's reports, in case the process is ended from outside next (perf.c)
}
// The window was closed: the process ends with it, once a save Commit still running in the background is

View File

@@ -102,6 +102,7 @@ void perf_present(uint64_t frame);
void perf_cpu_start(void); // the process's logical processors (NX2NAVI_CACHE_DIE, NX2NAVI_ONE_PER_CORE), at start
int perf_cpu_on_cache_die(void); // 1 while the process runs on the die with the largest L3 cache alone (perf.c cpu_placement)
void perf_summary_flush(void); // prints the frame-time summary of the running period (exit); the 60 s lines come from perf_present
void perf_focus_lost(void); // the window lost the focus: the session's reports at the next present, in play
void gfx_exit_log(void); // back end's lines for the exit summary (weak no-op in prof_win.c)
void gfx_window_closed(void); // gfx_present.c (gfx_wsys.h): the end of a closed window; does not return
void perf_gpu_wait(uint64_t t0); // a wait for a GPU fence ended (any thread; the render thread's also counts as PERF_FENCE)

View File

@@ -53,9 +53,15 @@ void perf_gpu_busy(uint64_t ns) { plat_add64(&gpu_busy_total, (int64_t)ns); }
uint64_t perf_gpu_busy_total(void) { return (uint64_t)__atomic_load_n(&gpu_busy_total, __ATOMIC_RELAXED); }
// Registered before the handlers below, so it runs after them (atexit's order is the reverse): a process that ends
// through exit() rather than plat_exit, whose log sync this is, gets the lines of the frame-time summary, the stutter
// map and everything queued before them into the log instead of losing them with the log thread's queue.
static void log_sync_at_exit(void) { rt_log_sync(); }
void prof_start(void) {
flight_init();
stutter_map_init();
atexit(log_sync_at_exit);
atexit(perf_summary_flush); // boot.c's _exit path goes through prof_write instead
perf_base = (rt_trace & RT_TRACE_PERF) || flight_on;
perf_on = perf_base || overlay == 2;
@@ -586,6 +592,33 @@ static void ft_report(uint64_t now, const char *tag) {
}
__attribute__((weak)) void gfx_exit_log(void) {}
__attribute__((weak)) void vk_mem_rank_log(const char *when) { (void)when; }
// The session's reports when the window loses the focus in play: the frame-time summary of the period so far (which
// starts a new period), the stutter map and the memory report's growth ranking, at most every SESSION_REPORT_GAP_NS.
// They are written at the exit too (perf_summary_flush, vk_mem_exit_log), but a process ended from outside, or by a
// path that skips them, leaves none: a session of 2026-11-13 ended 8 s after its window lost the focus, after 7 minutes
// of play, with no ranking (one every 10 minutes then) and no map of its last minute. gfx_present.c
// gfx_window_focus_changed asks for them; the present thread writes them at its next present (perf_present). Formatting
// only: no device call, no wait.
#define SESSION_REPORT_GAP_NS 60000000000ull
static volatile int32_t session_due;
void perf_focus_lost(void) {
if (frame_step_world_us() >= 0) plat_xchg32(&session_due, 1); // in play: the loaded save's world clock runs
}
static void session_report(uint64_t now) {
static uint64_t last;
if (last && now - last < SESSION_REPORT_GAP_NS) return;
last = now;
if (summary_t0) {
ft_report(now, "at focus loss");
summary_t0 = now;
}
stutter_report("at focus loss");
vk_mem_rank_log("at focus loss, after");
}
// The renderer's per-frame texture work (vk_texture.c): closes the frame's sums; d is the frame's interval.
__attribute__((weak)) void vk_texstat_frame(uint64_t frame, uint64_t d) { (void)frame, (void)d; }
@@ -891,6 +924,7 @@ void perf_present(uint64_t frame) {
uint64_t now = kern_now_ns(), d = last ? now - last : 0;
prof_sampler_frame(frame, now, last ? d : 0);
uint64_t rep = ft_frame(frame, now, d); // d is 0 on the first present: it only starts the period
if (__atomic_load_n(&session_due, __ATOMIC_RELAXED) && plat_xchg32(&session_due, 0)) session_report(now);
ab_b += rt_ab();
cpu_placement();
reserve_sweep(frame);

View File

@@ -15,7 +15,8 @@
// What a hitch went to comes from the frame-time summary's split (perf.c ft_frame: pipeline, translation, texture,
// fence, pacing, replay, unattributed), with the draws that met a pipeline or a shader missing between the previous
// present and this one (stutter_miss, from the replay thread). Each hitch gets a "stutter:" line, at most
// SM_LINES_PER_S a second and SM_LINES_MAX in all; the counts go on past that. Every SM_REPORT_NS of play and at exit,
// SM_LINES_PER_S a second and SM_LINES_MAX in all; the counts go on past that. Every SM_REPORT_NS of play, when the
// window loses the focus in play (perf.c session_report) and at exit,
// "stutter map" lines rank the areas by their hitches and the pipelines by the time draws lost to them, each with
// whether this install had recorded it before (the pipeline list or an earlier run) and whether one of its shaders was
// translated in play rather than prepared.
@@ -49,7 +50,7 @@ int stutter_map_on;
#define SM_RING 256 // draws that met something missing, between two presents
#define SM_LINES_MAX 4000
#define SM_LINES_PER_S 5
#define SM_REPORT_NS 600000000000ull // the map every 10 minutes of play
#define SM_REPORT_NS 300000000000ull // the map every 5 minutes of play
#define SM_TOP_AREAS 40
#define SM_TOP_PIPES 40

View File

@@ -21,4 +21,4 @@ void stutter_ready(int mesh, const uint8_t *vi, const uint8_t *fi, double ms, in
// the last one is the part nothing recorded explains), cause the one the frame is charged to.
void stutter_frame(uint64_t frame, uint64_t now, uint64_t d, const uint64_t *part, const char *const *names, int n,
int cause);
void stutter_report(const char *tag); // the map so far; every 10 minutes of play and at exit
void stutter_report(const char *tag); // the map so far; every 5 minutes of play, at a focus loss in play and at exit

View File

@@ -499,6 +499,7 @@ void vk_mem_lost_report(void); // a line with the video memor
float vk_mem_device_used_mb(void); // device-local memory this process holds (the driver's budget
// figure), MB; -1 without VK_EXT_memory_budget. Any thread.
void vk_mem_stage_log(const char *stage); // one line after a boot stage: device memory, process commit
void vk_mem_rank_log(const char *when); // the growth ranking now, "when" leading its minutes of play
void vk_mem_exit_log(void); // at the process's end: the memory report's growth ranking of the
// session (vk_memory.c growth_take), once it reached play
// VRAM in use and its budget, summed over the DEVICE_LOCAL heaps. exact 1: VK_EXT_memory_budget (the whole process),

View File

@@ -5415,7 +5415,9 @@ uint64_t vk_mem_give_back(void) {
// their locks (a fraction of a millisecond, once a report), the C runtime heap's summary. Nothing is counted per frame.
#define IDLE_MIN 10 // pipelines no lookup reached for this many minutes count as unused
#define GROWTH_STEP (64ull << 20) // growth_take names a category that grew by more than this
#define RANK_EVERY_NS (600ull * 1000000000ull) // the ranking's period in play
// the ranking's period in play: every 2 minutes, as a session ended without its exit lines after 7 minutes of play had
// no ranking at all with one every 10 (2026-11-13); a ranking is one line of figures the book already holds
#define RANK_EVERY_NS (120ull * 1000000000ull)
#define HEAP_SLOW_NS 2000000ull // a heap summary that took longer is not asked for again
typedef struct {
@@ -5608,6 +5610,13 @@ void vk_mem_exit_log(void) {
plat_mutex_unlock(&grow_lock);
}
// The same ranking at a moment of the caller's (perf.c session_report, when the window loses the focus).
void vk_mem_rank_log(const char *when) {
plat_mutex_lock(&grow_lock);
if (gbook.play) rank_log_locked(when, plat_now_ns());
plat_mutex_unlock(&grow_lock);
}
static void beyond_log(VkCtx *c, uint64_t frame, const VkPhysicalDeviceMemoryBudgetPropertiesEXT *bp, const VmaBudget *vb,
const ReportFig *f) {
VkPipeMem pm;