improve time profiling
parent
3b56791bec
commit
c93e5e4e46
|
@ -2,6 +2,7 @@
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
PROF_TOTAL_TIME,
|
||||||
PROF_MAIN_LOOP,
|
PROF_MAIN_LOOP,
|
||||||
|
|
||||||
PROF_WORLD_WRITE,
|
PROF_WORLD_WRITE,
|
||||||
|
|
|
@ -84,6 +84,7 @@ static debug_item items[] = {
|
||||||
.list = {
|
.list = {
|
||||||
.items = (debug_item[]) {
|
.items = (debug_item[]) {
|
||||||
{ .kind = DITEM_RAW, .val = PROF_MAIN_LOOP, .proc = DrawProfilerDelta },
|
{ .kind = DITEM_RAW, .val = PROF_MAIN_LOOP, .proc = DrawProfilerDelta },
|
||||||
|
{ .kind = DITEM_TEXT, .name = "unmesasured time", .proc = DrawUnmeasuredTime },
|
||||||
{ .kind = DITEM_RAW, .val = PROF_WORLD_WRITE, .proc = DrawProfilerDelta },
|
{ .kind = DITEM_RAW, .val = PROF_WORLD_WRITE, .proc = DrawProfilerDelta },
|
||||||
{ .kind = DITEM_RAW, .val = PROF_RENDER, .proc = DrawProfilerDelta },
|
{ .kind = DITEM_RAW, .val = PROF_RENDER, .proc = DrawProfilerDelta },
|
||||||
{ .kind = DITEM_RAW, .val = PROF_UPDATE_SYSTEMS, .proc = DrawProfilerDelta },
|
{ .kind = DITEM_RAW, .val = PROF_UPDATE_SYSTEMS, .proc = DrawProfilerDelta },
|
||||||
|
|
|
@ -28,6 +28,15 @@ DrawColoredText(float xpos, float ypos, char const *text, Color color) {
|
||||||
|
|
||||||
//~ NOTE(zaklaus): widgets
|
//~ NOTE(zaklaus): widgets
|
||||||
|
|
||||||
|
static inline debug_draw_result
|
||||||
|
DrawUnmeasuredTime(debug_item *it, float xpos, float ypos) {
|
||||||
|
(void)it;
|
||||||
|
float total_time = profiler_delta(PROF_TOTAL_TIME);
|
||||||
|
float acc_time = profiler_delta(PROF_MAIN_LOOP);
|
||||||
|
|
||||||
|
return DrawFormattedText(xpos, ypos, TextFormat("%.02f ms", (total_time-acc_time) * 1000.0f));
|
||||||
|
}
|
||||||
|
|
||||||
static inline debug_draw_result
|
static inline debug_draw_result
|
||||||
DrawDeltaTime(debug_item *it, float xpos, float ypos) {
|
DrawDeltaTime(debug_item *it, float xpos, float ypos) {
|
||||||
(void)it;
|
(void)it;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
// NOTE(zaklaus): KEEP ORDER IN SYNC WITH profiler_kind ENUM !!!
|
// NOTE(zaklaus): KEEP ORDER IN SYNC WITH profiler_kind ENUM !!!
|
||||||
static profiler profilers[] = {
|
static profiler profilers[] = {
|
||||||
|
{ .id = PROF_TOTAL_TIME, .name = "measured time" },
|
||||||
{ .id = PROF_MAIN_LOOP, .name = "main loop" },
|
{ .id = PROF_MAIN_LOOP, .name = "main loop" },
|
||||||
{ .id = PROF_WORLD_WRITE, .name = "world write" },
|
{ .id = PROF_WORLD_WRITE, .name = "world write" },
|
||||||
{ .id = PROF_RENDER, .name = "render" },
|
{ .id = PROF_RENDER, .name = "render" },
|
||||||
|
@ -33,16 +34,21 @@ void profiler_stop(profiler_kind id) {
|
||||||
|
|
||||||
void profiler_collate() {
|
void profiler_collate() {
|
||||||
static double frame_counter = 0.0;
|
static double frame_counter = 0.0;
|
||||||
|
static uint64_t frames = 0;
|
||||||
|
|
||||||
frame_counter += GetFrameTime();
|
frame_counter += GetFrameTime();
|
||||||
|
frames++;
|
||||||
|
|
||||||
if (frame_counter >= PROF_COLLATE_WINDOW) {
|
if (frame_counter >= PROF_COLLATE_WINDOW) {
|
||||||
for (uint32_t i = 0; i < MAX_PROF; i += 1) {
|
profilers[PROF_TOTAL_TIME].delta_time = frame_counter / (double)frames;
|
||||||
|
|
||||||
|
for (uint32_t i = PROF_MAIN_LOOP; i < MAX_PROF; i += 1) {
|
||||||
profiler *p = &profilers[i];
|
profiler *p = &profilers[i];
|
||||||
p->delta_time = p->num_invocations == 0 ? 0.0 : p->total_time / (double)p->num_invocations;
|
p->delta_time = p->num_invocations == 0 ? 0.0 : p->total_time / (double)p->num_invocations;
|
||||||
}
|
}
|
||||||
|
|
||||||
frame_counter = 0.0;
|
frame_counter = 0.0;
|
||||||
|
frames = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue