diff --git a/build.lua b/build.lua
index 8e395dc9..e9c85c28 100644
--- a/build.lua
+++ b/build.lua
@@ -63,7 +63,7 @@ for i = 1, #arg do
end
local ldflags = ""
-local cflags = " -g -march=haswell -I common -Wall -Werror -Wno-unused -Wno-deprecated -DMI_SKIP_COLLECT_ON_EXIT -DCUIK_ALLOW_THREADS -I mimalloc/include"
+local cflags = " -g -march=haswell -I common -Wall -Werror -Wno-unused -Wno-deprecated -DMI_SKIP_COLLECT_ON_EXIT -DCUIK_ALLOW_THREADS -I mimalloc/include -fdiagnostics-color=always"
if options.asan then
cflags = cflags.." -fsanitize=address"
diff --git a/main/spall.h b/main/spall.h
index 724cb4fd..6b37e57d 100644
--- a/main/spall.h
+++ b/main/spall.h
@@ -36,6 +36,7 @@ TODO: Optional Helper APIs:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
+#include <pthread.h>
#define SPALL_FN static inline SPALL_NOINSTRUMENT
@@ -67,9 +68,9 @@ typedef struct SpallBeginEvent {
uint8_t type; // = SpallEventType_Begin
uint8_t category;
- uint32_t pid;
- uint32_t tid;
- double when;
+ uint32_t pid;
+ pthread_t tid;
+ double when;
uint8_t name_length;
uint8_t args_length;
@@ -82,10 +83,10 @@ typedef struct SpallBeginEventMax {
} SpallBeginEventMax;
typedef struct SpallEndEvent {
- uint8_t type; // = SpallEventType_End
- uint32_t pid;
- uint32_t tid;
- double when;
+ uint8_t type; // = SpallEventType_End
+ uint32_t pid;
+ pthread_t tid;
+ double when;
} SpallEndEvent;
typedef struct SpallPadSkipEvent {
@@ -255,7 +256,7 @@ SPALL_FN size_t spall_build_header(void *buffer, size_t rem_size, double timesta
header->must_be_0 = 0;
return header_size;
}
-SPALL_FN SPALL_FORCEINLINE size_t spall_build_begin(void *buffer, size_t rem_size, const char *name, signed long name_len, const char *args, signed long args_len, double when, uint32_t tid, uint32_t pid) {
+SPALL_FN SPALL_FORCEINLINE size_t spall_build_begin(void *buffer, size_t rem_size, const char *name, signed long name_len, const char *args, signed long args_len, double when, pthread_t tid, uint32_t pid) {
SpallBeginEventMax *ev = (SpallBeginEventMax *)buffer;
uint8_t trunc_name_len = (uint8_t)SPALL_MIN(name_len, 255); // will be interpreted as truncated in the app (?)
uint8_t trunc_args_len = (uint8_t)SPALL_MIN(args_len, 255); // will be interpreted as truncated in the app (?)
@@ -277,7 +278,7 @@ SPALL_FN SPALL_FORCEINLINE size_t spall_build_begin(void *buffer, size_t rem_siz
return ev_size;
}
-SPALL_FN SPALL_FORCEINLINE size_t spall_build_end(void *buffer, size_t rem_size, double when, uint32_t tid, uint32_t pid) {
+SPALL_FN SPALL_FORCEINLINE size_t spall_build_end(void *buffer, size_t rem_size, double when, pthread_t tid, uint32_t pid) {
size_t ev_size = sizeof(SpallEndEvent);
if (ev_size > rem_size) {
return 0;
@@ -352,7 +353,7 @@ SPALL_FN bool spall_flush(SpallProfile *ctx) {
return true;
}
-SPALL_FN SPALL_FORCEINLINE bool spall_buffer_begin_args(SpallProfile *ctx, SpallBuffer *wb, const char *name, signed long name_len, const char *args, signed long args_len, double when, uint32_t tid, uint32_t pid) {
+SPALL_FN SPALL_FORCEINLINE bool spall_buffer_begin_args(SpallProfile *ctx, SpallBuffer *wb, const char *name, signed long name_len, const char *args, signed long args_len, double when, pthread_t tid, uint32_t pid) {
#ifdef SPALL_DEBUG
if (!ctx) return false;
if (!name) return false;
@@ -363,8 +364,8 @@ SPALL_FN SPALL_FORCEINLINE bool spall_buffer_begin_args(SpallProfile *ctx, Spall
if (ctx->is_json) {
char buf[1024];
int buf_len = snprintf(buf, sizeof(buf),
- "{\"ph\":\"B\",\"ts\":%f,\"pid\":%u,\"tid\":%u,\"name\":\"%.*s\",\"args\":\"%.*s\"},\n",
- when * ctx->timestamp_unit, pid, tid, (int)(uint8_t)name_len, name, (int)(uint8_t)args_len, args);
+ "{\"ph\":\"B\",\"ts\":%f,\"pid\":%u,\"tid\":%zu,\"name\":\"%.*s\",\"args\":\"%.*s\"},\n",
+ when * ctx->timestamp_unit, pid, (uintptr_t)tid, (int)(uint8_t)name_len, name, (int)(uint8_t)args_len, args);
if (buf_len <= 0) return false;
if (buf_len >= sizeof(buf)) return false;
if (!spall__buffer_write(ctx, wb, buf, buf_len)) return false;
@@ -381,7 +382,7 @@ SPALL_FN SPALL_FORCEINLINE bool spall_buffer_begin_args(SpallProfile *ctx, Spall
return true;
}
-SPALL_FN SPALL_FORCEINLINE bool spall_buffer_begin_ex(SpallProfile *ctx, SpallBuffer *wb, const char *name, signed long name_len, double when, uint32_t tid, uint32_t pid) {
+SPALL_FN SPALL_FORCEINLINE bool spall_buffer_begin_ex(SpallProfile *ctx, SpallBuffer *wb, const char *name, signed long name_len, double when, pthread_t tid, uint32_t pid) {
return spall_buffer_begin_args(ctx, wb, name, name_len, "", 0, when, tid, pid);
}
@@ -389,7 +390,7 @@ SPALL_FN bool spall_buffer_begin(SpallProfile *ctx, SpallBuffer *wb, const char
return spall_buffer_begin_args(ctx, wb, name, name_len, "", 0, when, 0, 0);
}
-SPALL_FN SPALL_FORCEINLINE bool spall_buffer_end_ex(SpallProfile *ctx, SpallBuffer *wb, double when, uint32_t tid, uint32_t pid) {
+SPALL_FN SPALL_FORCEINLINE bool spall_buffer_end_ex(SpallProfile *ctx, SpallBuffer *wb, double when, pthread_t tid, uint32_t pid) {
#ifdef SPALL_DEBUG
if (!ctx) return false;
if (!wb) return false;
@@ -398,8 +399,8 @@ SPALL_FN SPALL_FORCEINLINE bool spall_buffer_end_ex(SpallProfile *ctx, SpallBuff
if (ctx->is_json) {
char buf[512];
int buf_len = snprintf(buf, sizeof(buf),
- "{\"ph\":\"E\",\"ts\":%f,\"pid\":%u,\"tid\":%u},\n",
- when * ctx->timestamp_unit, pid, tid);
+ "{\"ph\":\"E\",\"ts\":%f,\"pid\":%u,\"tid\":%zu},\n",
+ when * ctx->timestamp_unit, pid, (uintptr_t)tid);
if (buf_len <= 0) return false;
if (buf_len >= sizeof(buf)) return false;
if (!spall__buffer_write(ctx, wb, buf, buf_len)) return false;
@@ -423,8 +424,8 @@ SPALL_FN SPALL_FORCEINLINE void spall__buffer_profile(SpallProfile *ctx, SpallBu
// precon: ctx->write
char temp_buffer_data[2048];
SpallBuffer temp_buffer = { temp_buffer_data, sizeof(temp_buffer_data) };
- if (!spall_buffer_begin_ex(ctx, &temp_buffer, name, name_len, spall_time_begin, (uint32_t)(uintptr_t)wb->data, 4222222222)) return;
- if (!spall_buffer_end_ex(ctx, &temp_buffer, spall_time_end, (uint32_t)(uintptr_t)wb->data, 4222222222)) return;
+ if (!spall_buffer_begin_ex(ctx, &temp_buffer, name, name_len, spall_time_begin, (pthread_t)wb->data, 4222222222)) return;
+ if (!spall_buffer_end_ex(ctx, &temp_buffer, spall_time_end, (pthread_t)wb->data, 4222222222)) return;
if (ctx->write) ctx->write(ctx, temp_buffer_data, temp_buffer.head);
}
diff --git a/main/spall_perf.h b/main/spall_perf.h
index f9775b76..dd1d14c9 100644
--- a/main/spall_perf.h
+++ b/main/spall_perf.h
@@ -64,7 +64,7 @@ static void spallperf__begin_plot(void* user_data, uint64_t nanos, const char* l
#if _WIN32
uint32_t tid = GetCurrentThreadId();
#else
- uint32_t tid = pthread_self();
+ pthread_t tid = pthread_self();
#endif
spall_buffer_begin_args(&ctx, &muh_buffer, label, strlen(label), extra, strlen(extra), nanos, tid, 0);
@@ -76,7 +76,7 @@ static void spallperf__end_plot(void* user_data, uint64_t nanos) {
#if _WIN32
uint32_t tid = GetCurrentThreadId();
#else
- uint32_t tid = pthread_self();
+ pthread_t tid = pthread_self();
#endif
spall_buffer_end_ex(&ctx, &muh_buffer, nanos, tid, 0);
Hello :D
The compile fails when building under musl libc:
pthread_selfdoes not returnuint32_tbutpthread_twhich internally is a pointer so i'm concerned with the use of 32bit value on 64bit platforms.I wrote a naive little patch to fix this:
after this the project compiles but fails to link:
At this point i gave up and I'm looking for help
Thanks :D