forked from zeux/microprofile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
microprofileui.h
3829 lines (3391 loc) · 129 KB
/
microprofileui.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
// This is free and unencumbered software released into the public domain.
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// For more information, please refer to <http://unlicense.org/>
//
// ***********************************************************************
//
//
//
#ifndef MICROPROFILE_ENABLED
#error "microprofile.h must be included before including microprofileui.h"
#endif
#ifndef MICROPROFILEUI_ENABLED
#define MICROPROFILEUI_ENABLED MICROPROFILE_ENABLED
#endif
#ifndef MICROPROFILEUI_API
#define MICROPROFILEUI_API
#endif
#if 0 == MICROPROFILEUI_ENABLED
#define MicroProfileMouseButton(foo, bar) do{}while(0)
#define MicroProfileMousePosition(foo, bar, z) do{}while(0)
#define MicroProfileModKey(key) do{}while(0)
#define MicroProfileDraw(foo, bar) do{}while(0)
#define MicroProfileIsDrawing() 0
#define MicroProfileToggleDisplayMode() do{}while(0)
#define MicroProfileSetDisplayMode(f) do{}while(0)
#else
#ifndef MICROPROFILE_DRAWCURSOR
#define MICROPROFILE_DRAWCURSOR 0
#endif
#ifndef MICROPROFILE_DETAILED_BAR_NAMES
#define MICROPROFILE_DETAILED_BAR_NAMES 1
#endif
#ifndef MICROPROFILE_TEXT_WIDTH
#define MICROPROFILE_TEXT_WIDTH 5
#endif
#ifndef MICROPROFILE_TEXT_HEIGHT
#define MICROPROFILE_TEXT_HEIGHT 8
#endif
#ifndef MICROPROFILE_DETAILED_BAR_HEIGHT
#define MICROPROFILE_DETAILED_BAR_HEIGHT 12
#endif
#ifndef MICROPROFILE_DETAILED_CONTEXT_SWITCH_HEIGHT
#define MICROPROFILE_DETAILED_CONTEXT_SWITCH_HEIGHT 7
#endif
#ifndef MICROPROFILE_GRAPH_WIDTH
#define MICROPROFILE_GRAPH_WIDTH 256
#endif
#ifndef MICROPROFILE_GRAPH_HEIGHT
#define MICROPROFILE_GRAPH_HEIGHT 256
#endif
#ifndef MICROPROFILE_BORDER_SIZE
#define MICROPROFILE_BORDER_SIZE 1
#endif
#ifndef MICROPROFILE_HELP_LEFT
#define MICROPROFILE_HELP_LEFT "Left-Click"
#endif
#ifndef MICROPROFILE_HELP_RIGHT
#define MICROPROFILE_HELP_RIGHT "Right-Click"
#endif
#ifndef MICROPROFILE_HELP_MOD
#define MICROPROFILE_HELP_MOD "Mod"
#endif
#ifndef MICROPROFILE_BAR_WIDTH
#define MICROPROFILE_BAR_WIDTH 100
#endif
#ifndef MICROPROFILE_CUSTOM_MAX
#define MICROPROFILE_CUSTOM_MAX 8
#endif
#ifndef MICROPROFILE_CUSTOM_MAX_TIMERS
#define MICROPROFILE_CUSTOM_MAX_TIMERS 64
#endif
#ifndef MICROPROFILE_CUSTOM_PADDING
#define MICROPROFILE_CUSTOM_PADDING 12
#endif
#define MICROPROFILE_FRAME_HISTORY_HEIGHT 50
#define MICROPROFILE_FRAME_HISTORY_WIDTH 7
#define MICROPROFILE_FRAME_HISTORY_COLOR_CPU 0xffff7f27 //255 127 39
#define MICROPROFILE_FRAME_HISTORY_COLOR_GPU 0xff37a0ee //55 160 238
#define MICROPROFILE_FRAME_HISTORY_COLOR_HIGHTLIGHT 0x7733bb44
#define MICROPROFILE_FRAME_COLOR_HIGHTLIGHT 0x20009900
#define MICROPROFILE_FRAME_COLOR_HIGHTLIGHT_GPU 0x20996600
#define MICROPROFILE_NUM_FRAMES (MICROPROFILE_MAX_FRAME_HISTORY - (MICROPROFILE_GPU_FRAME_DELAY+1))
#define MICROPROFILE_TOOLTIP_MAX_STRINGS (32 + MICROPROFILE_MAX_GROUPS*2)
#define MICROPROFILE_TOOLTIP_STRING_BUFFER_SIZE (4*1024)
#define MICROPROFILE_TOOLTIP_MAX_LOCKED 3
#define MICROPROFILE_COUNTER_INDENT 4
#define MICROPROFILE_COUNTER_WIDTH 100
enum
{
MICROPROFILE_CUSTOM_BARS = 0x1,
MICROPROFILE_CUSTOM_BAR_SOURCE_MAX = 0x2,
MICROPROFILE_CUSTOM_BAR_SOURCE_AVG = 0,
MICROPROFILE_CUSTOM_STACK = 0x4,
MICROPROFILE_CUSTOM_STACK_SOURCE_MAX = 0x8,
MICROPROFILE_CUSTOM_STACK_SOURCE_AVG = 0,
};
MICROPROFILEUI_API void MicroProfileDraw(uint32_t nWidth, uint32_t nHeight); //! call if drawing microprofilers
MICROPROFILEUI_API bool MicroProfileIsDrawing();
MICROPROFILEUI_API void MicroProfileToggleGraph(MicroProfileToken nToken);
MICROPROFILEUI_API bool MicroProfileDrawGraph(uint32_t nScreenWidth, uint32_t nScreenHeight);
MICROPROFILEUI_API void MicroProfileToggleDisplayMode(); //switch between off, bars, detailed
MICROPROFILEUI_API void MicroProfileSetDisplayMode(int); //switch between off, bars, detailed
MICROPROFILEUI_API void MicroProfileClearGraph();
MICROPROFILEUI_API void MicroProfileMousePosition(uint32_t nX, uint32_t nY, int nWheelDelta);
MICROPROFILEUI_API void MicroProfileModKey(uint32_t nKeyState);
MICROPROFILEUI_API void MicroProfileMouseButton(uint32_t nLeft, uint32_t nRight);
MICROPROFILEUI_API void MicroProfileDrawLineVertical(int nX, int nTop, int nBottom, uint32_t nColor);
MICROPROFILEUI_API void MicroProfileDrawLineHorizontal(int nLeft, int nRight, int nY, uint32_t nColor);
MICROPROFILEUI_API void MicroProfileLoadPreset(const char* pSuffix);
MICROPROFILEUI_API void MicroProfileSavePreset(const char* pSuffix);
MICROPROFILEUI_API void MicroProfileDrawText(int nX, int nY, uint32_t nColor, const char* pText, uint32_t nNumCharacters);
MICROPROFILEUI_API void MicroProfileDrawBox(int nX, int nY, int nX1, int nY1, uint32_t nColor, MicroProfileBoxType = MicroProfileBoxTypeFlat);
MICROPROFILEUI_API void MicroProfileDrawLine2D(uint32_t nVertices, float* pVertices, uint32_t nColor);
MICROPROFILEUI_API void MicroProfileDumpTimers();
MICROPROFILEUI_API void MicroProfileInitUI();
MICROPROFILEUI_API void MicroProfileCustomGroupToggle(const char* pCustomName);
MICROPROFILEUI_API void MicroProfileCustomGroupEnable(const char* pCustomName);
MICROPROFILEUI_API void MicroProfileCustomGroupEnable(uint32_t nIndex);
MICROPROFILEUI_API void MicroProfileCustomGroupDisable();
MICROPROFILEUI_API void MicroProfileCustomGroup(const char* pCustomName, uint32_t nMaxTimers, uint32_t nAggregateFlip, float fReferenceTime, uint32_t nFlags);
MICROPROFILEUI_API void MicroProfileCustomGroupAddTimer(const char* pCustomName, const char* pGroup, const char* pTimer);
#ifdef MICROPROFILEUI_IMPL
#ifdef _WIN32
#define snprintf _snprintf
#endif
#include <cstdlib>
#include <cstdarg>
#include <cmath>
#include <algorithm>
MICROPROFILE_DEFINE(g_MicroProfileDetailed, "MicroProfile", "Detailed View", 0x8888000);
MICROPROFILE_DEFINE(g_MicroProfileDrawGraph, "MicroProfile", "Draw Graph", 0xff44ee00);
MICROPROFILE_DEFINE(g_MicroProfileDrawBarView, "MicroProfile", "DrawBarView", 0x00dd77);
MICROPROFILE_DEFINE(g_MicroProfileDraw,"MicroProfile", "Draw", 0x737373);
struct MicroProfileStringArray
{
const char* ppStrings[MICROPROFILE_TOOLTIP_MAX_STRINGS];
char Buffer[MICROPROFILE_TOOLTIP_STRING_BUFFER_SIZE];
char* pBufferPos;
uint32_t nNumStrings;
};
struct MicroProfileGroupMenuItem
{
uint32_t nIsCategory;
uint32_t nCategoryIndex;
uint32_t nIndex;
const char* pName;
};
struct MicroProfileCustom
{
char pName[MICROPROFILE_NAME_MAX_LEN];
uint32_t nFlags;
uint32_t nAggregateFlip;
uint32_t nNumTimers;
uint32_t nMaxTimers;
uint64_t nGroupMask;
float fReference;
uint64_t* pTimers;
};
struct SOptionDesc
{
SOptionDesc(){}
SOptionDesc(uint8_t nSubType, uint8_t nIndex, const char* fmt, ...):nSubType(nSubType), nIndex(nIndex)
{
va_list args;
va_start (args, fmt);
vsprintf(Text, fmt, args);
va_end(args);
}
char Text[32];
uint8_t nSubType;
uint8_t nIndex;
bool bSelected;
};
static uint32_t g_MicroProfileAggregatePresets[] = {0, 10, 20, 30, 60, 120};
static float g_MicroProfileReferenceTimePresets[] = {5.f, 10.f, 15.f,20.f, 33.33f, 66.66f, 100.f, 250.f, 500.f, 1000.f};
static uint32_t g_MicroProfileOpacityPresets[] = {0x40, 0x80, 0xc0, 0xff};
static const char* g_MicroProfilePresetNames[] =
{
MICROPROFILE_DEFAULT_PRESET,
"Render",
"GPU",
"Lighting",
"AI",
"Visibility",
"Sound",
};
enum
{
MICROPROFILE_NUM_REFERENCE_PRESETS = sizeof(g_MicroProfileReferenceTimePresets)/sizeof(g_MicroProfileReferenceTimePresets[0]),
MICROPROFILE_NUM_OPACITY_PRESETS = sizeof(g_MicroProfileOpacityPresets)/sizeof(g_MicroProfileOpacityPresets[0]),
#if MICROPROFILE_CONTEXT_SWITCH_TRACE
MICROPROFILE_OPTION_SIZE = MICROPROFILE_NUM_REFERENCE_PRESETS + MICROPROFILE_NUM_OPACITY_PRESETS * 2 + 2 + 6,
#else
MICROPROFILE_OPTION_SIZE = MICROPROFILE_NUM_REFERENCE_PRESETS + MICROPROFILE_NUM_OPACITY_PRESETS * 2 + 2 + 3,
#endif
};
struct MicroProfileUI
{
//menu/mouse over stuff
uint64_t nHoverToken;
int64_t nHoverTime;
int nHoverFrame;
#if MICROPROFILE_DEBUG
uint64_t nHoverAddressEnter;
uint64_t nHoverAddressLeave;
#endif
uint32_t nWidth;
uint32_t nHeight;
int nOffsetX[MP_DRAW_SIZE];
int nOffsetY[MP_DRAW_SIZE];
float fDetailedOffset; //display offset relative to start of latest displayable frame.
float fDetailedRange; //no. of ms to display
float fDetailedOffsetTarget;
float fDetailedRangeTarget;
uint32_t nOpacityBackground;
uint32_t nOpacityForeground;
bool bShowSpikes;
uint32_t nMouseX;
uint32_t nMouseY;
uint32_t nMouseDownX;
uint32_t nMouseDownY;
int nMouseWheelDelta;
uint32_t nMouseDownLeft;
uint32_t nMouseDownRight;
uint32_t nMouseLeft;
uint32_t nMouseRight;
uint32_t nMouseLeftMod;
uint32_t nMouseRightMod;
uint32_t nModDown;
uint32_t nActiveMenu;
MicroProfileLogEntry* pDisplayMouseOver;
int64_t nRangeBegin;
int64_t nRangeEnd;
int64_t nRangeBeginGpu;
int64_t nRangeEndGpu;
uint32_t nRangeBeginIndex;
uint32_t nRangeEndIndex;
MicroProfileThreadLog* pRangeLog;
uint32_t nHoverColor;
uint32_t nHoverColorShared;
int64_t nTickReferenceCpu;
int64_t nTickReferenceGpu;
MicroProfileStringArray LockedToolTips[MICROPROFILE_TOOLTIP_MAX_LOCKED];
uint32_t nLockedToolTipColor[MICROPROFILE_TOOLTIP_MAX_LOCKED];
int LockedToolTipFront;
MicroProfileGroupMenuItem GroupMenu[MICROPROFILE_MAX_GROUPS + MICROPROFILE_MAX_CATEGORIES];
uint32_t GroupMenuCount;
uint32_t nCustomActive;
uint32_t nCustomTimerCount;
uint32_t nCustomCount;
MicroProfileCustom Custom[MICROPROFILE_CUSTOM_MAX];
uint64_t CustomTimer[MICROPROFILE_CUSTOM_MAX_TIMERS];
SOptionDesc Options[MICROPROFILE_OPTION_SIZE];
uint32_t nCounterWidth;
uint32_t nLimitWidth;
uint32_t nCounterWidthTemp;
uint32_t nLimitWidthTemp;
};
MicroProfileUI g_MicroProfileUI;
#define UI g_MicroProfileUI
static uint32_t g_nMicroProfileBackColors[2] = { 0x474747, 0x313131 };
#define MICROPROFILE_NUM_CONTEXT_SWITCH_COLORS 16
static uint32_t g_nMicroProfileContextSwitchThreadColors[MICROPROFILE_NUM_CONTEXT_SWITCH_COLORS] = //palette generated by http://tools.medialab.sciences-po.fr/iwanthue/index.php
{
0x63607B,
0x755E2B,
0x326A55,
0x523135,
0x904F42,
0x87536B,
0x346875,
0x5E6046,
0x35404C,
0x224038,
0x413D1E,
0x5E3A26,
0x5D6161,
0x4C6234,
0x7D564F,
0x5C4352,
};
void MicroProfileInitUI()
{
static bool bInitialized = false;
if(!bInitialized)
{
bInitialized = true;
memset(&g_MicroProfileUI, 0, sizeof(g_MicroProfileUI));
UI.nActiveMenu = (uint32_t)-1;
UI.fDetailedOffsetTarget = UI.fDetailedOffset = 0.f;
UI.fDetailedRangeTarget = UI.fDetailedRange = 50.f;
UI.nOpacityBackground = 0xff<<24;
UI.nOpacityForeground = 0xff<<24;
UI.bShowSpikes = false;
UI.nWidth = 100;
UI.nHeight = 100;
UI.nCustomActive = (uint32_t)-1;
UI.nCustomTimerCount = 0;
UI.nCustomCount = 0;
int nIndex = 0;
UI.Options[nIndex++] = SOptionDesc(0xff, 0, "%s", "Reference");
for(int i = 0; i < MICROPROFILE_NUM_REFERENCE_PRESETS; ++i)
{
UI.Options[nIndex++] = SOptionDesc(0, i, " %6.2fms", g_MicroProfileReferenceTimePresets[i]);
}
UI.Options[nIndex++] = SOptionDesc(0xff, 0, "%s", "BG Opacity");
for(int i = 0; i < MICROPROFILE_NUM_OPACITY_PRESETS; ++i)
{
UI.Options[nIndex++] = SOptionDesc(1, i, " %7d%%", (i+1)*25);
}
UI.Options[nIndex++] = SOptionDesc(0xff, 0, "%s", "FG Opacity");
for(int i = 0; i < MICROPROFILE_NUM_OPACITY_PRESETS; ++i)
{
UI.Options[nIndex++] = SOptionDesc(2, i, " %7d%%", (i+1)*25);
}
UI.Options[nIndex++] = SOptionDesc(0xff, 0, "%s", "Spike Display");
UI.Options[nIndex++] = SOptionDesc(3, 0, "%s", " Enable");
#if MICROPROFILE_CONTEXT_SWITCH_TRACE
UI.Options[nIndex++] = SOptionDesc(0xff, 0, "%s", "CSwitch Trace");
UI.Options[nIndex++] = SOptionDesc(4, 0, "%s", " All Threads");
UI.Options[nIndex++] = SOptionDesc(4, 1, "%s", " No Bars");
#endif
MP_ASSERT(nIndex == MICROPROFILE_OPTION_SIZE);
UI.nCounterWidth = 100;
UI.nLimitWidth = 100;
UI.nCounterWidthTemp = 100;
UI.nLimitWidthTemp = 100;
}
}
void MicroProfileSetDisplayMode(int nValue)
{
MicroProfile& S = *MicroProfileGet();
nValue = nValue >= 0 && nValue < MP_DRAW_SIZE ? nValue : S.nDisplay;
S.nDisplay = nValue;
UI.nOffsetY[S.nDisplay] = 0;
}
void MicroProfileToggleDisplayMode()
{
MicroProfile& S = *MicroProfileGet();
S.nDisplay = (S.nDisplay + 1) % MP_DRAW_SIZE;
UI.nOffsetY[S.nDisplay] = 0;
}
void MicroProfileStringArrayClear(MicroProfileStringArray* pArray)
{
pArray->nNumStrings = 0;
pArray->pBufferPos = &pArray->Buffer[0];
}
void MicroProfileStringArrayAddLiteral(MicroProfileStringArray* pArray, const char* pLiteral)
{
MP_ASSERT(pArray->nNumStrings < MICROPROFILE_TOOLTIP_MAX_STRINGS);
pArray->ppStrings[pArray->nNumStrings++] = pLiteral;
}
MICROPROFILE_FORMAT(2, 3) void MicroProfileStringArrayFormat(MicroProfileStringArray* pArray, const char* fmt, ...)
{
MP_ASSERT(pArray->nNumStrings < MICROPROFILE_TOOLTIP_MAX_STRINGS);
pArray->ppStrings[pArray->nNumStrings++] = pArray->pBufferPos;
va_list args;
va_start (args, fmt);
pArray->pBufferPos += 1 + vsprintf(pArray->pBufferPos, fmt, args);
va_end(args);
MP_ASSERT(pArray->pBufferPos < pArray->Buffer + MICROPROFILE_TOOLTIP_STRING_BUFFER_SIZE);
}
void MicroProfileStringArrayCopy(MicroProfileStringArray* pDest, MicroProfileStringArray* pSrc)
{
memcpy(&pDest->ppStrings[0], &pSrc->ppStrings[0], sizeof(pDest->ppStrings));
memcpy(&pDest->Buffer[0], &pSrc->Buffer[0], sizeof(pDest->Buffer));
for(uint32_t i = 0; i < MICROPROFILE_TOOLTIP_MAX_STRINGS; ++i)
{
if(i < pSrc->nNumStrings)
{
if(pSrc->ppStrings[i] >= &pSrc->Buffer[0] && pSrc->ppStrings[i] < &pSrc->Buffer[0] + MICROPROFILE_TOOLTIP_STRING_BUFFER_SIZE)
{
pDest->ppStrings[i] += &pDest->Buffer[0] - &pSrc->Buffer[0];
}
}
}
pDest->nNumStrings = pSrc->nNumStrings;
}
void MicroProfileFloatWindowSize(const char** ppStrings, uint32_t nNumStrings, uint32_t* pColors, uint32_t& nWidth, uint32_t& nHeight, uint32_t* pStringLengths = 0)
{
uint32_t* nStringLengths = pStringLengths ? pStringLengths : (uint32_t*)alloca(nNumStrings * sizeof(uint32_t));
uint32_t nTextCount = nNumStrings/2;
for(uint32_t i = 0; i < nTextCount; ++i)
{
uint32_t i0 = i * 2;
uint32_t s0, s1;
nStringLengths[i0] = s0 = (uint32_t)strlen(ppStrings[i0]);
nStringLengths[i0+1] = s1 = (uint32_t)strlen(ppStrings[i0+1]);
nWidth = MicroProfileMax(s0+s1, nWidth);
}
nWidth = (MICROPROFILE_TEXT_WIDTH+1) * (2+nWidth) + 2 * MICROPROFILE_BORDER_SIZE;
if(pColors)
nWidth += MICROPROFILE_TEXT_WIDTH + 1;
nHeight = (MICROPROFILE_TEXT_HEIGHT+1) * nTextCount + 2 * MICROPROFILE_BORDER_SIZE;
}
void MicroProfileDrawFloatWindow(uint32_t nX, uint32_t nY, const char** ppStrings, uint32_t nNumStrings, uint32_t nColor, uint32_t* pColors = 0)
{
uint32_t nWidth = 0, nHeight = 0;
uint32_t* nStringLengths = (uint32_t*)alloca(nNumStrings * sizeof(uint32_t));
MicroProfileFloatWindowSize(ppStrings, nNumStrings, pColors, nWidth, nHeight, nStringLengths);
uint32_t nTextCount = nNumStrings/2;
if(nX + nWidth > UI.nWidth)
nX = UI.nWidth - nWidth;
if(nY + nHeight > UI.nHeight)
nY = UI.nHeight - nHeight;
MicroProfileDrawBox(nX-1, nY-1, nX + nWidth+1, nY + nHeight+1, 0xff000000|nColor);
MicroProfileDrawBox(nX, nY, nX + nWidth, nY + nHeight, 0xff000000);
if(pColors)
{
nX += MICROPROFILE_TEXT_WIDTH+1;
nWidth -= MICROPROFILE_TEXT_WIDTH+1;
}
for(uint32_t i = 0; i < nTextCount; ++i)
{
int i0 = i * 2;
if(pColors)
{
MicroProfileDrawBox(nX-MICROPROFILE_TEXT_WIDTH, nY, nX, nY + MICROPROFILE_TEXT_WIDTH, pColors[i]|0xff000000);
}
MicroProfileDrawText(nX + 1, nY + 1, (uint32_t)-1, ppStrings[i0], (uint32_t)strlen(ppStrings[i0]));
MicroProfileDrawText(nX + nWidth - nStringLengths[i0+1] * (MICROPROFILE_TEXT_WIDTH+1), nY + 1, (uint32_t)-1, ppStrings[i0+1], (uint32_t)strlen(ppStrings[i0+1]));
nY += (MICROPROFILE_TEXT_HEIGHT+1);
}
}
void MicroProfileDrawTextBackground(uint32_t nX, uint32_t nY, uint32_t nColor, uint32_t nBgColor, const char* pString, uint32_t nStrLen)
{
uint32_t nWidth = (MICROPROFILE_TEXT_WIDTH + 1) * (nStrLen) + 2 * MICROPROFILE_BORDER_SIZE;
uint32_t nHeight = (MICROPROFILE_TEXT_HEIGHT + 1) ;
MicroProfileDrawBox(nX, nY, nX + nWidth, nY + nHeight, nBgColor);
MicroProfileDrawText(nX, nY, nColor, pString, nStrLen);
}
void MicroProfileToolTipMeta(MicroProfileStringArray* pToolTip)
{
MicroProfile& S = *MicroProfileGet();
if(UI.nRangeBeginIndex != UI.nRangeEndIndex && UI.pRangeLog)
{
uint64_t nMetaSum[MICROPROFILE_META_MAX] = {0};
uint64_t nMetaSumInclusive[MICROPROFILE_META_MAX] = {0};
int nStackDepth = 0;
uint32_t nRange[2][2];
MicroProfileThreadLog* pLog = UI.pRangeLog;
MicroProfileGetRange(UI.nRangeEndIndex, UI.nRangeBeginIndex, nRange);
for(uint32_t i = 0; i < 2; ++i)
{
uint32_t nStart = nRange[i][0];
uint32_t nEnd = nRange[i][1];
for(uint32_t j = nStart; j < nEnd; ++j)
{
MicroProfileLogEntry LE = pLog->Log[j];
uint64_t nType = MicroProfileLogType(LE);
switch(nType)
{
case MP_LOG_META:
{
int64_t nMetaIndex = MicroProfileLogTimerIndex(LE);
int64_t nMetaCount = MicroProfileLogGetTick(LE);
MP_ASSERT(nMetaIndex < MICROPROFILE_META_MAX);
if(nStackDepth>1)
{
nMetaSumInclusive[nMetaIndex] += nMetaCount;
}
else
{
nMetaSum[nMetaIndex] += nMetaCount;
}
}
break;
case MP_LOG_LEAVE:
if(nStackDepth)
{
nStackDepth--;
}
else
{
for(int i = 0; i < MICROPROFILE_META_MAX; ++i)
{
nMetaSumInclusive[i] += nMetaSum[i];
nMetaSum[i] = 0;
}
}
break;
case MP_LOG_ENTER:
nStackDepth++;
break;
}
}
}
bool bSpaced = false;
for(int i = 0; i < MICROPROFILE_META_MAX; ++i)
{
if(S.MetaCounters[i].pName && (nMetaSum[i]||nMetaSumInclusive[i]))
{
if(!bSpaced)
{
bSpaced = true;
MicroProfileStringArrayAddLiteral(pToolTip, "");
MicroProfileStringArrayAddLiteral(pToolTip, "");
}
MicroProfileStringArrayFormat(pToolTip, "%s excl", S.MetaCounters[i].pName);
MicroProfileStringArrayFormat(pToolTip, "%5lld", (long long)nMetaSum[i]);
MicroProfileStringArrayFormat(pToolTip, "%s incl", S.MetaCounters[i].pName);
MicroProfileStringArrayFormat(pToolTip, "%5lld", (long long)(nMetaSum[i] + nMetaSumInclusive[i]));
}
}
}
}
void MicroProfileToolTipLabel(MicroProfileStringArray* pToolTip)
{
if(UI.nRangeBeginIndex != UI.nRangeEndIndex && UI.pRangeLog)
{
bool bSpaced = false;
int nStackDepth = 0;
uint32_t nRange[2][2];
MicroProfileThreadLog* pLog = UI.pRangeLog;
MicroProfileGetRange(UI.nRangeEndIndex, UI.nRangeBeginIndex, nRange);
for(uint32_t i = 0; i < 2; ++i)
{
uint32_t nStart = nRange[i][0];
uint32_t nEnd = nRange[i][1];
for(uint32_t j = nStart; j < nEnd; ++j)
{
MicroProfileLogEntry LE = pLog->Log[j];
int nType = MicroProfileLogType(LE);
switch(nType)
{
case MP_LOG_LABEL:
{
if(nStackDepth == 1)
{
uint64_t nLabel = MicroProfileLogGetTick(LE);
const char* pLabelName = MicroProfileGetLabel(nLabel);
if (!bSpaced)
{
bSpaced = true;
MicroProfileStringArrayAddLiteral(pToolTip, "");
MicroProfileStringArrayAddLiteral(pToolTip, "");
}
if (pToolTip->nNumStrings + 2 <= MICROPROFILE_TOOLTIP_MAX_STRINGS)
{
MicroProfileStringArrayAddLiteral(pToolTip, "Label:");
MicroProfileStringArrayAddLiteral(pToolTip, pLabelName ? pLabelName : "??");
}
}
}
break;
case MP_LOG_LEAVE:
if(nStackDepth)
{
nStackDepth--;
}
break;
case MP_LOG_ENTER:
nStackDepth++;
break;
}
}
}
}
}
void MicroProfileDrawFloatTooltip(uint32_t nX, uint32_t nY, uint32_t nToken, uint64_t nTime)
{
MicroProfile& S = *MicroProfileGet();
uint32_t nIndex = MicroProfileGetTimerIndex(nToken);
uint32_t nAggregateFrames = S.nAggregateFrames ? S.nAggregateFrames : 1;
uint32_t nAggregateCount = S.Aggregate[nIndex].nCount ? S.Aggregate[nIndex].nCount : 1;
uint32_t nGroupId = MicroProfileGetGroupIndex(nToken);
uint32_t nTimerId = MicroProfileGetTimerIndex(nToken);
bool bGpu = S.GroupInfo[nGroupId].Type == MicroProfileTokenTypeGpu;
float fToMs = MicroProfileTickToMsMultiplier(bGpu ? MicroProfileTicksPerSecondGpu() : MicroProfileTicksPerSecondCpu());
float fMs = fToMs * (nTime);
float fFrameMs = fToMs * (S.Frame[nIndex].nTicks);
float fAverage = fToMs * (S.Aggregate[nIndex].nTicks/nAggregateFrames);
float fCallAverage = fToMs * (S.Aggregate[nIndex].nTicks / nAggregateCount);
float fMax = fToMs * (S.AggregateMax[nIndex]);
float fMin = fToMs * (S.AggregateMin[nIndex]);
float fFrameMsExclusive = fToMs * (S.FrameExclusive[nIndex]);
float fAverageExclusive = fToMs * (S.AggregateExclusive[nIndex]/nAggregateFrames);
float fMaxExclusive = fToMs * (S.AggregateMaxExclusive[nIndex]);
float fGroupAverage = fToMs * (S.AggregateGroup[nGroupId] / nAggregateFrames);
float fGroupMax = fToMs * (S.AggregateGroupMax[nGroupId]);
float fGroup = fToMs * (S.FrameGroup[nGroupId]);
MicroProfileStringArray ToolTip;
MicroProfileStringArrayClear(&ToolTip);
const char* pGroupName = S.GroupInfo[nGroupId].pName;
const char* pTimerName = S.TimerInfo[nTimerId].pName;
MicroProfileStringArrayAddLiteral(&ToolTip, "Timer:");
MicroProfileStringArrayFormat(&ToolTip, "%s", pTimerName);
#if MICROPROFILE_DEBUG
MicroProfileStringArrayFormat(&ToolTip,"0x%p", UI.nHoverAddressEnter);
MicroProfileStringArrayFormat(&ToolTip,"0x%p", UI.nHoverAddressLeave);
#endif
if(nTime != (uint64_t)0)
{
MicroProfileStringArrayAddLiteral(&ToolTip, "Time:");
MicroProfileStringArrayFormat(&ToolTip,"%6.3fms", fMs);
MicroProfileStringArrayAddLiteral(&ToolTip, "");
MicroProfileStringArrayAddLiteral(&ToolTip, "");
}
MicroProfileStringArrayAddLiteral(&ToolTip, "Frame Time:");
MicroProfileStringArrayFormat(&ToolTip,"%6.3fms", fFrameMs);
MicroProfileStringArrayAddLiteral(&ToolTip, "Average:");
MicroProfileStringArrayFormat(&ToolTip,"%6.3fms", fAverage);
MicroProfileStringArrayAddLiteral(&ToolTip, "Max:");
MicroProfileStringArrayFormat(&ToolTip,"%6.3fms", fMax);
MicroProfileStringArrayAddLiteral(&ToolTip, "Min:");
MicroProfileStringArrayFormat(&ToolTip, "%6.3fms", fMin);
MicroProfileStringArrayAddLiteral(&ToolTip, "");
MicroProfileStringArrayAddLiteral(&ToolTip, "");
MicroProfileStringArrayAddLiteral(&ToolTip, "Call Average:");
MicroProfileStringArrayFormat(&ToolTip,"%6.3fms", fCallAverage);
MicroProfileStringArrayAddLiteral(&ToolTip, "Call Count:");
MicroProfileStringArrayFormat(&ToolTip, "%6.2f", double(nAggregateCount) / nAggregateFrames);
MicroProfileStringArrayAddLiteral(&ToolTip, "");
MicroProfileStringArrayAddLiteral(&ToolTip, "");
MicroProfileStringArrayAddLiteral(&ToolTip, "Exclusive Frame Time:");
MicroProfileStringArrayFormat(&ToolTip, "%6.3fms", fFrameMsExclusive);
MicroProfileStringArrayAddLiteral(&ToolTip, "Exclusive Average:");
MicroProfileStringArrayFormat(&ToolTip, "%6.3fms", fAverageExclusive);
MicroProfileStringArrayAddLiteral(&ToolTip, "Exclusive Max:");
MicroProfileStringArrayFormat(&ToolTip, "%6.3fms", fMaxExclusive);
MicroProfileStringArrayAddLiteral(&ToolTip, "");
MicroProfileStringArrayAddLiteral(&ToolTip, "");
MicroProfileStringArrayAddLiteral(&ToolTip, "Group:");
MicroProfileStringArrayFormat(&ToolTip, "%s", pGroupName);
MicroProfileStringArrayAddLiteral(&ToolTip, "Frame Time:");
MicroProfileStringArrayFormat(&ToolTip, "%6.3f", fGroup);
MicroProfileStringArrayAddLiteral(&ToolTip, "Frame Average:");
MicroProfileStringArrayFormat(&ToolTip, "%6.3f", fGroupAverage);
MicroProfileStringArrayAddLiteral(&ToolTip, "Frame Max:");
MicroProfileStringArrayFormat(&ToolTip, "%6.3f", fGroupMax);
MicroProfileToolTipMeta(&ToolTip);
MicroProfileToolTipLabel(&ToolTip);
MicroProfileDrawFloatWindow(nX, nY+20, &ToolTip.ppStrings[0], ToolTip.nNumStrings, S.TimerInfo[nTimerId].nColor);
if(UI.nMouseLeftMod)
{
int nIndex = (g_MicroProfileUI.LockedToolTipFront + MICROPROFILE_TOOLTIP_MAX_LOCKED - 1) % MICROPROFILE_TOOLTIP_MAX_LOCKED;
g_MicroProfileUI.nLockedToolTipColor[nIndex] = S.TimerInfo[nTimerId].nColor;
MicroProfileStringArrayCopy(&g_MicroProfileUI.LockedToolTips[nIndex], &ToolTip);
g_MicroProfileUI.LockedToolTipFront = nIndex;
}
}
int64_t MicroProfileGetGpuTickSync(int64_t nTickCpu, int64_t nTickGpu)
{
if(UI.nTickReferenceCpu && UI.nTickReferenceGpu)
{
int64_t nTicksPerSecondCpu = MicroProfileTicksPerSecondCpu();
int64_t nTicksPerSecondGpu = MicroProfileTicksPerSecondGpu();
return (nTickCpu - UI.nTickReferenceCpu) * (double(nTicksPerSecondGpu) / double(nTicksPerSecondCpu)) + UI.nTickReferenceGpu;
}
else
{
return nTickGpu;
}
}
void MicroProfileZoomTo(int64_t nTickStart, int64_t nTickEnd, MicroProfileTokenType eToken)
{
MicroProfile& S = *MicroProfileGet();
bool bGpu = eToken == MicroProfileTokenTypeGpu;
int64_t nStartCpu = S.Frames[S.nFrameCurrent].nFrameStartCpu;
int64_t nStart = bGpu ? MicroProfileGetGpuTickSync(nStartCpu, S.Frames[S.nFrameCurrent].nFrameStartGpu) : nStartCpu;
uint64_t nFrequency = bGpu ? MicroProfileTicksPerSecondGpu() : MicroProfileTicksPerSecondCpu();
float fToMs = MicroProfileTickToMsMultiplier(nFrequency);
UI.fDetailedOffsetTarget = MicroProfileLogTickDifference(nStart, nTickStart) * fToMs;
UI.fDetailedRangeTarget = MicroProfileMax(MicroProfileLogTickDifference(nTickStart, nTickEnd) * fToMs, 0.01f); // clamp to 10us
}
void MicroProfileCenter(int64_t nTickCenter)
{
MicroProfile& S = *MicroProfileGet();
int64_t nStart = S.Frames[S.nFrameCurrent].nFrameStartCpu;
float fToMs = MicroProfileTickToMsMultiplier(MicroProfileTicksPerSecondCpu());
float fCenter = MicroProfileLogTickDifference(nStart, nTickCenter) * fToMs;
UI.fDetailedOffsetTarget = UI.fDetailedOffset = fCenter - 0.5f * UI.fDetailedRange;
}
#if MICROPROFILE_DEBUG
uint64_t* g_pMicroProfileDumpStart = 0;
uint64_t* g_pMicroProfileDumpEnd = 0;
void MicroProfileDebugDumpRange()
{
MicroProfile& S = *MicroProfileGet();
if(g_pMicroProfileDumpStart != g_pMicroProfileDumpEnd)
{
uint64_t* pStart = g_pMicroProfileDumpStart;
uint64_t* pEnd = g_pMicroProfileDumpEnd;
while(pStart != pEnd)
{
uint64_t nTick = MicroProfileLogGetTick(*pStart);
uint64_t nToken = MicroProfileLogTimerIndex(*pStart);
uint32_t nTimerId = MicroProfileGetTimerIndex(nToken);
const char* pTimerName = S.TimerInfo[nTimerId].pName;
char buffer[256];
uint64_t type = MicroProfileLogType(*pStart);
const char* pBegin = type == MP_LOG_LEAVE ? "END" :
(type == MP_LOG_ENTER ? "BEGIN" : "META");
snprintf(buffer, 255, "DUMP 0x%p: %s :: %" PRIx64 ": %s\n", pStart, pBegin, nTick, pTimerName);
#ifdef _WIN32
OutputDebugString(buffer);
#else
printf("%s", buffer);
#endif
pStart++;
}
g_pMicroProfileDumpStart = g_pMicroProfileDumpEnd;
}
}
#define MP_DEBUG_DUMP_RANGE() MicroProfileDebugDumpRange()
#else
#define MP_DEBUG_DUMP_RANGE() do{} while(0)
#endif
#define MICROPROFILE_HOVER_DIST 0.5f
void MicroProfileDrawDetailedContextSwitchBars(uint32_t nY, uint32_t nThreadId, uint32_t nContextSwitchStart, uint32_t nContextSwitchEnd, int64_t nBaseTicks, uint32_t nBaseY)
{
MicroProfile& S = *MicroProfileGet();
int64_t nTickIn = -1;
uint32_t nThreadBefore = -1;
float fToMs = MicroProfileTickToMsMultiplier(MicroProfileTicksPerSecondCpu());
float fMsToScreen = UI.nWidth / UI.fDetailedRange;
float fMouseX = (float)UI.nMouseX;
float fMouseY = (float)UI.nMouseY;
int nLineDrawn = -1;
for(uint32_t j = nContextSwitchStart; j != nContextSwitchEnd; j = (j+1) % MICROPROFILE_CONTEXT_SWITCH_BUFFER_SIZE)
{
MP_ASSERT(j < MICROPROFILE_CONTEXT_SWITCH_BUFFER_SIZE);
MicroProfileContextSwitch CS = S.ContextSwitch[j];
if(nTickIn == -1)
{
if(CS.nThreadIn == nThreadId)
{
nTickIn = CS.nTicks;
nThreadBefore = CS.nThreadOut;
}
}
else
{
if(CS.nThreadOut == nThreadId)
{
int64_t nTickOut = CS.nTicks;
float fMsStart = fToMs * MicroProfileLogTickDifference(nBaseTicks, nTickIn);
float fMsEnd = fToMs * MicroProfileLogTickDifference(nBaseTicks, nTickOut);
if(fMsStart <= fMsEnd)
{
float fXStart = fMsStart * fMsToScreen;
float fXEnd = fMsEnd * fMsToScreen;
float fYStart = (float)nY;
float fYEnd = fYStart + (MICROPROFILE_DETAILED_CONTEXT_SWITCH_HEIGHT);
uint32_t nColor = g_nMicroProfileContextSwitchThreadColors[CS.nCpu%MICROPROFILE_NUM_CONTEXT_SWITCH_COLORS];
float fXDist = MicroProfileMax(fXStart - fMouseX, fMouseX - fXEnd);
bool bHover = fXDist < MICROPROFILE_HOVER_DIST && fYStart <= fMouseY && fMouseY <= fYEnd && nBaseY < fMouseY;
if(bHover)
{
UI.nRangeBegin = nTickIn;
UI.nRangeEnd = nTickOut;
S.nContextSwitchHoverTickIn = nTickIn;
S.nContextSwitchHoverTickOut = nTickOut;
S.nContextSwitchHoverThread = CS.nThreadOut;
S.nContextSwitchHoverThreadBefore = nThreadBefore;
S.nContextSwitchHoverThreadAfter = CS.nThreadIn;
S.nContextSwitchHoverCpuNext = CS.nCpu;
nColor = UI.nHoverColor;
}
if(CS.nCpu == S.nContextSwitchHoverCpu)
{
nColor = UI.nHoverColorShared;
}
uint32_t nIntegerWidth = (uint32_t)(fXEnd - fXStart);
if(nIntegerWidth)
{
MicroProfileDrawBox((int)fXStart, (int)fYStart, (int)fXEnd, (int)fYEnd, nColor|UI.nOpacityForeground, MicroProfileBoxTypeFlat);
}
else
{
float fXAvg = 0.5f * (fXStart + fXEnd);
int nLineX = (int)floor(fXAvg+0.5f);
if(nLineDrawn != nLineX)
{
nLineDrawn = nLineX;
MicroProfileDrawLineVertical(nLineX, fYStart + 0.5f, fYEnd + 0.5f, nColor|UI.nOpacityForeground);
}
}
}
nTickIn = -1;
}
}
}
}
void MicroProfileWriteThreadHeader(uint32_t nY, MicroProfileThreadIdType ThreadId, const char* pNamedThread, const char* pThreadModule)
{
char Buffer[512];
int nStrLen = 0;
if(pThreadModule)
{
nStrLen = snprintf(Buffer, sizeof(Buffer) - 1, "%04x: %s [%s]", (uint32_t)ThreadId, pNamedThread ? pNamedThread : "", pThreadModule);
}
else
{
nStrLen = snprintf(Buffer, sizeof(Buffer) - 1, "%04x: %s", (uint32_t)ThreadId, pNamedThread ? pNamedThread : "");
}
MicroProfileDrawTextBackground(10, nY, 0xffffff, 0x88777777, Buffer, nStrLen);
}
uint32_t MicroProfileWriteProcessHeader(uint32_t nY, uint32_t nProcessId)
{
char Name[256];
const char* pProcessName = MicroProfileGetProcessName(nProcessId, Name, sizeof(Name));
char Buffer[512];
nY += MICROPROFILE_TEXT_HEIGHT + 1;
int nStrLen = 0;
if(pProcessName)
{
nStrLen = snprintf(Buffer, sizeof(Buffer) - 1, "* %04x: %s", nProcessId, pProcessName);
}
else
{
nStrLen = snprintf(Buffer, sizeof(Buffer) - 1, "* %04x", nProcessId);
}
MicroProfileDrawTextBackground(0, nY, 0xffffff, 0x88777777, Buffer, nStrLen);
nY += MICROPROFILE_TEXT_HEIGHT + 1;
return nY;
}
void MicroProfileGetFrameRange(int64_t nTicks, int64_t nTicksEnd, int32_t nLogIndex, uint32_t* nFrameBegin, uint32_t* nFrameEnd)
{
MicroProfile& S = *MicroProfileGet();
bool bGpu = (nLogIndex >= 0) ? S.Pool[nLogIndex]->nGpu != 0 : false;
uint32_t nPut = (nLogIndex >= 0) ? S.Pool[nLogIndex]->nPut.load(std::memory_order_relaxed) : 0;
uint32_t nBegin = S.nFrameCurrent;
for(uint32_t i = 0; i < MICROPROFILE_MAX_FRAME_HISTORY - MICROPROFILE_GPU_FRAME_DELAY; ++i)
{
uint32_t nFrame = (S.nFrameCurrent + MICROPROFILE_MAX_FRAME_HISTORY - i) % MICROPROFILE_MAX_FRAME_HISTORY;
if(nLogIndex >= 0)
{
uint32_t nCurrStart = S.Frames[nBegin].nLogStart[nLogIndex];
uint32_t nPrevStart = S.Frames[nFrame].nLogStart[nLogIndex];
bool bOverflow = (nPrevStart <= nCurrStart) ? (nPut >= nPrevStart && nPut < nCurrStart) : (nPut < nCurrStart || nPut >= nPrevStart);
if(bOverflow)
break;
}
nBegin = nFrame;