mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
perf: Added spall support.
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
.direnv
|
.direnv
|
||||||
result
|
result
|
||||||
thor
|
thor
|
||||||
|
*.spall
|
||||||
|
thor-prof
|
||||||
|
|||||||
@@ -1,10 +1,38 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "base:runtime"
|
||||||
|
import "core:fmt"
|
||||||
import "core:log"
|
import "core:log"
|
||||||
import "core:os"
|
import "core:os"
|
||||||
|
import "core:prof/spall"
|
||||||
|
import "core:sync"
|
||||||
import "core:time"
|
import "core:time"
|
||||||
|
|
||||||
|
SPALL :: #config(SPALL, false)
|
||||||
|
|
||||||
|
when SPALL {
|
||||||
|
spall_ctx: spall.Context
|
||||||
|
@(thread_local)
|
||||||
|
spall_buffer: spall.Buffer
|
||||||
|
}
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
|
when SPALL {
|
||||||
|
ctx, ok := spall.context_create_with_scale("thor.spall", false, 1.0)
|
||||||
|
if !ok {
|
||||||
|
fmt.eprintln("Failed to create spall trace file")
|
||||||
|
os.exit(1)
|
||||||
|
}
|
||||||
|
spall_ctx = ctx
|
||||||
|
defer spall.context_destroy(&spall_ctx)
|
||||||
|
|
||||||
|
spall_backing := make([]u8, spall.BUFFER_DEFAULT_SIZE)
|
||||||
|
defer delete(spall_backing)
|
||||||
|
|
||||||
|
spall_buffer = spall.buffer_create(spall_backing, u32(sync.current_thread_id()))
|
||||||
|
defer spall.buffer_destroy(&spall_ctx, &spall_buffer)
|
||||||
|
}
|
||||||
|
|
||||||
console_logger := log.create_console_logger()
|
console_logger := log.create_console_logger()
|
||||||
context.logger = console_logger
|
context.logger = console_logger
|
||||||
defer log.destroy_console_logger(console_logger)
|
defer log.destroy_console_logger(console_logger)
|
||||||
@@ -27,3 +55,20 @@ main :: proc() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
when SPALL {
|
||||||
|
@(instrumentation_enter)
|
||||||
|
spall_enter :: proc "contextless" (
|
||||||
|
proc_address, call_site_return_address: rawptr,
|
||||||
|
loc: runtime.Source_Code_Location,
|
||||||
|
) {
|
||||||
|
spall._buffer_begin(&spall_ctx, &spall_buffer, "", "", loc)
|
||||||
|
}
|
||||||
|
|
||||||
|
@(instrumentation_exit)
|
||||||
|
spall_exit :: proc "contextless" (
|
||||||
|
proc_address, call_site_return_address: rawptr,
|
||||||
|
loc: runtime.Source_Code_Location,
|
||||||
|
) {
|
||||||
|
spall._buffer_end(&spall_ctx, &spall_buffer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user