aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaytan <laytanlaats@hotmail.com>2025-11-03 19:51:42 +0100
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2026-02-08 13:08:32 +0100
commit470a245f5fc927fa9d04da0adcbcd57574d4067f (patch)
treef726f4443ac3ea3839b6e086f7c1a1bf58d01fa1
parentfb7ac1fb648e567d04626389b8113997fec4cae2 (diff)
new_os: core/prof/spall
-rw-r--r--core/prof/spall/spall.odin29
-rw-r--r--core/prof/spall/spall_linux.odin8
-rw-r--r--core/prof/spall/spall_unix.odin14
-rw-r--r--core/prof/spall/spall_windows.odin14
4 files changed, 28 insertions, 37 deletions
diff --git a/core/prof/spall/spall.odin b/core/prof/spall/spall.odin
index dc53dc3dc..b079c2eb2 100644
--- a/core/prof/spall/spall.odin
+++ b/core/prof/spall/spall.odin
@@ -1,8 +1,9 @@
package spall
-import "core:os"
-import "core:time"
-import "base:intrinsics"
+import "base:intrinsics"
+
+import os "core:os/os2"
+import "core:time"
// File Format
@@ -64,7 +65,9 @@ NAME_EVENT_MAX :: size_of(Name_Event) + 255
Context :: struct {
precise_time: bool,
timestamp_scale: f64,
- fd: os.Handle,
+
+ file: ^os.File,
+ fd: uintptr,
}
Buffer :: struct {
@@ -79,18 +82,20 @@ BUFFER_DEFAULT_SIZE :: 0x10_0000
context_create_with_scale :: proc(filename: string, precise_time: bool, timestamp_scale: f64) -> (ctx: Context, ok: bool) #optional_ok {
- fd, err := os.open(filename, os.O_WRONLY | os.O_APPEND | os.O_CREATE | os.O_TRUNC, 0o600)
+ file, err := os.open(filename, {.Write, .Append, .Create, .Trunc}, {.Read_User, .Write_User})
if err != nil {
return
}
- ctx.fd = fd
+ ctx.file = file
+ ctx.fd = os.fd(file)
+
ctx.precise_time = precise_time
ctx.timestamp_scale = timestamp_scale
temp := [size_of(Manual_Stream_Header)]u8{}
_build_stream_header(temp[:], ctx.timestamp_scale)
- os.write(ctx.fd, temp[:])
+ write(ctx.fd, temp[:])
ok = true
return
}
@@ -109,7 +114,7 @@ context_destroy :: proc(ctx: ^Context) {
return
}
- os.close(ctx.fd)
+ os.close(ctx.file)
ctx^ = Context{}
}
@@ -288,12 +293,12 @@ _buffer_name_process :: proc "contextless" (ctx: ^Context, buffer: ^Buffer, name
buffer.head += _build_name_event(buffer.data[buffer.head:], name, .Name_Process)
}
-@(no_instrumentation)
-write :: proc "contextless" (fd: os.Handle, buf: []byte) -> (n: int, err: os.Error) {
- return _write(fd, buf)
+@(no_instrumentation, private="package")
+write :: proc "contextless" (fd: uintptr, buf: []byte) {
+ _write(fd, buf)
}
-@(no_instrumentation)
+@(no_instrumentation, private="package")
tick_now :: proc "contextless" () -> (ns: i64) {
return _tick_now()
}
diff --git a/core/prof/spall/spall_linux.odin b/core/prof/spall/spall_linux.odin
index 8060af448..207bd8471 100644
--- a/core/prof/spall/spall_linux.odin
+++ b/core/prof/spall/spall_linux.odin
@@ -1,19 +1,17 @@
#+private
package spall
-// Only for types and constants.
-import "core:os"
-
// Package is `#+no-instrumentation`, safe to use.
import "core:sys/linux"
MAX_RW :: 0x7fffffff
@(no_instrumentation)
-_write :: proc "contextless" (fd: os.Handle, data: []byte) -> (n: int, err: os.Error) #no_bounds_check /* bounds check would segfault instrumentation */ {
+_write :: proc "contextless" (fd: uintptr, data: []byte) #no_bounds_check /* bounds check would segfault instrumentation */ {
+ n: int
for n < len(data) {
chunk := data[:min(len(data), MAX_RW)]
- n += linux.write(linux.Fd(fd), chunk) or_return
+ n += linux.write(linux.Fd(fd), chunk) or_break
}
return
}
diff --git a/core/prof/spall/spall_unix.odin b/core/prof/spall/spall_unix.odin
index 455245aad..2f1e356ee 100644
--- a/core/prof/spall/spall_unix.odin
+++ b/core/prof/spall/spall_unix.odin
@@ -2,29 +2,23 @@
#+build darwin, freebsd, openbsd, netbsd
package spall
-// Only for types.
-import "core:os"
-
import "core:sys/posix"
MAX_RW :: 0x7fffffff
@(no_instrumentation)
-_write :: proc "contextless" (fd: os.Handle, data: []byte) -> (n: int, err: os.Error) #no_bounds_check /* bounds check would segfault instrumentation */ {
- if len(data) == 0 {
- return 0, nil
- }
-
+_write :: proc "contextless" (fd: uintptr, data: []byte) #no_bounds_check /* bounds check would segfault instrumentation */ {
+ n: int
for n < len(data) {
chunk := data[:min(len(data), MAX_RW)]
written := posix.write(posix.FD(fd), raw_data(chunk), len(chunk))
if written < 0 {
- return n, os.get_last_error()
+ return
}
n += written
}
- return n, nil
+ return
}
// NOTE(tetra): "RAW" means: Not adjusted by NTP.
diff --git a/core/prof/spall/spall_windows.odin b/core/prof/spall/spall_windows.odin
index 11e216b63..2d059dc4d 100644
--- a/core/prof/spall/spall_windows.odin
+++ b/core/prof/spall/spall_windows.odin
@@ -1,20 +1,13 @@
#+private
package spall
-// Only for types.
-import "core:os"
-
// Package is `#+no-instrumentation`, safe to use.
import win32 "core:sys/windows"
MAX_RW :: 1<<30
@(no_instrumentation)
-_write :: proc "contextless" (fd: os.Handle, data: []byte) -> (int, os.Error) #no_bounds_check /* bounds check would segfault instrumentation */ {
- if len(data) == 0 {
- return 0, nil
- }
-
+_write :: proc "contextless" (fd: uintptr, data: []byte) #no_bounds_check /* bounds check would segfault instrumentation */ {
single_write_length: win32.DWORD
total_write: i64
length := i64(len(data))
@@ -25,11 +18,12 @@ _write :: proc "contextless" (fd: os.Handle, data: []byte) -> (int, os.Error) #n
e := win32.WriteFile(win32.HANDLE(fd), &data[total_write], to_write, &single_write_length, nil)
if single_write_length <= 0 || !e {
- return int(total_write), os.get_last_error()
+ return
}
total_write += i64(single_write_length)
}
- return int(total_write), nil
+
+ return
}
@(no_instrumentation)