summaryrefslogtreecommitdiff
path: root/externals/microprofile/microprofile.h
diff options
context:
space:
mode:
Diffstat (limited to 'externals/microprofile/microprofile.h')
-rw-r--r--externals/microprofile/microprofile.h59
1 files changed, 39 insertions, 20 deletions
diff --git a/externals/microprofile/microprofile.h b/externals/microprofile/microprofile.h
index 0c0d0a4d3..85d5bd5de 100644
--- a/externals/microprofile/microprofile.h
+++ b/externals/microprofile/microprofile.h
@@ -152,9 +152,11 @@ typedef uint16_t MicroProfileGroupId;
152 152
153#include <stdint.h> 153#include <stdint.h>
154#include <string.h> 154#include <string.h>
155#include <thread> 155#include <algorithm>
156#include <mutex> 156#include <array>
157#include <atomic> 157#include <atomic>
158#include <mutex>
159#include <thread>
158 160
159#ifndef MICROPROFILE_API 161#ifndef MICROPROFILE_API
160#define MICROPROFILE_API 162#define MICROPROFILE_API
@@ -605,28 +607,45 @@ struct MicroProfileFrameState
605 607
606struct MicroProfileThreadLog 608struct MicroProfileThreadLog
607{ 609{
608 MicroProfileLogEntry Log[MICROPROFILE_BUFFER_SIZE]; 610 std::array<MicroProfileLogEntry, MICROPROFILE_BUFFER_SIZE> Log{};
609 611
610 std::atomic<uint32_t> nPut; 612 std::atomic<uint32_t> nPut{0};
611 std::atomic<uint32_t> nGet; 613 std::atomic<uint32_t> nGet{0};
612 uint32_t nActive; 614 uint32_t nActive = 0;
613 uint32_t nGpu; 615 uint32_t nGpu = 0;
614 ThreadIdType nThreadId; 616 ThreadIdType nThreadId{};
615 617
616 uint32_t nStack[MICROPROFILE_STACK_MAX]; 618 std::array<uint32_t, MICROPROFILE_STACK_MAX> nStack{};
617 int64_t nChildTickStack[MICROPROFILE_STACK_MAX]; 619 std::array<int64_t, MICROPROFILE_STACK_MAX> nChildTickStack{};
618 uint32_t nStackPos; 620 uint32_t nStackPos = 0;
619 621
620 622
621 uint8_t nGroupStackPos[MICROPROFILE_MAX_GROUPS]; 623 std::array<uint8_t, MICROPROFILE_MAX_GROUPS> nGroupStackPos{};
622 int64_t nGroupTicks[MICROPROFILE_MAX_GROUPS]; 624 std::array<int64_t, MICROPROFILE_MAX_GROUPS> nGroupTicks{};
623 int64_t nAggregateGroupTicks[MICROPROFILE_MAX_GROUPS]; 625 std::array<int64_t, MICROPROFILE_MAX_GROUPS> nAggregateGroupTicks{};
624 enum 626 enum
625 { 627 {
626 THREAD_MAX_LEN = 64, 628 THREAD_MAX_LEN = 64,
627 }; 629 };
628 char ThreadName[64]; 630 char ThreadName[64]{};
629 int nFreeListNext; 631 int nFreeListNext = 0;
632
633 void Reset() {
634 Log.fill({});
635 nPut = 0;
636 nGet = 0;
637 nActive = 0;
638 nGpu = 0;
639 nThreadId = {};
640 nStack.fill(0);
641 nChildTickStack.fill(0);
642 nStackPos = 0;
643 nGroupStackPos.fill(0);
644 nGroupTicks.fill(0);
645 nAggregateGroupTicks.fill(0);
646 std::fill(std::begin(ThreadName), std::end(ThreadName), '\0');
647 nFreeListNext = 0;
648 }
630}; 649};
631 650
632#if MICROPROFILE_GPU_TIMERS_D3D11 651#if MICROPROFILE_GPU_TIMERS_D3D11
@@ -1018,7 +1037,7 @@ static void MicroProfileCreateThreadLogKey()
1018#else 1037#else
1019MP_THREAD_LOCAL MicroProfileThreadLog* g_MicroProfileThreadLog = 0; 1038MP_THREAD_LOCAL MicroProfileThreadLog* g_MicroProfileThreadLog = 0;
1020#endif 1039#endif
1021static bool g_bUseLock = false; /// This is used because windows does not support using mutexes under dll init(which is where global initialization is handled) 1040static std::atomic<bool> g_bUseLock{false}; /// This is used because windows does not support using mutexes under dll init(which is where global initialization is handled)
1022 1041
1023 1042
1024MICROPROFILE_DEFINE(g_MicroProfileFlip, "MicroProfile", "MicroProfileFlip", 0x3355ee); 1043MICROPROFILE_DEFINE(g_MicroProfileFlip, "MicroProfile", "MicroProfileFlip", 0x3355ee);
@@ -1151,6 +1170,7 @@ MicroProfileThreadLog* MicroProfileCreateThreadLog(const char* pName)
1151 MP_ASSERT(pLog->nPut.load() == 0); 1170 MP_ASSERT(pLog->nPut.load() == 0);
1152 MP_ASSERT(pLog->nGet.load() == 0); 1171 MP_ASSERT(pLog->nGet.load() == 0);
1153 S.nFreeListHead = S.Pool[S.nFreeListHead]->nFreeListNext; 1172 S.nFreeListHead = S.Pool[S.nFreeListHead]->nFreeListNext;
1173 pLog->Reset();
1154 } 1174 }
1155 else 1175 else
1156 { 1176 {
@@ -1158,7 +1178,6 @@ MicroProfileThreadLog* MicroProfileCreateThreadLog(const char* pName)
1158 S.nMemUsage += sizeof(MicroProfileThreadLog); 1178 S.nMemUsage += sizeof(MicroProfileThreadLog);
1159 S.Pool[S.nNumLogs++] = pLog; 1179 S.Pool[S.nNumLogs++] = pLog;
1160 } 1180 }
1161 memset(pLog, 0, sizeof(*pLog));
1162 int len = (int)strlen(pName); 1181 int len = (int)strlen(pName);
1163 int maxlen = sizeof(pLog->ThreadName)-1; 1182 int maxlen = sizeof(pLog->ThreadName)-1;
1164 len = len < maxlen ? len : maxlen; 1183 len = len < maxlen ? len : maxlen;
@@ -1206,8 +1225,8 @@ void MicroProfileOnThreadExit()
1206 { 1225 {
1207 S.Frames[i].nLogStart[nLogIndex] = 0; 1226 S.Frames[i].nLogStart[nLogIndex] = 0;
1208 } 1227 }
1209 memset(pLog->nGroupStackPos, 0, sizeof(pLog->nGroupStackPos)); 1228 pLog->nGroupStackPos.fill(0);
1210 memset(pLog->nGroupTicks, 0, sizeof(pLog->nGroupTicks)); 1229 pLog->nGroupTicks.fill(0);
1211 } 1230 }
1212} 1231}
1213 1232