aboutsummaryrefslogtreecommitdiff
path: root/core/log
diff options
context:
space:
mode:
authorLaytan Laats <laytanlaats@hotmail.com>2023-12-16 01:27:38 +0100
committerLaytan Laats <laytanlaats@hotmail.com>2023-12-16 01:27:38 +0100
commit58ff3dd1edc7707db574c1fbd23a16d0bbb07512 (patch)
tree79a83799e0067bbee224cb074808f2f19384766b /core/log
parentcf8c9a6be4120f4e20093051c15a141794575596 (diff)
log allocator: add option to switch between bytes and human format
Diffstat (limited to 'core/log')
-rw-r--r--core/log/log_allocator.odin59
1 files changed, 34 insertions, 25 deletions
diff --git a/core/log/log_allocator.odin b/core/log/log_allocator.odin
index f2211a010..a6788a957 100644
--- a/core/log/log_allocator.odin
+++ b/core/log/log_allocator.odin
@@ -2,18 +2,26 @@ package log
import "core:runtime"
+Log_Allocator_Format :: enum {
+ Bytes, // Actual number of bytes.
+ Human, // Bytes in human units like bytes, kibibytes, etc. as appropriate.
+}
+
Log_Allocator :: struct {
allocator: runtime.Allocator,
level: Level,
prefix: string,
locked: bool,
+ size_fmt: Log_Allocator_Format,
}
-log_allocator_init :: proc(la: ^Log_Allocator, level: Level, allocator := context.allocator, prefix := "") {
+log_allocator_init :: proc(la: ^Log_Allocator, level: Level, size_fmt := Log_Allocator_Format.Bytes,
+ allocator := context.allocator, prefix := "") {
la.allocator = allocator
la.level = level
la.prefix = prefix
la.locked = false
+ la.size_fmt = size_fmt
}
@@ -37,27 +45,27 @@ log_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode,
switch mode {
case .Alloc:
- logf(
- la.level,
- "%s%s>>> ALLOCATOR(mode=.Alloc, size=%m, alignment=%d)",
- la.prefix, padding, size, alignment,
- location = location,
- )
+ fmt: string
+ switch la.size_fmt {
+ case .Bytes: fmt = "%s%s>>> ALLOCATOR(mode=.Alloc, size=%d, alignment=%d)"
+ case .Human: fmt = "%s%s>>> ALLOCATOR(mode=.Alloc, size=%m, alignment=%d)"
+ }
+ logf(la.level, fmt, la.prefix, padding, size, alignment, location = location)
case .Alloc_Non_Zeroed:
- logf(
- la.level,
- "%s%s>>> ALLOCATOR(mode=.Alloc_Non_Zeroed, size=%m, alignment=%d)",
- la.prefix, padding, size, alignment,
- location = location,
- )
+ fmt: string
+ switch la.size_fmt {
+ case .Bytes: fmt = "%s%s>>> ALLOCATOR(mode=.Alloc_Non_Zeroed, size=%d, alignment=%d)"
+ case .Human: fmt = "%s%s>>> ALLOCATOR(mode=.Alloc_Non_Zeroed, size=%m, alignment=%d)"
+ }
+ logf(la.level, fmt, la.prefix, padding, size, alignment, location = location)
case .Free:
if old_size != 0 {
- logf(
- la.level,
- "%s%s<<< ALLOCATOR(mode=.Free, ptr=%p, size=%m)",
- la.prefix, padding, old_memory, old_size,
- location = location,
- )
+ fmt: string
+ switch la.size_fmt {
+ case .Bytes: fmt = "%s%s<<< ALLOCATOR(mode=.Free, ptr=%p, size=%d)"
+ case .Human: fmt = "%s%s<<< ALLOCATOR(mode=.Free, ptr=%p, size=%m)"
+ }
+ logf(la.level, fmt, la.prefix, padding, old_memory, old_size, location = location)
} else {
logf(
la.level,
@@ -74,12 +82,13 @@ log_allocator_proc :: proc(allocator_data: rawptr, mode: runtime.Allocator_Mode,
location = location,
)
case .Resize:
- logf(
- la.level,
- "%s%s>>> ALLOCATOR(mode=.Resize, ptr=%p, old_size=%m, size=%m, alignment=%d)",
- la.prefix, padding, old_memory, old_size, size, alignment,
- location = location,
- )
+ fmt: string
+ switch la.size_fmt {
+ case .Bytes: fmt = "%s%s>>> ALLOCATOR(mode=.Resize, ptr=%p, old_size=%d, size=%d, alignment=%d)"
+ case .Human: fmt = "%s%s>>> ALLOCATOR(mode=.Resize, ptr=%p, old_size=%m, size=%m, alignment=%d)"
+ }
+ logf(la.level, fmt, la.prefix, padding, old_memory, old_size, size, alignment, location = location)
+
case .Query_Features:
logf(
la.level,