-
Notifications
You must be signed in to change notification settings - Fork 1
/
profiling.h
75 lines (62 loc) · 2.08 KB
/
profiling.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
#ifndef PROFILING_H
#define PROFILING_H
#include <proto/timer.h>
typedef struct ProfilingItem
{
uint64 ticks;
uint64 callCount;
uint64 errors;
uint64 nullptrs;
int index; // Only for qsorting
} ProfilingItem;
typedef struct MyClock {
union {
uint64 ticks;
struct EClockVal clockVal;
};
} MyClock;
typedef struct PrimitiveCounter {
uint64 triangles;
uint64 triangleStrips;
uint64 triangleFans;
uint64 lines;
uint64 lineStrips;
uint64 lineLoops;
uint64 points;
} PrimitiveCounter;
#define PROF_INIT(context, LAST_INDEX) \
ITimer->ReadEClock(&context->start.clockVal); \
context->ticks = 0; \
for (int item = 0; item < LAST_INDEX; item++) { \
ProfilingItem *pi = &context->profiling[item]; \
pi->ticks = 0; \
pi->callCount = 0; \
pi->errors = 0; \
pi->index = item; \
}
#define PROF_START \
struct MyClock start, finish; \
ITimer->ReadEClock(&start.clockVal);
#define PROF_FINISH(func) \
ITimer->ReadEClock(&finish.clockVal); \
const uint64 duration = finish.ticks - start.ticks; \
context->ticks += duration; \
context->profiling[func].ticks += duration; \
context->profiling[func].callCount++;
#define PROF_FINISH_CONTEXT \
MyClock finish; \
ITimer->ReadEClock(&finish.clockVal); \
const uint64 totalTicks = finish.ticks - context->start.ticks; \
const double seconds = timer_ticks_to_s(totalTicks);
#define PROF_PRINT_TOTAL \
const double timeUsed = timer_ticks_to_ms(context->ticks); \
char timeUsedBuffer[32]; \
snprintf(timeUsedBuffer, sizeof(timeUsedBuffer), "%% of %.6f ms", timeUsed); \
logAlways(" Function calls used %.6f ms, %.2f %% of context life-time %.6f ms", \
timeUsed, \
(double)context->ticks * 100.0 / (double)totalTicks, \
timer_ticks_to_ms(totalTicks));
int tickComparison(const void* first, const void* second);
void sort(ProfilingItem* items, const unsigned count);
void primitiveStats(const PrimitiveCounter* const counter, const double seconds, const double drawcalls);
#endif