diff --git a/.gitignore b/.gitignore index f8f5015..44415db 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ man builds envr envr-go +envr-prof findr/findr findr/findr-prof findr/bench-*.md diff --git a/Makefile b/Makefile index f87baba..cce9c31 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ LINUX_AMD64_BIN := $(BUILD_DIR)/$(APP_NAME)-$(VERSION)-linux-amd64 LINUX_ARM64_BIN := $(BUILD_DIR)/$(APP_NAME)-$(VERSION)-linux-arm64 DARWIN_ARM64_BIN := $(BUILD_DIR)/$(APP_NAME)-$(VERSION)-darwin-arm64 -.PHONY: all clean cleanall build-linux build-darwin compress release help +.PHONY: all clean cleanall build-linux build-darwin compress release profile help # Default target all: release clean @@ -66,6 +66,12 @@ release: build-linux compress @echo "Release artifacts created:" @ls -la $(BUILD_DIR)/*.tar.gz $(BUILD_DIR)/*.zip 2>/dev/null || echo "No compressed artifacts found" +# Build with spall profiling instrumentation +profile: + @echo "Building with spall profiling..." + odin build . -define:SPALL=true -o:speed -out:envr-prof + @echo "Built envr-prof (run it to generate envr.spall)" + # Clean binary files only clean: @echo "Cleaning binary files..." @@ -84,6 +90,7 @@ help: @echo " build-linux - Build Linux binaries only" @echo " build-darwin - Build Darwin binaries only" @echo " compress - Compress all built binaries" + @echo " profile - Build with spall profiling instrumentation" @echo " clean - Remove binary files only" @echo " cleanall - Remove entire build directory" @echo " help - Show this help message" diff --git a/main.odin b/main.odin index 24cb238..0192c89 100644 --- a/main.odin +++ b/main.odin @@ -1,10 +1,36 @@ package main +import "base:runtime" import "core:fmt" import "core:mem" import "core:os" +import "core:prof/spall" +import "core:sync" + +SPALL :: #config(SPALL, false) +when SPALL { + spall_ctx: spall.Context + @(thread_local) + spall_buffer: spall.Buffer +} main :: proc() { + when SPALL { + ctx, spall_ok := spall.context_create_with_scale("envr.spall", false, 1.0) + if !spall_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) + } + when ODIN_DEBUG { heap_track: mem.Tracking_Allocator mem.tracking_allocator_init(&heap_track, context.allocator) @@ -60,3 +86,21 @@ 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) + } +} + diff --git a/test_cond_import b/test_cond_import new file mode 100755 index 0000000..c9598aa Binary files /dev/null and b/test_cond_import differ