Report test memory usage only if there's an issue

Adds new option `ODIN_TEST_ALWAYS_REPORT_MEMORY`, for when you always
want to see the memory usage report.
This commit is contained in:
Feoramund
2024-06-02 14:47:07 -04:00
parent e1a3c0e21d
commit 49fa66370f
+16
View File
@@ -26,6 +26,8 @@ _ :: strings
TEST_THREADS : int : #config(ODIN_TEST_THREADS, 0) TEST_THREADS : int : #config(ODIN_TEST_THREADS, 0)
// Track the memory used by each test. // Track the memory used by each test.
TRACKING_MEMORY : bool : #config(ODIN_TEST_TRACK_MEMORY, true) TRACKING_MEMORY : bool : #config(ODIN_TEST_TRACK_MEMORY, true)
// Always report how much memory is used, even when there are no leaks or bad frees.
ALWAYS_REPORT_MEMORY : bool : #config(ODIN_TEST_ALWAYS_REPORT_MEMORY, false)
// Specify how much memory each thread allocator starts with. // Specify how much memory each thread allocator starts with.
PER_THREAD_MEMORY : int : #config(ODIN_TEST_THREAD_MEMORY, mem.ROLLBACK_STACK_DEFAULT_BLOCK_SIZE) PER_THREAD_MEMORY : int : #config(ODIN_TEST_THREAD_MEMORY, mem.ROLLBACK_STACK_DEFAULT_BLOCK_SIZE)
// Select a specific set of tests to run by name. // Select a specific set of tests to run by name.
@@ -382,8 +384,14 @@ runner :: proc(internal_tests: []Internal_Test) -> bool {
} }
when TRACKING_MEMORY { when TRACKING_MEMORY {
when ALWAYS_REPORT_MEMORY {
pkg_log.info("Memory tracking is enabled. Tests will log their memory usage when complete.") pkg_log.info("Memory tracking is enabled. Tests will log their memory usage when complete.")
} else {
pkg_log.info("Memory tracking is enabled. Tests will log their memory usage if there's an issue.")
}
pkg_log.info("< Final Mem/ Total Mem> < Peak Mem> (#Free/Alloc) :: [package.test_name]") pkg_log.info("< Final Mem/ Total Mem> < Peak Mem> (#Free/Alloc) :: [package.test_name]")
} else when ALWAYS_REPORT_MEMORY {
pkg_log.warn("ODIN_TEST_ALWAYS_REPORT_MEMORY is true, but ODIN_TRACK_MEMORY is false.")
} }
start_time := time.now() start_time := time.now()
@@ -397,10 +405,18 @@ runner :: proc(internal_tests: []Internal_Test) -> bool {
when TRACKING_MEMORY { when TRACKING_MEMORY {
#no_bounds_check tracker := &task_memory_trackers[data.allocator_index] #no_bounds_check tracker := &task_memory_trackers[data.allocator_index]
when ALWAYS_REPORT_MEMORY {
should_report := true
} else {
should_report := len(tracker.allocation_map) + len(tracker.bad_free_array) > 0
}
if should_report {
write_memory_report(batch_writer, tracker, data.it.pkg, data.it.name) write_memory_report(batch_writer, tracker, data.it.pkg, data.it.name)
pkg_log.info(bytes.buffer_to_string(&batch_buffer)) pkg_log.info(bytes.buffer_to_string(&batch_buffer))
bytes.buffer_reset(&batch_buffer) bytes.buffer_reset(&batch_buffer)
}
mem.tracking_allocator_reset(tracker) mem.tracking_allocator_reset(tracker)
} }