From 69e5b65c5f7ed956a5223085a654e23e79080c48 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Fri, 10 Oct 2025 11:11:52 +0200 Subject: checkpoint --- linux_profile.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 linux_profile.h (limited to 'linux_profile.h') diff --git a/linux_profile.h b/linux_profile.h new file mode 100644 index 0000000..d36c859 --- /dev/null +++ b/linux_profile.h @@ -0,0 +1,45 @@ +/* date = June 17th 2025 3:06 pm */ + +#ifndef LINUX_PROFILE_H +#define LINUX_PROFILE_H + +#if HANDMADE_PROFILING + +#include "handmade_platform.h" + +#include "spall.h" +global_variable SpallProfile spall_ctx; +global_variable SpallBuffer spall_buffer; +global_variable char SpallNumberBuffer[9]; + +#define PROFILE_START_LABEL(Label) \ +spall_buffer_begin(&spall_ctx, &spall_buffer, Label, strlen(Label), LinuxGetWallClockMSec()) +#define PROFILE_START_LINE sprintf(SpallNumberBuffer, "%d", __LINE__); \ +PROFILE_START_LABEL(SpallNumberBuffer) +#define PROFILE_START_FUNCTION PROFILE_START_LABEL(__FUNCTION__) +#define PROFILE_START PROFILE_START_LINE +#define PROFILE_END spall_buffer_end(&spall_ctx, &spall_buffer, LinuxGetWallClockMSec()); + +typedef struct timespec platform_get_wall_clock(void); + +global_variable platform_get_wall_clock *PlatformGetWallClock; +timespec LinuxGetWallClock(void); + +internal +r64 LinuxGetWallClockMSec(void) +{ + r64 Result = 0; + timespec Spec = PlatformGetWallClock(); + Result = (((r64)Spec.tv_sec) * 1000000) + (((r64)Spec.tv_nsec) / 1000); + return Result; +} + +#else +#define PROFILE_START +#define PROFILE_START_LABEL(Name) +#define PROFILE_START_LINE +#define PROFILE_START_FUNCTION +#define PROFILE_END +#endif + +#endif //LINUX_PROFILE_H -- cgit v1.2.3-70-g09d2