-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmicroprofile.h
5357 lines (4736 loc) · 167 KB
/
microprofile.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
// 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/>
//
// ***********************************************************************
//
//
//
//
// Howto:
// Call these functions from your code:
// MicroProfileOnThreadCreate
// MicroProfileMouseButton
// MicroProfileMousePosition
// MicroProfileModKey
// MicroProfileFlip <-- Call this once per frame
// MicroProfileDraw <-- Call this once per frame
// MicroProfileToggleDisplayMode <-- Bind to a key to toggle profiling
// MicroProfileTogglePause <-- Bind to a key to toggle pause
//
// Use these macros in your code in blocks you want to time:
//
// MICROPROFILE_DECLARE
// MICROPROFILE_DEFINE
// MICROPROFILE_DECLARE_GPU
// MICROPROFILE_DEFINE_GPU
// MICROPROFILE_SCOPE
// MICROPROFILE_SCOPEI
// MICROPROFILE_SCOPEGPU
// MICROPROFILE_SCOPEGPUI
// MICROPROFILE_META
//
//
// Usage:
//
// {
// MICROPROFILE_SCOPEI("GroupName", "TimerName", nColorRgb):
// ..Code to be timed..
// }
//
// MICROPROFILE_DECLARE / MICROPROFILE_DEFINE allows defining groups in a shared place, to ensure sorting of the timers
//
// (in global scope)
// MICROPROFILE_DEFINE(g_ProfileFisk, "Fisk", "Skalle", nSomeColorRgb);
//
// (in some other file)
// MICROPROFILE_DECLARE(g_ProfileFisk);
//
// void foo(){
// MICROPROFILE_SCOPE(g_ProfileFisk);
// }
//
// Once code is instrumented the gui is activeted by calling MicroProfileToggleDisplayMode or by clicking in the upper left corner of
// the screen
//
// The following functions must be implemented before the profiler is usable
// debug render:
// void MicroProfileDrawText(int nX, int nY, uint32_t nColor, const char* pText, uint32_t nNumCharacters);
// void MicroProfileDrawBox(int nX, int nY, int nX1, int nY1, uint32_t nColor, MicroProfileBoxType = MicroProfileBoxTypeFlat);
// void MicroProfileDrawLine2D(uint32_t nVertices, float* pVertices, uint32_t nColor);
// Gpu time stamps: (See below for d3d/opengl helper)
// uint32_t MicroProfileGpuInsertTimeStamp(void*);
// uint64_t MicroProfileGpuGetTimeStamp(uint32_t nKey);
// uint64_t MicroProfileTicksPerSecondGpu();
// threading:
// const char* MicroProfileGetThreadName(char* pzName); Threadnames in detailed view
//
// Default implementations of Gpu timestamp functions:
// Opengl:
// in .c file where MICROPROFILE_IMPL is defined:
// #define MICROPROFILE_GPU_TIMERS_GL
// call MicroProfileGpuInitGL() on startup
// D3D11:
// in .c file where MICROPROFILE_IMPL is defined:
// #define MICROPROFILE_GPU_TIMERS_D3D11
// call MICROPROFILE_GPU_TIMERS_D3D11(). Pass Device & ImmediateContext
//
// Limitations:
// GPU timestamps can only be inserted from one thread.
#ifndef MICROPROFILE_ENABLED
#define MICROPROFILE_ENABLED 1
#endif
#ifndef MICROPROFILE_ONCE
#define MICROPROFILE_ONCE
#include <stdint.h>
#if defined(_WIN32) && _MSC_VER == 1700
#define PRIx64 "llx"
#define PRIu64 "llu"
#define PRId64 "lld"
#else
#include <inttypes.h>
#endif
typedef uint64_t MicroProfileToken;
typedef uint16_t MicroProfileGroupId;
#if 0 == MICROPROFILE_ENABLED
#define MICROPROFILE_DECLARE(var)
#define MICROPROFILE_DEFINE(var, group, name, color)
#define MICROPROFILE_REGISTER_GROUP(group, color, category)
#define MICROPROFILE_DECLARE_GPU(var)
#define MICROPROFILE_DEFINE_GPU(var, name, color)
#define MICROPROFILE_SCOPE(var) do{}while(0)
#define MICROPROFILE_SCOPEI(group, name, color) do{}while(0)
#define MICROPROFILE_SCOPE_TOKEN(token) do {} while(0)
#define MICROPROFILE_SCOPEGPU_TOKEN(token)
#define MICROPROFILE_SCOPEGPU(var) do{}while(0)
#define MICROPROFILE_SCOPEGPUI( name, color) do{}while(0)
#define MICROPROFILE_SCOPEGPU_TOKEN_L(Log, token) do{}while(0)
#define MICROPROFILE_SCOPEGPU_L(Log, var) do{}while(0)
#define MICROPROFILE_SCOPEGPUI_L(Log, name, color) do{}while(0)
#define MICROPROFILE_GPU_INIT_QUEUE(QueueName) do {} while(0)
#define MICROPROFILE_GPU_GET_QUEUE(QueueName) do {} while(0)
#define MICROPROFILE_GPU_BEGIN(pContext, pLog) do {} while(0)
#define MICROPROFILE_GPU_SET_CONTEXT(pContext, pLog) do {} while(0)
#define MICROPROFILE_GPU_END(pLog) 0
#define MICROPROFILE_GPU_SUBMIT(Queue, Work) do {} while(0)
#define MICROPROFILE_THREADLOGGPURESET(a) do{}while(0)
#define MICROPROFILE_META_CPU(name, count)
#define MICROPROFILE_META_GPU(name, count)
#define MICROPROFILE_FORCEENABLECPUGROUP(s) do{} while(0)
#define MICROPROFILE_FORCEDISABLECPUGROUP(s) do{} while(0)
#define MICROPROFILE_FORCEENABLEGPUGROUP(s) do{} while(0)
#define MICROPROFILE_FORCEDISABLEGPUGROUP(s) do{} while(0)
#define MICROPROFILE_COUNTER_ADD(name, count) do{} while(0)
#define MICROPROFILE_COUNTER_SUB(name, count) do{} while(0)
#define MICROPROFILE_COUNTER_SET(name, count) do{} while(0)
#define MICROPROFILE_COUNTER_SET_INT32_PTR(name, ptr) do{} while(0)
#define MICROPROFILE_COUNTER_SET_INT64_PTR(name, ptr) do{} while(0)
#define MICROPROFILE_COUNTER_CLEAR_PTR(name) do{} while(0)
#define MICROPROFILE_COUNTER_SET_LIMIT(name, count) do{} while(0)
#define MICROPROFILE_CONDITIONAL(expr)
#define MICROPROFILE_COUNTER_CONFIG(name, type, limit, flags)
#define MICROPROFILE_DECLARE_LOCAL_COUNTER(var)
#define MICROPROFILE_DEFINE_LOCAL_COUNTER(var, name)
#define MICROPROFILE_DECLARE_LOCAL_ATOMIC_COUNTER(var)
#define MICROPROFILE_DEFINE_LOCAL_ATOMIC_COUNTER(var, name)
#define MICROPROFILE_COUNTER_LOCAL_ADD(var, count) do{}while(0)
#define MICROPROFILE_COUNTER_LOCAL_SUB(var, count) do{}while(0)
#define MICROPROFILE_COUNTER_LOCAL_SET(var, count) do{}while(0)
#define MICROPROFILE_COUNTER_LOCAL_UPDATE_ADD(var) do{}while(0)
#define MICROPROFILE_COUNTER_LOCAL_UPDATE_SET(var) do{}while(0)
#define MicroProfileGetTime(group, name) 0.f
#define MicroProfileOnThreadCreate(foo) do{}while(0)
#define MicroProfileOnThreadExit() do{}while(0)
#define MicroProfileFlip(pContext) do{}while(0)
#define MicroProfileSetAggregateFrames(a) do{}while(0)
#define MicroProfileGetAggregateFrames() 0
#define MicroProfileGetCurrentAggregateFrames() 0
#define MicroProfileTogglePause() do{}while(0)
#define MicroProfileToggleAllGroups() do{} while(0)
#define MicroProfileDumpTimers() do{}while(0)
#define MicroProfileShutdown() do{}while(0)
#define MicroProfileSetForceEnable(a) do{} while(0)
#define MicroProfileGetForceEnable() false
#define MicroProfileSetEnableAllGroups(a) do{} while(0)
#define MicroProfileEnableCategory(a) do{} while(0)
#define MicroProfileDisableCategory(a) do{} while(0)
#define MicroProfileGetEnableAllGroups() false
#define MicroProfileSetForceMetaCounters(a)
#define MicroProfileGetForceMetaCounters() 0
#define MicroProfileEnableMetaCounter(c) do{}while(0)
#define MicroProfileDisableMetaCounter(c) do{}while(0)
#define MicroProfileDumpFile(html,csv,spikecpu,spikegpu) do{} while(0)
#define MicroProfileWebServerPort() ((uint32_t)-1)
#define MicroProfileStartContextSwitchTrace() do{}while(0)
#define MicroProfileDumpFile(html,csv,cpu, gpu) do{} while(0)
#define MicroProfileWebServerPort() ((uint32_t)-1)
#define MicroProfileGpuInsertTimeStamp(a) 1
#define MicroProfileGpuGetTimeStamp(a) 0
#define MicroProfileTicksPerSecondGpu() 1
#define MicroProfileGetGpuTickReference(a,b) 0
#define MicroProfileGpuInitD3D12(pDevice,pCommandQueue) do{}while(0)
#define MicroProfileGpuInitD3D11(pDevice,pDeviceContext) do{}while(0)
#define MicroProfileGpuShutdown() do{}while(0)
#define MicroProfileGpuInitGL() do{}while(0)
#define MicroProfilePlatformMarkersGetEnabled() 0
#define MicroProfilePlatformMarkersSetEnabled(bEnabled) do{}while(0)
#else
#include <stdint.h>
#include <string.h>
#include <thread>
#include <mutex>
#include <atomic>
#ifndef MICROPROFILE_API
#define MICROPROFILE_API
#endif
MICROPROFILE_API int64_t MicroProfileTicksPerSecondCpu();
#if defined(__APPLE__)
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <unistd.h>
#include <libkern/OSAtomic.h>
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE
#define MICROPROFILE_IOS
#endif
#define MP_TICK() mach_absolute_time()
inline int64_t MicroProfileTicksPerSecondCpu()
{
static int64_t nTicksPerSecond = 0;
if(nTicksPerSecond == 0)
{
mach_timebase_info_data_t sTimebaseInfo;
mach_timebase_info(&sTimebaseInfo);
nTicksPerSecond = 1000000000ll * sTimebaseInfo.denom / sTimebaseInfo.numer;
}
return nTicksPerSecond;
}
inline uint64_t MicroProfileGetCurrentThreadId()
{
uint64_t tid;
pthread_threadid_np(pthread_self(), &tid);
return tid;
}
#define MP_BREAK() __builtin_trap()
#define MP_THREAD_LOCAL __thread
#define MP_STRCASECMP strcasecmp
#define MP_GETCURRENTTHREADID() MicroProfileGetCurrentThreadId()
typedef uint64_t MicroProfileThreadIdType;
#elif defined(_WIN32)
int64_t MicroProfileGetTick();
#define MP_TICK() MicroProfileGetTick()
#define MP_BREAK() __debugbreak()
#define MP_THREAD_LOCAL __declspec(thread)
#define MP_STRCASECMP _stricmp
#define MP_GETCURRENTTHREADID() GetCurrentThreadId()
typedef uint32_t MicroProfileThreadIdType;
#elif defined(__linux__)
#include <unistd.h>
#include <time.h>
inline int64_t MicroProfileTicksPerSecondCpu()
{
return 1000000000ll;
}
inline int64_t MicroProfileGetTick()
{
timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return 1000000000ll * ts.tv_sec + ts.tv_nsec;
}
#define MP_TICK() MicroProfileGetTick()
#define MP_BREAK() __builtin_trap()
#define MP_THREAD_LOCAL __thread
#define MP_STRCASECMP strcasecmp
#define MP_GETCURRENTTHREADID() (uint64_t)pthread_self()
typedef uint64_t MicroProfileThreadIdType;
#endif
#ifndef MP_GETCURRENTTHREADID
#define MP_GETCURRENTTHREADID() 0
typedef uint32_t MicroProfileThreadIdType;
#endif
#define MP_ASSERT(a) do{if(!(a)){MP_BREAK();} }while(0)
#define MICROPROFILE_DECLARE(var) extern MicroProfileToken g_mp_##var
#define MICROPROFILE_DEFINE(var, group, name, color) MicroProfileToken g_mp_##var = MicroProfileGetToken(group, name, color, MicroProfileTokenTypeCpu)
#define MICROPROFILE_REGISTER_GROUP(group, category, color) MicroProfileRegisterGroup(group, category, color)
#define MICROPROFILE_DECLARE_GPU(var) extern MicroProfileToken g_mp_##var
#define MICROPROFILE_DEFINE_GPU(var, name, color) MicroProfileToken g_mp_##var = MicroProfileGetToken("GPU", name, color, MicroProfileTokenTypeGpu)
#define MICROPROFILE_TOKEN_PASTE0(a, b) a ## b
#define MICROPROFILE_TOKEN_PASTE(a, b) MICROPROFILE_TOKEN_PASTE0(a,b)
#define MICROPROFILE_SCOPE(var) MicroProfileScopeHandler MICROPROFILE_TOKEN_PASTE(foo, __LINE__)(g_mp_##var)
#define MICROPROFILE_SCOPE_TOKEN(token) MicroProfileScopeHandler MICROPROFILE_TOKEN_PASTE(foo, __LINE__)(token)
#define MICROPROFILE_SCOPEI(group, name, color) static MicroProfileToken MICROPROFILE_TOKEN_PASTE(g_mp,__LINE__) = MicroProfileGetToken(group, name, color, MicroProfileTokenTypeCpu); MicroProfileScopeHandler MICROPROFILE_TOKEN_PASTE(foo,__LINE__)( MICROPROFILE_TOKEN_PASTE(g_mp,__LINE__))
#define MICROPROFILE_SCOPEGPU_TOKEN(token) MicroProfileScopeGpuHandler MICROPROFILE_TOKEN_PASTE(foo, __LINE__)(token, MicroProfileGetGlobaGpuThreadLog())
#define MICROPROFILE_SCOPEGPU(var) MicroProfileScopeGpuHandler MICROPROFILE_TOKEN_PASTE(foo, __LINE__)(g_mp_##var, MicroProfileGetGlobaGpuThreadLog())
#define MICROPROFILE_SCOPEGPUI(name, color) static MicroProfileToken MICROPROFILE_TOKEN_PASTE(g_mp,__LINE__) = MicroProfileGetToken("GPU", name, color, MicroProfileTokenTypeGpu); MicroProfileScopeGpuHandler MICROPROFILE_TOKEN_PASTE(foo,__LINE__)( MICROPROFILE_TOKEN_PASTE(g_mp,__LINE__), MicroProfileGetGlobaGpuThreadLog())
#define MICROPROFILE_SCOPEGPU_TOKEN_L(Log, token) MicroProfileScopeGpuHandler MICROPROFILE_TOKEN_PASTE(foo, __LINE__)(token, Log)
#define MICROPROFILE_SCOPEGPU_L(Log, var) MicroProfileScopeGpuHandler MICROPROFILE_TOKEN_PASTE(foo, __LINE__)(g_mp_##var, Log)
#define MICROPROFILE_SCOPEGPUI_L(Log, name, color) static MicroProfileToken MICROPROFILE_TOKEN_PASTE(g_mp,__LINE__) = MicroProfileGetToken("GPU", name, color, MicroProfileTokenTypeGpu); MicroProfileScopeGpuHandler MICROPROFILE_TOKEN_PASTE(foo,__LINE__)( MICROPROFILE_TOKEN_PASTE(g_mp,__LINE__), Log)
#define MICROPROFILE_GPU_INIT_QUEUE(QueueName) MicroProfileInitGpuQueue(QueueName)
#define MICROPROFILE_GPU_GET_QUEUE(QueueName) MicroProfileGetGpuQueue(QueueName)
#define MICROPROFILE_GPU_BEGIN(pContext, pLog) MicroProfileGpuBegin(pContext, pLog)
#define MICROPROFILE_GPU_SET_CONTEXT(pContext, pLog) MicroProfileGpuSetContext(pContext, pLog)
#define MICROPROFILE_GPU_END(pLog) MicroProfileGpuEnd(pLog)
#define MICROPROFILE_GPU_SUBMIT(Queue, Work) MicroProfileGpuSubmit(Queue, Work)
#define MICROPROFILE_THREADLOGGPURESET(a) MicroProfileThreadLogGpuReset(a)
#define MICROPROFILE_META_CPU(name, count) static MicroProfileToken MICROPROFILE_TOKEN_PASTE(g_mp_meta,__LINE__) = MicroProfileGetMetaToken(name); MicroProfileMetaUpdate(MICROPROFILE_TOKEN_PASTE(g_mp_meta,__LINE__), count, MicroProfileTokenTypeCpu)
//#define MICROPROFILE_META_GPU(name, count) static MicroProfileToken MICROPROFILE_TOKEN_PASTE(g_mp_meta,__LINE__) = MicroProfileGetMetaToken(name); MicroProfileMetaUpdate(MICROPROFILE_TOKEN_PASTE(g_mp_meta,__LINE__), count, MicroProfileTokenTypeGpu)
#define MICROPROFILE_COUNTER_ADD(name, count) static MicroProfileToken MICROPROFILE_TOKEN_PASTE(g_mp_counter,__LINE__) = MicroProfileGetCounterToken(name); MicroProfileCounterAdd(MICROPROFILE_TOKEN_PASTE(g_mp_counter,__LINE__), count)
#define MICROPROFILE_COUNTER_SUB(name, count) static MicroProfileToken MICROPROFILE_TOKEN_PASTE(g_mp_counter,__LINE__) = MicroProfileGetCounterToken(name); MicroProfileCounterAdd(MICROPROFILE_TOKEN_PASTE(g_mp_counter,__LINE__), -(int64_t)count)
#define MICROPROFILE_COUNTER_SET(name, count) static MicroProfileToken MICROPROFILE_TOKEN_PASTE(g_mp_counter_set,__LINE__) = MicroProfileGetCounterToken(name); MicroProfileCounterSet(MICROPROFILE_TOKEN_PASTE(g_mp_counter_set,__LINE__), count)
#define MICROPROFILE_COUNTER_SET_INT32_PTR(name, ptr) MicroProfileCounterSetPtr(name, ptr, sizeof(int32_t))
#define MICROPROFILE_COUNTER_SET_INT64_PTR(name, ptr) MicroProfileCounterSetPtr(name, ptr, sizeof(int64_t))
#define MICROPROFILE_COUNTER_CLEAR_PTR(name) MicroProfileCounterSetPtr(name, 0, 0)
#define MICROPROFILE_COUNTER_SET_LIMIT(name, count) static MicroProfileToken MICROPROFILE_TOKEN_PASTE(g_mp_counter,__LINE__) = MicroProfileGetCounterToken(name); MicroProfileCounterSetLimit(MICROPROFILE_TOKEN_PASTE(g_mp_counter,__LINE__), count)
#define MICROPROFILE_COUNTER_CONFIG(name, type, limit, flags) MicroProfileCounterConfig(name, type, limit, flags)
#define MICROPROFILE_DECLARE_LOCAL_COUNTER(var) extern int64_t g_mp_local_counter##var; extern MicroProfileToken g_mp_counter_token##var;
#define MICROPROFILE_DEFINE_LOCAL_COUNTER(var, name) int64_t g_mp_local_counter##var = 0;MicroProfileToken g_mp_counter_token##var = MicroProfileGetCounterToken(name)
#define MICROPROFILE_DECLARE_LOCAL_ATOMIC_COUNTER(var) extern std::atomic<int64_t> g_mp_local_counter##var; extern MicroProfileToken g_mp_counter_token##var;
#define MICROPROFILE_DEFINE_LOCAL_ATOMIC_COUNTER(var, name) std::atomic<int64_t> g_mp_local_counter##var;MicroProfileToken g_mp_counter_token##var = MicroProfileGetCounterToken(name)
#define MICROPROFILE_COUNTER_LOCAL_ADD(var, count) MicroProfileLocalCounterAdd(&g_mp_local_counter##var, (count))
#define MICROPROFILE_COUNTER_LOCAL_SUB(var, count) MicroProfileLocalCounterAdd(&g_mp_local_counter##var, -(int64_t)(count))
#define MICROPROFILE_COUNTER_LOCAL_SET(var, count) MicroProfileLocalCounterSet(&g_mp_local_counter##var, count)
#define MICROPROFILE_COUNTER_LOCAL_UPDATE_ADD(var) MicroProfileCounterAdd(g_mp_counter_token##var, MicroProfileLocalCounterSet(&g_mp_local_counter##var, 0))
#define MICROPROFILE_COUNTER_LOCAL_UPDATE_SET(var) MicroProfileCounterSet(g_mp_counter_token##var, MicroProfileLocalCounterSet(&g_mp_local_counter##var, 0))
#define MICROPROFILE_CONDITIONAL(expr) expr
#ifndef MICROPROFILE_PLATFORM_MARKERS
#define MICROPROFILE_PLATFORM_MARKERS 0
#endif
#if MICROPROFILE_PLATFORM_MARKERS
#define MICROPROFILE_PLATFORM_MARKERS_ENABLED S.nPlatformMarkersEnabled
#define MICROPROFILE_PLATFORM_MARKER_BEGIN(color,marker) MicroProfilePlatformMarkerBegin(color,marker)
#define MICROPROFILE_PLATFORM_MARKER_END() MicroProfilePlatformMarkerEnd()
#else
#define MICROPROFILE_PLATFORM_MARKER_BEGIN(color,marker) do{(void)color;(void)marker;}while(0)
#define MICROPROFILE_PLATFORM_MARKER_END() do{}while(0)
#define MICROPROFILE_PLATFORM_MARKERS_ENABLED 0
#endif
#ifndef MICROPROFILE_USE_THREAD_NAME_CALLBACK
#define MICROPROFILE_USE_THREAD_NAME_CALLBACK 0
#endif
#ifndef MICROPROFILE_PER_THREAD_BUFFER_SIZE
#define MICROPROFILE_PER_THREAD_BUFFER_SIZE (2048<<10)
#endif
#ifndef MICROPROFILE_PER_THREAD_GPU_BUFFER_SIZE
#define MICROPROFILE_PER_THREAD_GPU_BUFFER_SIZE (128<<10)
#endif
#ifndef MICROPROFILE_MAX_FRAME_HISTORY
#define MICROPROFILE_MAX_FRAME_HISTORY 512
#endif
#ifndef MICROPROFILE_PRINTF
#define MICROPROFILE_PRINTF printf
#endif
#ifndef MICROPROFILE_META_MAX
#define MICROPROFILE_META_MAX 8
#endif
#ifndef MICROPROFILE_WEBSERVER_PORT
#define MICROPROFILE_WEBSERVER_PORT 1338
#endif
#ifndef MICROPROFILE_WEBSERVER
#define MICROPROFILE_WEBSERVER 1
#endif
#ifndef MICROPROFILE_WEBSERVER_MAXFRAMES
#define MICROPROFILE_WEBSERVER_MAXFRAMES 30
#endif
#ifndef MICROPROFILE_WEBSERVER_SOCKET_BUFFER_SIZE
#define MICROPROFILE_WEBSERVER_SOCKET_BUFFER_SIZE (16<<10)
#endif
#ifndef MICROPROFILE_GPU_TIMERS
#define MICROPROFILE_GPU_TIMERS 1
#endif
#ifndef MICROPROFILE_GPU_FRAME_DELAY
#define MICROPROFILE_GPU_FRAME_DELAY 5 //must be > 0
#endif
#ifndef MICROPROFILE_NAME_MAX_LEN
#define MICROPROFILE_NAME_MAX_LEN 64
#endif
#define MICROPROFILE_FORCEENABLECPUGROUP(s) MicroProfileForceEnableGroup(s, MicroProfileTokenTypeCpu)
#define MICROPROFILE_FORCEDISABLECPUGROUP(s) MicroProfileForceDisableGroup(s, MicroProfileTokenTypeCpu)
#define MICROPROFILE_FORCEENABLEGPUGROUP(s) MicroProfileForceEnableGroup(s, MicroProfileTokenTypeGpu)
#define MICROPROFILE_FORCEDISABLEGPUGROUP(s) MicroProfileForceDisableGroup(s, MicroProfileTokenTypeGpu)
#define MICROPROFILE_INVALID_TICK ((uint64_t)-1)
#define MICROPROFILE_GROUP_MASK_ALL 0xffffffffffff
#define MICROPROFILE_INVALID_TOKEN (uint64_t)-1
enum MicroProfileTokenType
{
MicroProfileTokenTypeCpu,
MicroProfileTokenTypeGpu,
};
enum MicroProfileBoxType
{
MicroProfileBoxTypeBar,
MicroProfileBoxTypeFlat,
};
struct MicroProfile;
struct MicroProfileThreadLogGpu;
MICROPROFILE_API void MicroProfileInit();
MICROPROFILE_API void MicroProfileShutdown();
MICROPROFILE_API MicroProfileToken MicroProfileFindToken(const char* sGroup, const char* sName);
MICROPROFILE_API MicroProfileToken MicroProfileGetToken(const char* sGroup, const char* sName, uint32_t nColor, MicroProfileTokenType Token = MicroProfileTokenTypeCpu);
MICROPROFILE_API MicroProfileToken MicroProfileGetMetaToken(const char* pName);
MICROPROFILE_API MicroProfileToken MicroProfileGetCounterToken(const char* pName);
MICROPROFILE_API void MicroProfileMetaUpdate(MicroProfileToken, int nCount, MicroProfileTokenType eTokenType);
MICROPROFILE_API void MicroProfileCounterAdd(MicroProfileToken nToken, int64_t nCount);
MICROPROFILE_API void MicroProfileCounterSet(MicroProfileToken nToken, int64_t nCount);
MICROPROFILE_API void MicroProfileCounterSetLimit(MicroProfileToken nToken, int64_t nCount);
MICROPROFILE_API void MicroProfileCounterConfig(const char* pCounterName, uint32_t nFormat, int64_t nLimit, uint32_t nFlags);
MICROPROFILE_API void MicroProfileCounterSetPtr(const char* pCounterName, void* pValue, uint32_t nSize);
MICROPROFILE_API void MicroProfileCounterFetchCounters();
MICROPROFILE_API void MicroProfileLocalCounterAdd(int64_t* pCounter, int64_t nCount);
MICROPROFILE_API int64_t MicroProfileLocalCounterSet(int64_t* pCounter, int64_t nCount);
MICROPROFILE_API void MicroProfileLocalCounterAdd(std::atomic<int64_t>* pCounter, int64_t nCount);
MICROPROFILE_API int64_t MicroProfileLocalCounterSet(std::atomic<int64_t>* pCounter, int64_t nCount);
MICROPROFILE_API uint64_t MicroProfileEnter(MicroProfileToken nToken);
MICROPROFILE_API void MicroProfileLeave(MicroProfileToken nToken, uint64_t nTick);
MICROPROFILE_API uint64_t MicroProfileGpuEnter(MicroProfileThreadLogGpu* pLog, MicroProfileToken nToken);
MICROPROFILE_API void MicroProfileGpuLeave(MicroProfileThreadLogGpu* pLog, MicroProfileToken nToken, uint64_t nTick);
MICROPROFILE_API void MicroProfileGpuBegin(void* pContext, MicroProfileThreadLogGpu* pLog);
MICROPROFILE_API void MicroProfileGpuSetContext(void* pContext, MicroProfileThreadLogGpu* pLog);
MICROPROFILE_API uint64_t MicroProfileGpuEnd(MicroProfileThreadLogGpu* pLog);
MICROPROFILE_API MicroProfileThreadLogGpu* MicroProfileThreadLogGpuAlloc();
MICROPROFILE_API void MicroProfileThreadLogGpuFree(MicroProfileThreadLogGpu* pLog);
MICROPROFILE_API void MicroProfileThreadLogGpuReset(MicroProfileThreadLogGpu* pLog);
MICROPROFILE_API void MicroProfileGpuSubmit(int nQueue, uint64_t nWork);
MICROPROFILE_API int MicroProfileInitGpuQueue(const char* pQueueName);
MICROPROFILE_API int MicroProfileGetGpuQueue(const char* pQueueName);
inline uint16_t MicroProfileGetTimerIndex(MicroProfileToken t){ return (t&0xffff); }
inline uint64_t MicroProfileGetGroupMask(MicroProfileToken t){ return ((t>>16)&MICROPROFILE_GROUP_MASK_ALL);}
inline MicroProfileToken MicroProfileMakeToken(uint64_t nGroupMask, uint16_t nTimer){ return (nGroupMask<<16) | nTimer;}
MICROPROFILE_API void MicroProfileFlip(void* pGpuContext); //! call once per frame.
MICROPROFILE_API void MicroProfileTogglePause();
MICROPROFILE_API void MicroProfileForceEnableGroup(const char* pGroup, MicroProfileTokenType Type);
MICROPROFILE_API void MicroProfileForceDisableGroup(const char* pGroup, MicroProfileTokenType Type);
MICROPROFILE_API float MicroProfileGetTime(const char* pGroup, const char* pName);
MICROPROFILE_API bool MicroProfilePlatformMarkersGetEnabled(); //enable platform markers. disables microprofile markers
MICROPROFILE_API void MicroProfilePlatformMarkersSetEnabled(bool bEnabled); //enable platform markers. disables microprofile markers
MICROPROFILE_API void MicroProfileContextSwitchSearch(uint32_t* pContextSwitchStart, uint32_t* pContextSwitchEnd, uint64_t nBaseTicksCpu, uint64_t nBaseTicksEndCpu);
MICROPROFILE_API void MicroProfileOnThreadCreate(const char* pThreadName); //should be called from newly created threads
MICROPROFILE_API void MicroProfileOnThreadExit(); //call on exit to reuse log
MICROPROFILE_API void MicroProfileInitThreadLog();
MICROPROFILE_API void MicroProfileSetForceEnable(bool bForceEnable);
MICROPROFILE_API bool MicroProfileGetForceEnable();
MICROPROFILE_API void MicroProfileSetEnableAllGroups(bool bEnable);
MICROPROFILE_API void MicroProfileEnableCategory(const char* pCategory);
MICROPROFILE_API void MicroProfileDisableCategory(const char* pCategory);
MICROPROFILE_API bool MicroProfileGetEnableAllGroups();
MICROPROFILE_API void MicroProfileSetForceMetaCounters(bool bEnable);
MICROPROFILE_API bool MicroProfileGetForceMetaCounters();
MICROPROFILE_API void MicroProfileEnableMetaCounter(const char* pMet);
MICROPROFILE_API void MicroProfileDisableMetaCounter(const char* pMet);
MICROPROFILE_API void MicroProfileSetAggregateFrames(int frames);
MICROPROFILE_API int MicroProfileGetAggregateFrames();
MICROPROFILE_API int MicroProfileGetCurrentAggregateFrames();
MICROPROFILE_API MicroProfile* MicroProfileGet();
MICROPROFILE_API void MicroProfileGetRange(uint32_t nPut, uint32_t nGet, uint32_t nRange[2][2]);
MICROPROFILE_API std::recursive_mutex& MicroProfileGetMutex();
MICROPROFILE_API void MicroProfileStartContextSwitchTrace();
MICROPROFILE_API void MicroProfileStopContextSwitchTrace();
MICROPROFILE_API bool MicroProfileIsLocalThread(uint32_t nThreadId);
MICROPROFILE_API int MicroProfileFormatCounter(int eFormat, int64_t nCounter, char* pOut, uint32_t nBufferSize);
MICROPROFILE_API MicroProfileThreadLogGpu* MicroProfileGetGlobaGpuThreadLog();
MICROPROFILE_API int MicroProfileGetGlobaGpuQueue();
MICROPROFILE_API void MicroProfileRegisterGroup(const char* pGroup, const char* pCategory, uint32_t nColor);
#if MICROPROFILE_PLATFORM_MARKERS
MICROPROFILE_API void MicroProfilePlatformMarkerBegin(uint32_t nColor, const char * pMarker); //not implemented by microprofile.
MICROPROFILE_API void MicroProfilePlatformMarkerEnd();//not implemented by microprofile.
#endif
// expose some internals - does not work on all platforms
#ifdef MICROPROFILE_EXPOSE_INTERNALS
struct MicroProfileThreadLog;
MICROPROFILE_API MicroProfileThreadLog* MicroProfileGetThreadLog();
#endif
struct MicroProfileThreadInfo
{
//3 first members are used to sort. dont reorder
uint32_t nIsLocal;
MicroProfileThreadIdType pid;
MicroProfileThreadIdType tid;
//3 first members are used to sort. dont reorder
const char* pThreadModule;
const char* pProcessModule;
MicroProfileThreadInfo()
:nIsLocal(0)
,pid(0)
,tid(0)
,pThreadModule("?")
,pProcessModule("?")
{
}
MicroProfileThreadInfo(uint32_t ThreadId, uint32_t ProcessId, uint32_t nIsLocal)
:nIsLocal(nIsLocal)
,pid(ProcessId)
,tid(ThreadId)
,pThreadModule("?")
,pProcessModule("?")
{
}
~MicroProfileThreadInfo() {}
};
MICROPROFILE_API MicroProfileThreadInfo MicroProfileGetThreadInfo(MicroProfileThreadIdType nThreadId);
MICROPROFILE_API uint32_t MicroProfileGetThreadInfoArray(MicroProfileThreadInfo** pThreadArray);
#if defined(MICROPROFILE_GPU_TIMERS_D3D12)
MICROPROFILE_API void MicroProfileGpuInitD3D12(void* pDevice, void* pCommandQueue);
MICROPROFILE_API void MicroProfileGpuShutdown();
#endif
#if MICROPROFILE_WEBSERVER
MICROPROFILE_API void MicroProfileDumpFile(const char* pHtml, const char* pCsv, float fCpuSpike, float fGpuSpike);
MICROPROFILE_API uint32_t MicroProfileWebServerPort();
#else
#define MicroProfileDumpFile(html,csv,cpu, gpu) do{} while(0)
#define MicroProfileWebServerPort() ((uint32_t)-1)
#endif
#if MICROPROFILE_GPU_TIMERS
MICROPROFILE_API uint32_t MicroProfileGpuInsertTimeStamp(void* pContext);
MICROPROFILE_API uint64_t MicroProfileGpuGetTimeStamp(uint32_t nKey);
MICROPROFILE_API uint64_t MicroProfileTicksPerSecondGpu();
MICROPROFILE_API int MicroProfileGetGpuTickReference(int64_t* pOutCPU, int64_t* pOutGpu);
#else
#define MicroProfileGpuInsertTimeStamp(a) 1
#define MicroProfileGpuGetTimeStamp(a) 0
#define MicroProfileTicksPerSecondGpu() 1
#define MicroProfileGetGpuTickReference(a,b) 0
#endif
#if MICROPROFILE_GPU_TIMERS_D3D11
#define MICROPROFILE_D3D_MAX_QUERIES (8<<10)
MICROPROFILE_API void MicroProfileGpuInitD3D11(void* pDevice, void* pDeviceContext);
MICROPROFILE_API void MicroProfileGpuShutdown();
#endif
#if MICROPROFILE_GPU_TIMERS_GL
#define MICROPROFILE_GL_MAX_QUERIES (8<<10)
MICROPROFILE_API void MicroProfileGpuInitGL();
#endif
#if MICROPROFILE_USE_THREAD_NAME_CALLBACK
MICROPROFILE_API const char* MicroProfileGetThreadName(char* pzName);
#else
#define MicroProfileGetThreadName(a) "<implement MicroProfileGetThreadName to get threadnames>"
#endif
struct MicroProfileScopeHandler
{
MicroProfileToken nToken;
uint64_t nTick;
MicroProfileScopeHandler(MicroProfileToken Token):nToken(Token)
{
nTick = MicroProfileEnter(nToken);
}
~MicroProfileScopeHandler()
{
MicroProfileLeave(nToken, nTick);
}
};
struct MicroProfileScopeGpuHandler
{
MicroProfileToken nToken;
MicroProfileThreadLogGpu* pLog;
uint64_t nTick;
MicroProfileScopeGpuHandler(MicroProfileToken Token, MicroProfileThreadLogGpu* pLog):nToken(Token), pLog(pLog)
{
nTick = MicroProfileGpuEnter(pLog, nToken);
}
~MicroProfileScopeGpuHandler()
{
MicroProfileGpuLeave(pLog, nToken, nTick);
}
};
struct MicroProfileInternalThread
{
const char* pThreadName;
uint64_t tid;
};
#define MICROPROFILE_MAX_COUNTERS 512
#define MICROPROFILE_MAX_COUNTER_NAME_CHARS (MICROPROFILE_MAX_COUNTERS*16)
#define MICROPROFILE_MAX_GROUPS 48 //dont bump! no. of bits used it bitmask
#define MICROPROFILE_MAX_CATEGORIES 16
#define MICROPROFILE_MAX_GRAPHS 5
#define MICROPROFILE_GRAPH_HISTORY 128
#define MICROPROFILE_BUFFER_SIZE ((MICROPROFILE_PER_THREAD_BUFFER_SIZE)/sizeof(MicroProfileLogEntry))
#define MICROPROFILE_GPU_BUFFER_SIZE ((MICROPROFILE_PER_THREAD_GPU_BUFFER_SIZE)/sizeof(MicroProfileLogEntry))
#define MICROPROFILE_MAX_CONTEXT_SWITCH_THREADS 256
#define MICROPROFILE_STACK_MAX 32
//#define MICROPROFILE_MAX_PRESETS 5
#define MICROPROFILE_ANIM_DELAY_PRC 0.5f
#define MICROPROFILE_GAP_TIME 50 //extra ms to fetch to close timers from earlier frames
#ifndef MICROPROFILE_MAX_TIMERS
#define MICROPROFILE_MAX_TIMERS 1024
#endif
#ifndef MICROPROFILE_MAX_THREADS
#define MICROPROFILE_MAX_THREADS 256
#endif
#ifndef MICROPROFILE_UNPACK_RED
#define MICROPROFILE_UNPACK_RED(c) ((c)>>16)
#endif
#ifndef MICROPROFILE_UNPACK_GREEN
#define MICROPROFILE_UNPACK_GREEN(c) ((c)>>8)
#endif
#ifndef MICROPROFILE_UNPACK_BLUE
#define MICROPROFILE_UNPACK_BLUE(c) ((c))
#endif
#ifndef MICROPROFILE_DEFAULT_PRESET
#define MICROPROFILE_DEFAULT_PRESET "Default"
#endif
#ifndef MICROPROFILE_CONTEXT_SWITCH_TRACE
#if defined(_WIN32)
#define MICROPROFILE_CONTEXT_SWITCH_TRACE 1
#elif defined(__APPLE__)
#define MICROPROFILE_CONTEXT_SWITCH_TRACE 0 //disabled until dtrace script is working.
#else
#define MICROPROFILE_CONTEXT_SWITCH_TRACE 0
#endif
#endif
#if MICROPROFILE_CONTEXT_SWITCH_TRACE
#define MICROPROFILE_CONTEXT_SWITCH_BUFFER_SIZE (128*1024) //2mb with 16 byte entry size
#else
#define MICROPROFILE_CONTEXT_SWITCH_BUFFER_SIZE (1)
#endif
#ifndef MICROPROFILE_MINIZ
#define MICROPROFILE_MINIZ 0
#endif
#ifndef MICROPROFILE_COUNTER_HISTORY
#define MICROPROFILE_COUNTER_HISTORY 1
#endif
#ifdef _WIN32
#include <basetsd.h>
typedef UINT_PTR MpSocket;
#else
typedef int MpSocket;
#endif
#if defined(__APPLE__) || defined(__linux__)
typedef pthread_t MicroProfileThread;
#elif defined(_WIN32)
#if _MSC_VER >= 1900
typedef void * HANDLE;
#endif
typedef HANDLE MicroProfileThread;
#else
typedef std::thread* MicroProfileThread;
#endif
enum MicroProfileDrawMask
{
MP_DRAW_OFF = 0x0,
MP_DRAW_BARS = 0x1,
MP_DRAW_DETAILED = 0x2,
MP_DRAW_COUNTERS = 0x3,
MP_DRAW_HIDDEN = 0x4,
MP_DRAW_SIZE = 0x5,
};
enum MicroProfileDrawBarsMask
{
MP_DRAW_TIMERS = 0x1,
MP_DRAW_AVERAGE = 0x2,
MP_DRAW_MAX = 0x4,
MP_DRAW_MIN = 0x8,
MP_DRAW_CALL_COUNT = 0x10,
MP_DRAW_TIMERS_EXCLUSIVE = 0x20,
MP_DRAW_AVERAGE_EXCLUSIVE = 0x40,
MP_DRAW_MAX_EXCLUSIVE = 0x80,
MP_DRAW_META_FIRST = 0x100,
MP_DRAW_ALL = 0xffffffff,
};
enum MicroProfileCounterFormat
{
MICROPROFILE_COUNTER_FORMAT_DEFAULT,
MICROPROFILE_COUNTER_FORMAT_BYTES,
};
enum MicroProfileCounterFlags
{
MICROPROFILE_COUNTER_FLAG_NONE = 0,
MICROPROFILE_COUNTER_FLAG_DETAILED = 0x1,
MICROPROFILE_COUNTER_FLAG_DETAILED_GRAPH= 0x2,
//internal:
MICROPROFILE_COUNTER_FLAG_INTERNAL_MASK = ~0x3,
MICROPROFILE_COUNTER_FLAG_HAS_LIMIT = 0x4,
MICROPROFILE_COUNTER_FLAG_CLOSED = 0x8,
MICROPROFILE_COUNTER_FLAG_MANUAL_SWAP = 0x10,
MICROPROFILE_COUNTER_FLAG_LEAF = 0x20,
};
typedef uint64_t MicroProfileLogEntry;
struct MicroProfileTimer
{
uint64_t nTicks;
uint32_t nCount;
};
struct MicroProfileCategory
{
char pName[MICROPROFILE_NAME_MAX_LEN];
uint64_t nGroupMask;
};
struct MicroProfileGroupInfo
{
char pName[MICROPROFILE_NAME_MAX_LEN];
uint32_t nNameLen;
uint32_t nGroupIndex;
uint32_t nNumTimers;
uint32_t nMaxTimerNameLen;
uint32_t nColor;
uint32_t nCategory;
MicroProfileTokenType Type;
};
struct MicroProfileTimerInfo
{
MicroProfileToken nToken;
uint32_t nTimerIndex;
uint32_t nGroupIndex;
char pName[MICROPROFILE_NAME_MAX_LEN];
char pNameExt[MICROPROFILE_NAME_MAX_LEN];
uint32_t nNameLen;
uint32_t nColor;
bool bGraph;
};
struct MicroProfileCounterInfo
{
int nParent;
int nSibling;
int nFirstChild;
uint16_t nNameLen;
uint8_t nLevel;
char* pName;
uint32_t nFlags;
int64_t nLimit;
MicroProfileCounterFormat eFormat;
};
struct MicroProfileCounterHistory
{
uint32_t nPut;
uint64_t nHistory[MICROPROFILE_GRAPH_HISTORY];
};
struct MicroProfileCounterSource
{
void* pSource;
uint32_t nSourceSize;
};
struct MicroProfileGraphState
{
int64_t nHistory[MICROPROFILE_GRAPH_HISTORY];
MicroProfileToken nToken;
int32_t nKey;
};
struct MicroProfileContextSwitch
{
MicroProfileThreadIdType nThreadOut;
MicroProfileThreadIdType nThreadIn;
int64_t nCpu : 8;
int64_t nTicks : 56;
};
struct MicroProfileFrameState
{
int64_t nFrameStartCpu;
int64_t nFrameStartGpu;
uint32_t nLogStart[MICROPROFILE_MAX_THREADS];
};
struct MicroProfileThreadLog
{
MicroProfileLogEntry Log[MICROPROFILE_BUFFER_SIZE];
std::atomic<uint32_t> nPut;
std::atomic<uint32_t> nGet;
uint32_t nStackPut;
uint32_t nActive;
uint32_t nGpu;
MicroProfileThreadIdType nThreadId;
uint32_t nLogIndex;
uint32_t nStack[MICROPROFILE_STACK_MAX];
int64_t nChildTickStack[MICROPROFILE_STACK_MAX];
uint32_t nStackPos;
uint8_t nGroupStackPos[MICROPROFILE_MAX_GROUPS];
int64_t nGroupTicks[MICROPROFILE_MAX_GROUPS];
int64_t nAggregateGroupTicks[MICROPROFILE_MAX_GROUPS];
enum
{
THREAD_MAX_LEN = 64,
};
char ThreadName[64];
int nFreeListNext;
};
//linear, per-frame per-thread gpu log
struct MicroProfileThreadLogGpu
{
MicroProfileLogEntry Log[MICROPROFILE_GPU_BUFFER_SIZE];
uint32_t nPut;
uint32_t nStart;
uint32_t nId;
void* pContext;
uint32_t nAllocated;
};
#if MICROPROFILE_GPU_TIMERS_D3D11
struct MicroProfileD3D11Frame
{
uint32_t m_nQueryStart;
uint32_t m_nQueryCount;
uint32_t m_nRateQueryStarted;
void* m_pRateQuery;
};
struct MicroProfileGpuTimerState
{
uint32_t bInitialized;
void* m_pDevice;
void* m_pDeviceContext;
void* m_pQueries[MICROPROFILE_D3D_MAX_QUERIES];
int64_t m_nQueryResults[MICROPROFILE_D3D_MAX_QUERIES];
uint32_t m_nQueryPut;
uint32_t m_nQueryGet;
uint32_t m_nQueryFrame;
int64_t m_nQueryFrequency;
void* pSyncQuery;
MicroProfileD3D11Frame m_QueryFrames[MICROPROFILE_GPU_FRAME_DELAY];
};
#elif defined(MICROPROFILE_GPU_TIMERS_D3D12)
#include <d3d12.h>
#ifndef MICROPROFILE_D3D_MAX_QUERIES
#define MICROPROFILE_D3D_MAX_QUERIES (32<<10)
#endif
#define MICROPROFILE_D3D_INTERNAL_DELAY 8
struct MicroProfileD3D12Frame
{
uint32_t nBegin;
uint32_t nCount;
ID3D12GraphicsCommandList* pCommandList;
ID3D12CommandAllocator* pCommandAllocator;
};
struct MicroProfileGpuTimerState
{
uint64_t nFrame;
uint64_t nPendingFrame;
uint32_t nFrameStart;
std::atomic<uint32_t> nFrameCount;
int64_t nFrequency;
ID3D12CommandQueue* pCommandQueue;
ID3D12QueryHeap* pHeap;
ID3D12Fence* pFence;
ID3D12Device* pDevice;
ID3D12Resource* pBuffer;
uint16_t nQueryFrames[MICROPROFILE_D3D_MAX_QUERIES];
int64_t nResults[MICROPROFILE_D3D_MAX_QUERIES];
MicroProfileD3D12Frame Frames[MICROPROFILE_D3D_INTERNAL_DELAY];
};
#elif MICROPROFILE_GPU_TIMERS_GL
struct MicroProfileGpuTimerState
{
uint32_t GLTimers[MICROPROFILE_GL_MAX_QUERIES];
uint32_t GLTimerPos;
};
#else
struct MicroProfileGpuTimerState{};
#endif
struct MicroProfile
{
uint32_t nTotalTimers;
uint32_t nGroupCount;
uint32_t nCategoryCount;
uint32_t nAggregateClear;
uint32_t nAggregateFlip;
uint32_t nAggregateFlipCount;
uint32_t nAggregateFrames;
uint64_t nAggregateFlipTick;
uint32_t nDisplay;
uint32_t nBars;
uint64_t nActiveGroup;
uint32_t nActiveBars;
uint32_t nPlatformMarkersEnabled;
uint64_t nForceGroup;
uint32_t nForceEnable;
uint32_t nForceMetaCounters;
uint64_t nForceGroupUI;
uint64_t nActiveGroupWanted;
uint32_t nAllGroupsWanted;
uint32_t nAllThreadsWanted;
uint32_t nOverflow;
uint64_t nGroupMask;
uint32_t nRunning;
uint32_t nToggleRunning;
uint32_t nMaxGroupSize;
uint32_t nDumpFileNextFrame;
uint32_t nDumpFileCountDown;
uint32_t nDumpSpikeMask;
uint32_t nAutoClearFrames;
float fDumpCpuSpike;
float fDumpGpuSpike;
char HtmlDumpPath[512];