[sys] Add some developer flags for cache/hunk/zone

And make Sys_MaskPrintf take the developer enum rather than just a raw
int.

It was actually getting some nasty hunk corruption errors when under
memory pressure that made it clear the sound system needs some work.
This commit is contained in:
Bill Currie 2022-06-03 12:04:27 +09:00
parent 9166b08b06
commit 3293fcaab0
4 changed files with 19 additions and 15 deletions

View file

@ -87,8 +87,6 @@ int64_t Sys_TimeBase (void) __attribute__ ((const));
double Sys_DoubleTimeBase (void) __attribute__ ((const));
void Sys_TimeOfDay(date_t *date);
void Sys_MaskPrintf (int mask, const char *fmt, ...) __attribute__((format(PRINTF,2,3)));
#define SYS_DEVELOPER(developer) SYS_DeveloperID_##developer,
enum {
#include "QF/sys_developer.h"
@ -97,10 +95,12 @@ enum {
// bit 0 so developer 1 will pick it up
#define SYS_DEVELOPER(developer) \
SYS_##developer = (SYS_dev | (1 << (SYS_DeveloperID_##developer + 1))),
enum {
typedef enum {
SYS_dev = 1,
#include "QF/sys_developer.h"
};
} sys_developer_e;
void Sys_MaskPrintf (sys_developer_e mask, const char *fmt, ...) __attribute__((format(PRINTF,2,3)));
struct qf_fd_set;
int Sys_Select (int maxfd, struct qf_fd_set *fdset, int64_t usec);

View file

@ -30,6 +30,9 @@
#endif
SYS_DEVELOPER (warn)
SYS_DEVELOPER (cache)
SYS_DEVELOPER (hunk)
SYS_DEVELOPER (zone)
SYS_DEVELOPER (vid)
SYS_DEVELOPER (input)
SYS_DEVELOPER (fs_nf)

View file

@ -353,7 +353,7 @@ Sys_Printf (const char *fmt, ...)
}
VISIBLE void
Sys_MaskPrintf (int mask, const char *fmt, ...)
Sys_MaskPrintf (sys_developer_e mask, const char *fmt, ...)
{
va_list args;

View file

@ -222,7 +222,7 @@ Z_TagMalloc (memzone_t *zone, size_t size, int tag)
int requested_size = size;
memblock_t *start, *rover, *new, *base;
if (developer & SYS_dev)
if (developer & SYS_zone)
Z_CheckHeap (zone); // DEBUG
if (!tag) {
@ -291,7 +291,7 @@ Z_Realloc (memzone_t *zone, void *ptr, size_t size)
if (!ptr)
return Z_Malloc (zone, size);
if (developer & SYS_dev)
if (developer & SYS_zone)
Z_CheckHeap (zone); // DEBUG
block = (memblock_t *) ((byte *) ptr - sizeof (memblock_t));
@ -821,7 +821,7 @@ Cache_Move (cache_system_t *c)
// we are clearing up space at the bottom, so allocate it late
new = Cache_TryAlloc (hunk, c->size, true);
if (new) {
Sys_MaskPrintf (SYS_dev, "cache_move ok\n");
Sys_MaskPrintf (SYS_cache, "cache_move ok\n");
memcpy (new + 1, c + 1, c->size - sizeof (cache_system_t));
new->user = c->user;
@ -829,7 +829,7 @@ Cache_Move (cache_system_t *c)
Cache_Free (c->user);
new->user->data = (void *) (new + 1);
} else {
Sys_MaskPrintf (SYS_dev, "cache_move failed\n");
Sys_MaskPrintf (SYS_cache, "cache_move failed\n");
Cache_Free (c->user); // tough luck...
}
@ -1122,7 +1122,7 @@ Cache_Free (cache_user_t *c)
Sys_Error ("Cache_Free: attempt to free locked block");
const int sz = sizeof (cs->name);
Sys_MaskPrintf (SYS_dev, "Cache_Free: freeing '%.*s' %p\n",
Sys_MaskPrintf (SYS_cache, "Cache_Free: freeing '%.*s' %p\n",
sz, cs->name, cs);
Cache_UnlinkLRU (cs);
@ -1195,16 +1195,17 @@ Cache_Alloc (cache_user_t *c, size_t size, const char *name)
static void
Cache_Report_r (memhunk_t *hunk)
{
if (!hunk) { hunk = global_hunk; } //FIXME clean up callers
Sys_MaskPrintf (SYS_dev, "%4.1f megabyte data cache\n",
(hunk->size - hunk->high_used -
hunk->low_used) / (float) (1024 * 1024));
Sys_Printf ("%4.1f megabyte data cache\n",
(hunk->size - hunk->high_used -
hunk->low_used) / (float) (1024 * 1024));
}
VISIBLE void
Cache_Report (void)
{
Cache_Report_r (global_hunk);
if (developer & SYS_cache) {
Cache_Report_r (global_hunk);
}
}
VISIBLE void