From 30ced041376fcfe6684f72f45ef16c335b8ed89d Mon Sep 17 00:00:00 2001 From: Colin Davidson Date: Thu, 9 Mar 2023 15:26:27 -0800 Subject: [PATCH 1/5] log buffer flushes to trace --- core/prof/spall/spall.odin | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/prof/spall/spall.odin b/core/prof/spall/spall.odin index ff8c69222..5d3fcdf83 100644 --- a/core/prof/spall/spall.odin +++ b/core/prof/spall/spall.odin @@ -95,7 +95,7 @@ context_destroy :: proc(ctx: ^Context) { } buffer_create :: proc(data: []byte, tid: u32 = 0, pid: u32 = 0) -> (buffer: Buffer, ok: bool) #optional_ok { - assert(len(data) > 0) + assert(len(data) >= 1024) buffer.data = data buffer.tid = tid buffer.pid = pid @@ -105,8 +105,13 @@ buffer_create :: proc(data: []byte, tid: u32 = 0, pid: u32 = 0) -> (buffer: Buff } buffer_flush :: proc(ctx: ^Context, buffer: ^Buffer) { + start := _trace_now(ctx) os.write(ctx.fd, buffer.data[:buffer.head]) buffer.head = 0 + end := _trace_now(ctx) + + buffer.head += _build_begin(buffer.data[buffer.head:], "Spall Trace Buffer Flush", "", start, buffer.tid, buffer.pid) + buffer.head += _build_end(buffer.data[buffer.head:], end, buffer.tid, buffer.pid) } buffer_destroy :: proc(ctx: ^Context, buffer: ^Buffer) { @@ -171,10 +176,11 @@ _build_begin :: proc "contextless" (buffer: []u8, name: string, args: string, ts mem.copy(raw_data(buffer[size_of(Begin_Event):]), raw_data(name), name_len) mem.copy(raw_data(buffer[size_of(Begin_Event)+name_len:]), raw_data(args), args_len) ok = true + return } -_build_end :: proc(buffer: []u8, ts: f64, tid: u32, pid: u32) -> (event_size: int, ok: bool) #optional_ok { +_build_end :: proc "contextless" (buffer: []u8, ts: f64, tid: u32, pid: u32) -> (event_size: int, ok: bool) #optional_ok { ev := (^End_Event)(raw_data(buffer)) event_size = size_of(End_Event) if event_size > len(buffer) { @@ -186,6 +192,7 @@ _build_end :: proc(buffer: []u8, ts: f64, tid: u32, pid: u32) -> (event_size: in ev.tid = u32le(tid) ev.ts = f64le(ts) ok = true + return } From 6f4f2754d6a8106bc922765d3006b6cce615d124 Mon Sep 17 00:00:00 2001 From: Colin Davidson Date: Thu, 9 Mar 2023 16:05:16 -0800 Subject: [PATCH 2/5] add basic usage example --- core/prof/spall/doc.odin | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 core/prof/spall/doc.odin diff --git a/core/prof/spall/doc.odin b/core/prof/spall/doc.odin new file mode 100644 index 000000000..a04c9e420 --- /dev/null +++ b/core/prof/spall/doc.odin @@ -0,0 +1,24 @@ +/* +import "core:prof/spall" + +spall_ctx: spall.Context +spall_buffer: spall.Buffer + +foo :: proc() { + spall.SCOPED_EVENT(&spall_ctx, &spall_buffer, #procedure) +} + +main :: proc() { + spall_ctx = spall.context_create("trace_test.spall") + defer spall.context_destroy(&spall_ctx) + + buffer_backing := make([]u8, spall.BUFFER_DEFAULT_SIZE) + spall_buffer = spall.buffer_create(buffer_backing) + defer spall.buffer_destroy(&spall_ctx, &spall_buffer) + + for i := 0; i < 9001; i += 1 { + foo() + } +} +*/ +package spall From 2334dadb6aa7650278213ec6364543ab8e47297c Mon Sep 17 00:00:00 2001 From: Colin Davidson Date: Thu, 9 Mar 2023 16:34:43 -0800 Subject: [PATCH 3/5] add main scope --- core/prof/spall/doc.odin | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/prof/spall/doc.odin b/core/prof/spall/doc.odin index a04c9e420..0f3cc8bb8 100644 --- a/core/prof/spall/doc.odin +++ b/core/prof/spall/doc.odin @@ -16,6 +16,8 @@ main :: proc() { spall_buffer = spall.buffer_create(buffer_backing) defer spall.buffer_destroy(&spall_ctx, &spall_buffer) + spall.SCOPED_EVENT(&spall_ctx, &spall_buffer, #procedure) + for i := 0; i < 9001; i += 1 { foo() } From 63b5d472fa6acb9c8d94a94fb0abe20436ffa32c Mon Sep 17 00:00:00 2001 From: William Roe Date: Fri, 10 Mar 2023 16:07:06 +0000 Subject: [PATCH 4/5] Fix documentation example of strings.to_upper This looks like it was a copy/paste mistake --- core/strings/conversion.odin | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/strings/conversion.odin b/core/strings/conversion.odin index ab827490d..8a67618da 100644 --- a/core/strings/conversion.odin +++ b/core/strings/conversion.odin @@ -78,8 +78,8 @@ to_lower :: proc(s: string, allocator := context.allocator) -> string { returns the input string `s` with all runes set to upper case always allocates using the `allocator` - strings.to_lower("test") -> TEST - strings.to_lower("Test") -> TEST + strings.to_upper("test") -> TEST + strings.to_upper("Test") -> TEST */ to_upper :: proc(s: string, allocator := context.allocator) -> string { b: Builder From ac0f3c84332feb66113db5069fd2126a875f5156 Mon Sep 17 00:00:00 2001 From: Jon Lipstate Date: Fri, 10 Mar 2023 19:24:11 -0800 Subject: [PATCH 5/5] resolve doc/spall package name conflict --- core/prof/spall/spall.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/prof/spall/spall.odin b/core/prof/spall/spall.odin index 5d3fcdf83..6a78c466e 100644 --- a/core/prof/spall/spall.odin +++ b/core/prof/spall/spall.odin @@ -1,4 +1,4 @@ -package prof_spall +package spall import "core:os" import "core:time"