fix profiler buffer size usage

This commit is contained in:
dzaima 2023-03-24 13:47:33 +02:00
parent 98f4df88d0
commit e4c95dce22

View File

@ -1413,7 +1413,7 @@ NOINLINE void vm_pstLive() {
#if __has_include(<sys/time.h>) && __has_include(<signal.h>) && !NO_MMAP && !WASM #if __has_include(<sys/time.h>) && __has_include(<signal.h>) && !NO_MMAP && !WASM
#include <sys/time.h> #include <sys/time.h>
#include <signal.h> #include <signal.h>
#define PROFILE_BUFFER (1ULL<<25) #define PROFILE_BUFFER (1ULL<<25) // number of `Profiler_ent`s
typedef struct Profiler_ent { typedef struct Profiler_ent {
Comp* comp; Comp* comp;
@ -1466,7 +1466,7 @@ i32 profiler_index(void** mapRaw, B comp);
void profiler_freeMap(void* mapRaw); void profiler_freeMap(void* mapRaw);
bool profiler_alloc(void) { bool profiler_alloc(void) {
profiler_buf_s = profiler_buf_c = mmap(NULL, PROFILE_BUFFER, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); profiler_buf_s = profiler_buf_c = mmap(NULL, PROFILE_BUFFER*sizeof(Profiler_ent), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (profiler_buf_s == MAP_FAILED) { if (profiler_buf_s == MAP_FAILED) {
fprintf(stderr, "Failed to allocate profiler buffer\n"); fprintf(stderr, "Failed to allocate profiler buffer\n");
return false; return false;
@ -1476,7 +1476,7 @@ bool profiler_alloc(void) {
return true; return true;
} }
void profiler_free(void) { void profiler_free(void) {
munmap(profiler_buf_s, PROFILE_BUFFER); munmap(profiler_buf_s, PROFILE_BUFFER*sizeof(Profiler_ent));
} }
bool profiler_active; bool profiler_active;
@ -1488,7 +1488,7 @@ bool profiler_start(i64 hz) {
bool profiler_stop(void) { bool profiler_stop(void) {
if (!profiler_active) return false; if (!profiler_active) return false;
profiler_active = false; profiler_active = false;
if (profile_buf_full) fprintf(stderr, "Profiler buffer ran out in the middle of execution. Only timings of the start of profiling will be shown.\n"); if (profile_buf_full) fprintf(stderr, "Profiler buffer ran out in the middle of execution. Only timings of the first "N64u" samples will be shown.\n", (u64)PROFILE_BUFFER);
return setProfTimer(0) && setProfHandler(false); return setProfTimer(0) && setProfHandler(false);
} }