Commit: 34ce26e6a88de1f121d9e116f463d62f35663474
Parent: 7805c91014126f6be0c923847cd36cb107e342f6
Author: Randy Palamar
Date: Thu, 24 Oct 2024 22:00:17 -0600
ensure BEGIN_TIMED_BLOCK is actually inlined
Diffstat:
M | debug.h | | | 33 | ++++++++++++--------------------- |
1 file changed, 12 insertions(+), 21 deletions(-)
diff --git a/debug.h b/debug.h
@@ -25,26 +25,17 @@ typedef struct {
DebugRecord debug_records[];
-static u32
-begin_timed_block(u32 counter, char *file_name, char *function_name, i32 line_number)
-{
- DebugRecord *record = debug_records + counter;
- record->cycles -= __rdtsc();
- record->file_name = file_name;
- record->function_name = function_name;
- record->line_number = line_number;
- record->hit_count += 1;
- return counter;
-}
-
-static void
-end_timed_block(u32 counter)
-{
- DebugRecord *record = debug_records + counter;
- record->cycles += __rdtsc();
-}
-
-#define BEGIN_TIMED_BLOCK(...) u32 __counter = begin_timed_block(__COUNTER__, __FILE__, (char *)__FUNCTION__, __LINE__)
-#define END_TIMED_BLOCK(...) end_timed_block(__counter)
+#define BEGIN_TIMED_BLOCK(...) \
+ u32 __counter = __COUNTER__; \
+ { \
+ DebugRecord *record = debug_records + __counter; \
+ record->cycles -= __rdtsc(); \
+ record->file_name = __FILE__; \
+ record->function_name = (char *)__FUNCTION__; \
+ record->line_number = __LINE__; \
+ record->hit_count += 1; \
+ }
+
+#define END_TIMED_BLOCK(...) debug_records[__counter].cycles += __rdtsc();
#endif