]>
git.bts.cx Git - benzene.git/blob - src/bz/debug/perfgraph.c
1 #include <bz/debug/perfgraph_internal.h>
3 #include <bz/types/common.h>
4 #include <bz/gfx/gfx.h>
6 extern void resetSystemTimer(void);
7 extern float getSystemTimer(void);
10 const char *identifier
;
14 typedef struct BZPerfTimer BZPerfTimer
;
16 BZPerfTimer perfTimers
[32];
21 for (size_t i
= 0; i
< 32; ++i
) { // FIXME
22 perfTimers
[i
].identifier
= NULL
;
23 perfTimers
[i
].elapsedTime
= 0.0f
;
27 static BZPerfTimer
*bzPerfTimerFind(const char *identifier
) {
28 BZPerfTimer
*timer
= NULL
;
30 for (size_t i
= 0; i
< 32; ++i
) {
31 if (perfTimers
[i
].identifier
== NULL
&& timer
== NULL
) {
32 timer
= &perfTimers
[i
];
33 } else if (perfTimers
[i
].identifier
== identifier
) {
34 timer
= &perfTimers
[i
];
39 bzAssert(timer
!= NULL
);
43 void _bzPerfTimerStart(const char *identifier
) {
44 BZPerfTimer
*timer
= bzPerfTimerFind(identifier
);
45 timer
->identifier
= identifier
;
46 timer
->startTime
= getSystemTimer();
49 void _bzPerfTimerStop(const char *identifier
) {
50 float endTime
= getSystemTimer();
51 BZPerfTimer
*timer
= bzPerfTimerFind(identifier
);
52 timer
->elapsedTime
+= endTime
- timer
->startTime
;
55 void _bzPerfTimerOutput() {
56 for (size_t i
= 0; i
< 32; ++i
) {
57 if (perfTimers
[i
].identifier
!= NULL
) {
58 bzLog("Timer '%s': %fs", perfTimers
[i
].identifier
, perfTimers
[i
].elapsedTime
);
63 void _bzPerfTimerDraw() {
66 for (size_t i
= 0; i
< 32; ++i
) {
67 if (perfTimers
[i
].identifier
!= NULL
) {
68 bzRectFill(10, y
, 10 + width
, y
+3, 5);
69 float t
= perfTimers
[i
].elapsedTime
/ (1 / 30.0f
);
70 bzRectFill(10, y
, 10 + width
* t
, y
+ 3, 8);
71 bzPrint(10 + width
, y
, 7, perfTimers
[i
].identifier
);