From 4f1c1073cbc3360bedcf31dbeb6bd701760b9492 Mon Sep 17 00:00:00 2001 From: doylet Date: Wed, 24 Sep 2025 19:32:27 +1000 Subject: [PATCH] Profiler cleanup, misc fixes --- Single_Header/dn_single_header.cpp | 183 ++++++++++++++++++----------- Single_Header/dn_single_header.h | 109 ++++++++--------- Source/External/stb_sprintf.h | 3 +- Source/Extra/dn_net2_curl.cpp | 6 +- Source/Extra/dn_net2_curl.h | 1 + 5 files changed, 169 insertions(+), 133 deletions(-) diff --git a/Single_Header/dn_single_header.cpp b/Single_Header/dn_single_header.cpp index 024c5aa..29e5c04 100644 --- a/Single_Header/dn_single_header.cpp +++ b/Single_Header/dn_single_header.cpp @@ -1,4 +1,4 @@ -// Generated by the DN single header generator 2025-09-13 19:09:12 +// Generated by the DN single header generator 2025-09-24 19:31:27 #define DN_BASE_INC_CPP @@ -767,6 +767,13 @@ DN_API void DN_ASanUnpoisonMemoryRegion(void const volatile *ptr, DN_USize size) (void)size; #endif } + +DN_API DN_F32 DN_EpsilonClampF32(DN_F32 value, DN_F32 target, DN_F32 epsilon) +{ + DN_F32 delta = DN_Abs(target - value); + DN_F32 result = (delta < epsilon) ? target : value; + return result; +} // DN: Single header generator inlined this file => #include "Base/dn_base_containers.cpp" #define DN_CONTAINERS_CPP @@ -9793,11 +9800,7 @@ DN_API void DN_Core_Init(DN_Core *core, DN_CoreOnInit on_init) DN_Assert(g_dn_os_core_); g_dn_core = core; - // NOTE Initialise fields ////////////////////////////////////////////////////////////////////// - #if !defined(DN_NO_PROFILER) - core->profiler = &core->profiler_default_instance; - #endif - + // NOTE Initialise fields #if defined(DN_LEAK_TRACKING) // NOTE: Setup the allocation table with allocation tracking turned off on // the arena we're using to initialise the table. @@ -9832,10 +9835,6 @@ DN_API void DN_Core_Init(DN_Core *core, DN_CoreOnInit on_init) DN_Str8Builder_AppendRef(&builder, DN_STR8(" Allocation leak tracing\n")); #endif - #if !defined(DN_NO_PROFILER) - DN_Str8Builder_AppendRef(&builder, DN_STR8(" TSC profiler available\n")); - #endif - #if defined(DN_PLATFORM_EMSCRIPTEN) || defined(DN_PLATFORM_POSIX) DN_POSIXCore *posix = DN_CAST(DN_POSIXCore *)g_dn_os_core_->platform_context; DN_Str8Builder_AppendF(&builder, " Clock GetTime: %S\n", posix->clock_monotonic_raw ? DN_STR8("CLOCK_MONOTONIC_RAW") : DN_STR8("CLOCK_MONOTONIC")); @@ -9878,19 +9877,12 @@ DN_API void DN_Core_BeginFrame() { DN_AtomicSetValue64(&g_dn_os_core_->mem_allocs_frame, 0); } - -#if !defined(DN_NO_PROFILER) -DN_API void DN_Core_SetProfiler(DN_Profiler *profiler) -{ - if (profiler) - g_dn_core->profiler = profiler; -} -#endif // DN: Single header generator inlined this file => #include "Core/dn_core_debug.cpp" #define DN_CORE_DEBUG_CPP // DN: Single header generator commented out this header => #include "../dn_base_inc.h" // DN: Single header generator commented out this header => #include "../dn_os_inc.h" +// DN: Single header generator commented out this header => #include "../dn_core_inc.h" DN_API DN_StackTraceWalkResult DN_StackTrace_Walk(DN_Arena *arena, uint16_t limit) { @@ -10238,91 +10230,135 @@ DN_API void DN_DBGDumpLeaks() } #endif // DN_LEAK_TRACKING -#if !defined(DN_NO_PROFILER) -// NOTE: DN_Profiler /////////////////////////////////////////////////////////////////////////////// -DN_API DN_ProfilerZoneScope::DN_ProfilerZoneScope(DN_Str8 name, uint16_t anchor_index) +// NOTE: DN_Profiler +DN_API DN_Profiler DN_Profiler_Init(DN_ProfilerAnchor *anchors, DN_USize count, DN_USize anchors_per_frame, DN_ProfilerTSC tsc, DN_U64 tsc_frequency) { - zone = DN_Profiler_BeginZoneAtIndex(name, anchor_index); -} - -DN_API DN_ProfilerZoneScope::~DN_ProfilerZoneScope() -{ - DN_Profiler_EndZone(zone); -} - -DN_API DN_ProfilerAnchor *DN_Profiler_ReadBuffer() -{ - uint8_t mask = DN_ArrayCountU(g_dn_core->profiler->anchors) - 1; - DN_ProfilerAnchor *result = g_dn_core->profiler->anchors[(g_dn_core->profiler->active_anchor_buffer - 1) & mask]; + DN_Profiler result = {}; + result.anchors = anchors; + result.anchors_count = count; + result.anchors_per_frame = anchors_per_frame; + result.tsc = tsc; + result.tsc_frequency = tsc_frequency; return result; } -DN_API DN_ProfilerAnchor *DN_Profiler_WriteBuffer() +DN_API DN_USize DN_Profiler_FrameCount(DN_Profiler const *profiler) { - uint8_t mask = DN_ArrayCountU(g_dn_core->profiler->anchors) - 1; - DN_ProfilerAnchor *result = g_dn_core->profiler->anchors[(g_dn_core->profiler->active_anchor_buffer + 0) & mask]; + DN_USize result = profiler->anchors_count / profiler->anchors_per_frame; return result; } -DN_API DN_ProfilerZone DN_Profiler_BeginZoneAtIndex(DN_Str8 name, uint16_t anchor_index) +DN_API DN_ProfilerAnchorArray DN_Profiler_FrameAnchorsFromIndex(DN_Profiler *profiler, DN_USize frame_index) { - DN_ProfilerAnchor *anchor = DN_Profiler_WriteBuffer() + anchor_index; + DN_ProfilerAnchorArray result = {}; + DN_USize anchor_offset = frame_index * profiler->anchors_per_frame; + result.data = profiler->anchors + anchor_offset; + result.count = profiler->anchors_per_frame; + return result; +} + +DN_API DN_ProfilerAnchorArray DN_Profiler_FrameAnchors(DN_Profiler *profiler) +{ + DN_ProfilerAnchorArray result = DN_Profiler_FrameAnchorsFromIndex(profiler, profiler->frame_index); + return result; +} + +DN_API DN_ProfilerZone DN_Profiler_BeginZone(DN_Profiler *profiler, DN_Str8 name, DN_U16 anchor_index) +{ + DN_ProfilerZone result = {}; + if (profiler->paused) + return result; + + DN_Assert(anchor_index < profiler->anchors_per_frame); + DN_ProfilerAnchor *anchor = DN_Profiler_FrameAnchors(profiler).data + anchor_index; + anchor->name = name; + // TODO: We need per-thread-local-storage profiler so that we can use these apis // across threads. For now, we let them overwrite each other but this is not tenable. #if 0 if (DN_Str8_HasData(anchor->name) && anchor->name != name) DN_AssertF(name == anchor->name, "Potentially overwriting a zone by accident? Anchor is '%.*s', name is '%.*s'", DN_STR_FMT(anchor->name), DN_STR_FMT(name)); #endif - anchor->name = name; - DN_ProfilerZone result = {}; - result.begin_tsc = DN_CPUGetTSC(); + + if (profiler->tsc == DN_ProfilerTSC_RDTSC) + result.begin_tsc = DN_CPUGetTSC(); + else + result.begin_tsc = DN_OS_PerfCounterNow(); result.anchor_index = anchor_index; - result.parent_zone = g_dn_core->profiler->parent_zone; + result.parent_zone = profiler->parent_zone; result.elapsed_tsc_at_zone_start = anchor->tsc_inclusive; - g_dn_core->profiler->parent_zone = anchor_index; + profiler->parent_zone = anchor_index; return result; } -DN_API void DN_Profiler_EndZone(DN_ProfilerZone zone) +DN_API void DN_Profiler_EndZone(DN_Profiler *profiler, DN_ProfilerZone zone) { - uint64_t elapsed_tsc = DN_CPUGetTSC() - zone.begin_tsc; - DN_ProfilerAnchor *anchor_buffer = DN_Profiler_WriteBuffer(); - DN_ProfilerAnchor *anchor = anchor_buffer + zone.anchor_index; + if (profiler->paused) + return; + + DN_Assert(zone.anchor_index < profiler->anchors_per_frame); + DN_Assert(zone.parent_zone < profiler->anchors_per_frame); + + DN_ProfilerAnchorArray array = DN_Profiler_FrameAnchors(profiler); + DN_ProfilerAnchor *anchor = array.data + zone.anchor_index; + DN_U64 tsc_now = profiler->tsc == DN_ProfilerTSC_RDTSC ? DN_CPUGetTSC() : DN_OS_PerfCounterNow(); + DN_U64 elapsed_tsc = tsc_now - zone.begin_tsc; anchor->hit_count++; - anchor->tsc_inclusive = zone.elapsed_tsc_at_zone_start + elapsed_tsc; - anchor->tsc_exclusive += elapsed_tsc; + anchor->tsc_inclusive = zone.elapsed_tsc_at_zone_start + elapsed_tsc; + anchor->tsc_exclusive += elapsed_tsc; - DN_ProfilerAnchor *parent_anchor = anchor_buffer + zone.parent_zone; - parent_anchor->tsc_exclusive -= elapsed_tsc; - g_dn_core->profiler->parent_zone = zone.parent_zone; + if (zone.parent_zone != zone.anchor_index) { + DN_ProfilerAnchor *parent_anchor = array.data + zone.parent_zone; + parent_anchor->tsc_exclusive -= elapsed_tsc; + } + profiler->parent_zone = zone.parent_zone; } -DN_API void DN_Profiler_SwapAnchorBuffer() +DN_API void DN_Profiler_NewFrame(DN_Profiler *profiler) { - g_dn_core->profiler->active_anchor_buffer++; - g_dn_core->profiler->parent_zone = 0; - DN_ProfilerAnchor *anchors = DN_Profiler_WriteBuffer(); - DN_Memset(anchors, - 0, - DN_ArrayCountU(g_dn_core->profiler->anchors[0]) * sizeof(g_dn_core->profiler->anchors[0][0])); + if (profiler->paused) + return; + + // NOTE: End the frame's zone + DN_Profiler_EndZone(profiler, profiler->frame_zone); + DN_ProfilerAnchorArray old_frame_anchors = DN_Profiler_FrameAnchors(profiler); + DN_ProfilerAnchor old_frame_anchor = old_frame_anchors.data[0]; + profiler->frame_avg_tsc = (profiler->frame_avg_tsc + old_frame_anchor.tsc_inclusive) / 2.f; + + // NOTE: Bump to the next frame + DN_USize frame_count = profiler->anchors_count / profiler->anchors_per_frame; + profiler->frame_index = (profiler->frame_index + 1) % frame_count; + + // NOTE: Zero out the anchors + DN_ProfilerAnchorArray next_anchors = DN_Profiler_FrameAnchors(profiler); + DN_Memset(next_anchors.data, 0, sizeof(*profiler->anchors) * next_anchors.count); + + // NOTE: Start the frame's zone + profiler->frame_zone = DN_Profiler_BeginZone(profiler, DN_STR8("Profiler Frame"), 0); } -DN_API void DN_Profiler_Dump(uint64_t tsc_per_second) +DN_API void DN_Profiler_Dump(DN_Profiler *profiler) { - DN_ProfilerAnchor *anchors = DN_Profiler_ReadBuffer(); - for (size_t anchor_index = 1; anchor_index < DN_PROFILER_ANCHOR_BUFFER_SIZE; anchor_index++) { - DN_ProfilerAnchor const *anchor = anchors + anchor_index; + if (profiler->frame_index == 0) + return; + + DN_USize frame_index = profiler->frame_index - 1; + DN_Assert(profiler->frame_index < profiler->anchors_per_frame); + + DN_ProfilerAnchor *anchors = profiler->anchors + (frame_index * profiler->anchors_per_frame); + for (DN_USize index = 1; index < profiler->anchors_per_frame; index++) { + DN_ProfilerAnchor const *anchor = anchors + index; if (!anchor->hit_count) continue; - uint64_t tsc_exclusive = anchor->tsc_exclusive; - uint64_t tsc_inclusive = anchor->tsc_inclusive; - DN_F64 tsc_exclusive_milliseconds = tsc_exclusive * 1000 / DN_CAST(DN_F64) tsc_per_second; + DN_U64 tsc_exclusive = anchor->tsc_exclusive; + DN_U64 tsc_inclusive = anchor->tsc_inclusive; + DN_F64 tsc_exclusive_milliseconds = tsc_exclusive * 1000 / DN_CAST(DN_F64) profiler->tsc_frequency; if (tsc_exclusive == tsc_inclusive) { DN_OS_PrintOutLnF("%.*s[%u]: %.1fms", DN_STR_FMT(anchor->name), anchor->hit_count, tsc_exclusive_milliseconds); } else { - DN_F64 tsc_inclusive_milliseconds = tsc_inclusive * 1000 / DN_CAST(DN_F64) tsc_per_second; + DN_F64 tsc_inclusive_milliseconds = tsc_inclusive * 1000 / DN_CAST(DN_F64) profiler->tsc_frequency; DN_OS_PrintOutLnF("%.*s[%u]: %.1f/%.1fms", DN_STR_FMT(anchor->name), anchor->hit_count, @@ -10331,8 +10367,18 @@ DN_API void DN_Profiler_Dump(uint64_t tsc_per_second) } } } -#endif // !defined(DN_NO_PROFILER) +DN_API DN_F64 DN_Profiler_SecFromTSC(DN_Profiler *profiler, DN_U64 duration_tsc) +{ + DN_F64 result = DN_CAST(DN_F64)duration_tsc / profiler->tsc_frequency; + return result; +} + +DN_API DN_F64 DN_Profiler_MsFromTSC(DN_Profiler *profiler, DN_U64 duration_tsc) +{ + DN_F64 result = DN_CAST(DN_F64)duration_tsc / profiler->tsc_frequency * 1000.0; + return result; +} // DN: Single header generator inlined this file => #include "Core/dn_core_demo.cpp" /* //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -11915,7 +11961,6 @@ DN_API DN_Rect DN_RectCut_Cut (DN_RectCut rec DN_API DN_RaycastLineIntersectV2Result DN_Raycast_LineIntersectV2(DN_V2F32 origin_a, DN_V2F32 dir_a, DN_V2F32 origin_b, DN_V2F32 dir_b); DN_API DN_V2F32 DN_Lerp_V2F32 (DN_V2F32 a, DN_F32 t, DN_V2F32 b); DN_API DN_F32 DN_Lerp_F32 (DN_F32 a, DN_F32 t, DN_F32 b); - #endif // !defined(DN_MATH_H) DN_API bool operator==(DN_V2I32 lhs, DN_V2I32 rhs) diff --git a/Single_Header/dn_single_header.h b/Single_Header/dn_single_header.h index 0dc924a..b23b362 100644 --- a/Single_Header/dn_single_header.h +++ b/Single_Header/dn_single_header.h @@ -1,4 +1,4 @@ -// Generated by the DN single header generator 2025-09-13 19:09:12 +// Generated by the DN single header generator 2025-09-24 19:31:27 #if !defined(DN_BASE_INC_H) #define DN_BASE_INC_H @@ -707,6 +707,9 @@ DN_API DN_U64 DN_SaturateCastIntToU64 (int val); DN_API void DN_ASanPoisonMemoryRegion (void const volatile *ptr, DN_USize size); DN_API void DN_ASanUnpoisonMemoryRegion(void const volatile *ptr, DN_USize size); + +DN_API DN_F32 DN_EpsilonClampF32 (DN_F32 value, DN_F32 target, DN_F32 epsilon); + #endif // !defined(DN_BASE_H) // DN: Single header generator inlined this file => #include "Base/dn_base_os.h" #if !defined(DN_BASE_OS_H) @@ -1175,6 +1178,7 @@ DN_GCC_WARNING_DISABLE(-Wunused-function) // - Adding STBSP__ASAN to STBSP__PUBLICDEC so that MSVC's ASAN does not trigger (https://github.com/nothings/stb/pull/1350) // - Adding __attribute__((no_sanitize("undefined"))) to STBSP__ASAN for CLANG so that UBSAN does not trigger (https://github.com/nothings/stb/pull/1477) // - Adding '%S' for DN_Str8 +// - Using defined(__wasm64__) to correctly assign stbsp__uintptr to stbsp__uint64 for a 64bit WASM target. // stb_sprintf - v1.10 - public domain snprintf() implementation // originally by Jeff Roberts / RAD Game Tools, 2015/10/20 @@ -1412,7 +1416,7 @@ STBSP__PUBLICDEC void STB_SPRINTF_DECORATE(set_separators)(char comma, char peri #define stbsp__uint16 unsigned short #ifndef stbsp__uintptr -#if defined(__ppc64__) || defined(__powerpc64__) || defined(__aarch64__) || defined(_M_X64) || defined(__x86_64__) || defined(__x86_64) || defined(__s390x__) +#if defined(__ppc64__) || defined(__powerpc64__) || defined(__aarch64__) || defined(_M_X64) || defined(__x86_64__) || defined(__x86_64) || defined(__s390x__) || defined(__wasm64__) #define stbsp__uintptr stbsp__uint64 #else #define stbsp__uintptr stbsp__uint32 @@ -5796,7 +5800,7 @@ struct DN_OSCore DN_CPUReport cpu_report; DN_OSTLS tls; // Thread local storage state for the main thread. - // NOTE: Logging /////////////////////////////////////////////////////////////////////////////// + // NOTE: Logging DN_LOGEmitFromTypeFVFunc * log_callback; // Set this pointer to override the logging routine void * log_user_data; // User pointer passed into 'log_callback' bool log_to_file; // Output logs to file as well as standard out @@ -5804,12 +5808,12 @@ struct DN_OSCore DN_TicketMutex log_file_mutex; // Is locked when instantiating the log_file for the first time bool log_no_colour; // Disable colours in the logging output - // NOTE: OS ////////////////////////////////////////////////////////////////////////////////////// + // NOTE: OS DN_U32 logical_processor_count; DN_U32 page_size; DN_U32 alloc_granularity; - // NOTE: Memory //////////////////////////////////////////////////////////////////////////////// + // NOTE: Memory // Total OS mem allocs in lifetime of program (e.g. malloc, VirtualAlloc, HeapAlloc ...). This // only includes allocations routed through the library such as the growing nature of arenas or // using the memory allocation routines in the library like DN_OS_MemCommit and so forth. @@ -6176,8 +6180,7 @@ DN_API DN_Slice DN_Str8Builder_BuildSliceFromTLS (DN_Str8Bu // DN: Single header generator commented out this header => #include "../dn_base_inc.h" -// NOTE: DN_StackTrace ///////////////////////////////////////////////////////////////////////////// -// NOTE: DN_Debug ////////////////////////////////////////////////////////////////////////////////// +// NOTE: DN_Debug enum DN_DebugAllocFlag { DN_DebugAllocFlag_Freed = 1 << 0, @@ -6199,12 +6202,7 @@ static_assert(sizeof(DN_DebugAlloc) == 64 || sizeof(DN_DebugAlloc) == 32, // NOT "memory tracking can get expensive. Enforce that there is no " "unexpected padding."); -// NOTE: DN_Profiler /////////////////////////////////////////////////////////////////////////////// -#if !defined(DN_NO_PROFILER) -#if !defined(DN_PROFILER_ANCHOR_BUFFER_SIZE) - #define DN_PROFILER_ANCHOR_BUFFER_SIZE 256 -#endif - +// NOTE: DN_Profiler struct DN_ProfilerAnchor { // Inclusive refers to the time spent to complete the function call @@ -6228,47 +6226,50 @@ struct DN_ProfilerZone DN_U64 elapsed_tsc_at_zone_start; }; -#if defined(__cplusplus) -struct DN_ProfilerZoneScope +struct DN_ProfilerAnchorArray { - DN_ProfilerZoneScope(DN_Str8 name, DN_U16 anchor_index); - ~DN_ProfilerZoneScope(); - DN_ProfilerZone zone; + DN_ProfilerAnchor *data; + DN_USize count; }; -#define DN_Profiler_ZoneScopeAtIndex(name, anchor_index) auto DN_UniqueName(profile_zone_) = DN_ProfilerZoneScope(DN_STR8(name), anchor_index) -#define DN_Profiler_ZoneScope(name) DN_Profiler_ZoneScopeAtIndex(name, __COUNTER__ + 1) -#endif - -#define DN_Profiler_ZoneBlockIndex(name, index) \ - for (DN_ProfilerZone DN_UniqueName(profile_zone__) = DN_Profiler_BeginZoneAtIndex(name, index), DN_UniqueName(dummy__) = {}; \ - DN_UniqueName(dummy__).begin_tsc == 0; \ - DN_Profiler_EndZone(DN_UniqueName(profile_zone__)), DN_UniqueName(dummy__).begin_tsc = 1) - -#define DN_Profiler_ZoneBlock(name) DN_Profiler_ZoneBlockIndex(DN_STR8(name), __COUNTER__ + 1) - -enum DN_ProfilerAnchorBuffer +enum DN_ProfilerTSC { - DN_ProfilerAnchorBuffer_Back, - DN_ProfilerAnchorBuffer_Front, + DN_ProfilerTSC_RDTSC, + DN_ProfilerTSC_OSPerformanceCounter, }; struct DN_Profiler { - DN_ProfilerAnchor anchors[2][DN_PROFILER_ANCHOR_BUFFER_SIZE]; - DN_U8 active_anchor_buffer; - DN_U16 parent_zone; + DN_USize frame_index; + DN_ProfilerAnchor *anchors; + DN_USize anchors_count; + DN_USize anchors_per_frame; + DN_U16 parent_zone; + bool paused; + DN_ProfilerTSC tsc; + DN_U64 tsc_frequency; + DN_ProfilerZone frame_zone; + DN_F64 frame_avg_tsc; }; -DN_API DN_ProfilerAnchor * DN_Profiler_ReadBuffer (); -DN_API DN_ProfilerAnchor * DN_Profiler_WriteBuffer (); -#define DN_Profiler_BeginZone(name) DN_Profiler_BeginZoneAtIndex(DN_STR8(name), __COUNTER__ + 1) -DN_API DN_ProfilerZone DN_Profiler_BeginZoneAtIndex (DN_Str8 name, DN_U16 anchor_index); -DN_API void DN_Profiler_EndZone (DN_ProfilerZone zone); -DN_API DN_ProfilerAnchor * DN_Profiler_AnchorBuffer (DN_ProfilerAnchorBuffer buffer); -DN_API void DN_Profiler_SwapAnchorBuffer (); -DN_API void DN_Profiler_Dump (DN_U64 tsc_per_second); -#endif // !defined(DN_NO_PROFILER) +#define DN_Profiler_ZoneLoop(prof, name, index) \ + DN_ProfilerZone DN_UniqueName(zone_) = DN_Profiler_BeginZone(prof, DN_STR8(name), index), DN_UniqueName(dummy_) = {}; \ + DN_UniqueName(dummy_).begin_tsc == 0; \ + DN_Profiler_EndZone(prof, DN_UniqueName(zone_)), DN_UniqueName(dummy_).begin_tsc = 1 + +#define DN_Profiler_ZoneLoopAuto(prof, name) DN_Profiler_ZoneLoop(prof, name, __COUNTER__ + 1) + +DN_API DN_Profiler DN_Profiler_Init (DN_ProfilerAnchor *anchors, DN_USize count, DN_USize anchors_per_frame, DN_ProfilerTSC tsc, DN_U64 tsc_frequency); +DN_API DN_ProfilerZone DN_Profiler_BeginZone (DN_Profiler *profiler, DN_Str8 name, DN_U16 anchor_index); +#define DN_Profiler_BeginZoneAuto(prof, name) DN_Profiler_BeginZone(prof, DN_STR8(name), __COUNTER__ + 1) +DN_API void DN_Profiler_EndZone (DN_Profiler *profiler, DN_ProfilerZone zone); +DN_API DN_USize DN_Profiler_FrameCount (DN_Profiler const *profiler); +DN_API DN_ProfilerAnchorArray DN_Profiler_FrameAnchorsFromIndex (DN_Profiler *profiler, DN_USize frame_index); +DN_API DN_ProfilerAnchorArray DN_Profiler_FrameAnchors (DN_Profiler *profiler); +DN_API void DN_Profiler_NewFrame (DN_Profiler *profiler); +DN_API void DN_Profiler_Dump (DN_Profiler *profiler); +DN_API DN_F64 DN_Profiler_SecFromTSC (DN_Profiler *profiler, DN_U64 duration_tsc); +DN_API DN_F64 DN_Profiler_MsFromTSC (DN_Profiler *profiler, DN_U64 duration_tsc); #if defined(DN_LEAK_TRACKING) @@ -6285,24 +6286,16 @@ DN_API void DN_DBGDumpLeaks (); #if !defined(DN_CORE_H) #define DN_CORE_H -// NOTE: DN_Core /////////////////////////////////////////////////////////////////////////////////// -// Book-keeping data for the library and allow customisation of certain features -// provided. +// NOTE: DN_Core struct DN_Core { - // NOTE: Leak Tracing ////////////////////////////////////////////////////////////////////////// + // NOTE: Leak Tracing #if defined(DN_LEAK_TRACKING) DN_DSMap alloc_table; DN_TicketMutex alloc_table_mutex; DN_Arena alloc_table_arena; #endif DN_U64 alloc_table_bytes_allocated_for_stack_traces; - - // NOTE: Profiler ////////////////////////////////////////////////////////////////////////////// - #if !defined(DN_NO_PROFILER) - DN_Profiler * profiler; - DN_Profiler profiler_default_instance; - #endif }; enum DN_CoreOnInit @@ -6313,11 +6306,8 @@ enum DN_CoreOnInit DN_CoreOnInit_LogAllFeatures = DN_CoreOnInit_LogLibFeatures | DN_CoreOnInit_LogCPUFeatures, }; -DN_API void DN_Core_Init (DN_Core *core, DN_CoreOnInit on_init); -DN_API void DN_Core_BeginFrame (); -#if !defined(DN_NO_PROFILER) -DN_API void DN_Core_SetProfiler (DN_Profiler *profiler); -#endif +DN_API void DN_Core_Init (DN_Core *core, DN_CoreOnInit on_init); +DN_API void DN_Core_BeginFrame(); #endif // !defined(DN_CORE_H) #endif // !defined(DN_CORE_INC_H) @@ -6692,7 +6682,6 @@ DN_API DN_Rect DN_RectCut_Cut (DN_RectCut rec DN_API DN_RaycastLineIntersectV2Result DN_Raycast_LineIntersectV2(DN_V2F32 origin_a, DN_V2F32 dir_a, DN_V2F32 origin_b, DN_V2F32 dir_b); DN_API DN_V2F32 DN_Lerp_V2F32 (DN_V2F32 a, DN_F32 t, DN_V2F32 b); DN_API DN_F32 DN_Lerp_F32 (DN_F32 a, DN_F32 t, DN_F32 b); - #endif // !defined(DN_MATH_H) #if !defined(DN_ASYNC_H) #define DN_ASYNC_H diff --git a/Source/External/stb_sprintf.h b/Source/External/stb_sprintf.h index e4b0323..94610c7 100644 --- a/Source/External/stb_sprintf.h +++ b/Source/External/stb_sprintf.h @@ -2,6 +2,7 @@ // - Adding STBSP__ASAN to STBSP__PUBLICDEC so that MSVC's ASAN does not trigger (https://github.com/nothings/stb/pull/1350) // - Adding __attribute__((no_sanitize("undefined"))) to STBSP__ASAN for CLANG so that UBSAN does not trigger (https://github.com/nothings/stb/pull/1477) // - Adding '%S' for DN_Str8 +// - Using defined(__wasm64__) to correctly assign stbsp__uintptr to stbsp__uint64 for a 64bit WASM target. // stb_sprintf - v1.10 - public domain snprintf() implementation // originally by Jeff Roberts / RAD Game Tools, 2015/10/20 @@ -239,7 +240,7 @@ STBSP__PUBLICDEC void STB_SPRINTF_DECORATE(set_separators)(char comma, char peri #define stbsp__uint16 unsigned short #ifndef stbsp__uintptr -#if defined(__ppc64__) || defined(__powerpc64__) || defined(__aarch64__) || defined(_M_X64) || defined(__x86_64__) || defined(__x86_64) || defined(__s390x__) +#if defined(__ppc64__) || defined(__powerpc64__) || defined(__aarch64__) || defined(_M_X64) || defined(__x86_64__) || defined(__x86_64) || defined(__s390x__) || defined(__wasm64__) #define stbsp__uintptr stbsp__uint64 #else #define stbsp__uintptr stbsp__uint32 diff --git a/Source/Extra/dn_net2_curl.cpp b/Source/Extra/dn_net2_curl.cpp index 0e5c7ea..76b623c 100644 --- a/Source/Extra/dn_net2_curl.cpp +++ b/Source/Extra/dn_net2_curl.cpp @@ -482,9 +482,9 @@ static DN_NET2Request DN_NET2_DoRequest_(DN_NET2Core *net, DN_Str8 url, DN_Str8 if (!request->arena.curr) request->arena = DN_Arena_FromVMem(DN_Megabytes(1), DN_Kilobytes(1), DN_ArenaFlags_Nil); - request->type = type; - request->gen = DN_Max(request->gen + 1, 1); - request->url = DN_Str8_FromStr8(&request->arena, url); + request->type = type; + request->gen = DN_Max(request->gen + 1, 1); + request->url = DN_Str8_FromStr8(&request->arena, url); request->method = DN_Str8_FromStr8(&request->arena, method); if (args) { diff --git a/Source/Extra/dn_net2_curl.h b/Source/Extra/dn_net2_curl.h index f7eaf44..2644074 100644 --- a/Source/Extra/dn_net2_curl.h +++ b/Source/Extra/dn_net2_curl.h @@ -67,6 +67,7 @@ struct DN_NET2ResponseInternal struct DN_NET2Request { DN_U64 handle; + DN_U64 gen; }; struct DN_NET2Response