77 lines
1.4 KiB
C
77 lines
1.4 KiB
C
#ifndef TIMER_H
|
|
#define TIMER_H
|
|
|
|
#include "aliases.h"
|
|
|
|
#ifndef MAX_PROFILE_SAMPLES
|
|
#define MAX_PROFILE_SAMPLES 1024
|
|
#endif // !MAX_PROFILE_SAMPLES
|
|
|
|
#ifdef FULL_PROFILING
|
|
#define SAMPLE_START(ID, TITLE) sample_start(ID, TITLE)
|
|
#define SAMPLE_END(ID, BYTES) sample_end(ID, BYTES)
|
|
#define SAMPLE_END_DEFAULT(ID) sample_end(ID, 0)
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
void sample_start(u64 id, const char *title);
|
|
void sample_end(u64 id, u64 byte_count);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#else
|
|
#define SAMPLE_START(ID, TITLE)
|
|
#define SAMPLE_END(ID, BYTES)
|
|
#define SAMPLE_END_DEFAULT(ID)
|
|
#endif // FULL_PROFILING
|
|
|
|
#if defined(BASIC_PROFILING) || defined(FULL_PROFILING)
|
|
#define PROFILE_START(COUNT) profile_start(COUNT)
|
|
#define PROFILE_END profile_end()
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef struct sample profiler_sample_t;
|
|
|
|
struct sample {
|
|
const char *title;
|
|
u64 first_start;
|
|
u64 start;
|
|
u64 exclusive_time;
|
|
u64 children_time;
|
|
u64 hit_count;
|
|
u64 byte_count;
|
|
profiler_sample_t *parent;
|
|
};
|
|
|
|
u64 get_os_frequency();
|
|
|
|
// Time in nanoseconds
|
|
u64 get_os_time(void);
|
|
|
|
// CPU timer using rdtsc
|
|
u64 read_cpu_timer(void);
|
|
|
|
// CPU frequency in hz/sec
|
|
u64 get_cpu_freq(u64 milliseconds);
|
|
|
|
void profile_start(u64 count);
|
|
void profile_end();
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#else
|
|
#define PROFILE_START(COUNT)
|
|
#define PROFILE_END
|
|
#endif // BASIC_PROFILING || FULL_PROFILING
|
|
|
|
#endif // !TIMER_H
|