Update the timer code to support profiling loops and recursive functions

This commit is contained in:
2023-07-09 22:13:06 +01:00
parent a118afaffb
commit 6b9a7ab8a5
2 changed files with 94 additions and 32 deletions

View File

@@ -8,12 +8,12 @@
#endif // !MAX_PROFILE_SAMPLES
#ifdef ENABLE_PROFILING
#define PROFILE_START profile_start()
#define PROFILE_START(COUNT) profile_start(COUNT)
#define PROFILE_END profile_end()
#define SAMPLE_START(ID, TITLE) profiler_sample_t ID = sample_start(TITLE)
#define SAMPLE_END(ID) sample_end(&ID)
#define SAMPLE_START(ID, TITLE) sample_start(ID, TITLE)
#define SAMPLE_END(ID) sample_end(ID)
#else
#define PROFILE_START
#define PROFILE_START(COUNT)
#define PROFILE_END
#define SAMPLE_START(ID, TITLE)
#define SAMPLE_END(ID)
@@ -23,11 +23,16 @@
extern "C" {
#endif
typedef struct {
typedef struct sample profiler_sample_t;
struct sample {
const char *title;
u64 start;
u64 end;
} profiler_sample_t;
u64 duration;
u64 children_duration;
u64 hit_count;
profiler_sample_t *parent;
};
u64 get_os_frequency();
@@ -40,11 +45,11 @@ u64 read_cpu_timer(void);
// CPU frequency in hz/sec
u64 get_cpu_freq(u64 milliseconds);
void profile_start();
void profile_start(u64 count);
void profile_end();
profiler_sample_t sample_start(const char *title);
void sample_end(profiler_sample_t *sample);
void sample_start(u64 id, const char *title);
void sample_end(u64 id);
#ifdef __cplusplus
}