Can use in any process, not just the core engine processes.
class FramePacer {
vector\<string> checkpoint_names;
vector\<CheckpointStats> checkpoint_stats;
Stat\<float> metric_too_expensive_to_retrieve_every_checkpoint?;//maybe temperatures?
//Any of these function calls might sleep or busy wait if you're ahead of schedule if the frame pacing control is enabled
void StartFrame(float wait_multiplier, float target_frame_time);//doesn't have to be a frame, just the largest unit of work
void EndFrame(float wait_multiplier);
void StartCheckpoint(int id, float wait_multiplier);
void EndCheckpoint(int id, float wait_multiplier);
//wait_multiplier multiplies the amount of time to wait to maintain frame pacing, 0 of course means never wait. A value greater than 1.0 would rarely be useful unless you know that a certain frame is going to be too fast for some reason? If you know the frame is going to be too fast before you take input then wouldn't you just do a sleep for a set amount of time outside of this function?
//Or maybe I just need a Split function that works like live split and automatically keeps track of what checkpoint you're on? Or maybe keep the explicit StartFrame and EndFrame but inside of that just use a split function?
//Maybe I should provide a sleep function in this class so it can intelligently track it and determine if it should busy wait or sleep?
void Sleep(float ms);
};
template\<class T>//or maybe just always float?
class Stat {
T avg;
T lowest;
T highest;
T one_percent_low;
T one_percent_high;
};
class CheckpointStats {
Stat\<float> time_ms;
Stat\<int> cache_misses;
Stat\<int> cache_hits;
Stat\<float> cache_hit_rate;
Stat\<int> instructions_executed;
Stat\<int> cycles_executed;
Stat\<int> branches;
Stat\<float> gpu_load;
//Temperatures? Clock speeds? Some stats might be too expensive to retrieve every checkpoint?
};
Could I try to determine the cause of a hiccup? If it was GPU time, or which thread didn't get enough CPU time, if there were more cache misses than the average frame, maybe CPU clock speed changed, maybe something else on the system was using the CPU
Maybe with BTS I could count how many instructions were executed to see if a frame executed more instructions than average, or if more jumps were executed than average? It sounds like enabling it slows things down a lot though. https://stackoverflow.com/a/4531402
The FramePacer class could also determine how long certain checkpoints took to run for the frame. It might also be able to track all those other metrics per checkpoint. Imagine it telling you which part of the frame caused the extra cache misses that caused the stutter.
Maybe target_frame_time should be a member instead of function argument? Checkpoints could return how ahead/behind schedule they are/were? But if it sleeps when ahead, how will the program adapt to being ahead of schedule?
Can use in any process, not just the core engine processes.
class FramePacer { vector\<string> checkpoint_names; vector\<CheckpointStats> checkpoint_stats; Stat\<float> metric_too_expensive_to_retrieve_every_checkpoint?;//maybe temperatures?
//Any of these function calls might sleep or busy wait if you're ahead of schedule if the frame pacing control is enabled void StartFrame(float wait_multiplier, float target_frame_time);//doesn't have to be a frame, just the largest unit of work
void EndFrame(float wait_multiplier);
void StartCheckpoint(int id, float wait_multiplier); void EndCheckpoint(int id, float wait_multiplier); //wait_multiplier multiplies the amount of time to wait to maintain frame pacing, 0 of course means never wait. A value greater than 1.0 would rarely be useful unless you know that a certain frame is going to be too fast for some reason? If you know the frame is going to be too fast before you take input then wouldn't you just do a sleep for a set amount of time outside of this function? //Or maybe I just need a Split function that works like live split and automatically keeps track of what checkpoint you're on? Or maybe keep the explicit StartFrame and EndFrame but inside of that just use a split function?
//Maybe I should provide a sleep function in this class so it can intelligently track it and determine if it should busy wait or sleep? void Sleep(float ms); };
template\<class T>//or maybe just always float? class Stat { T avg; T lowest; T highest; T one_percent_low; T one_percent_high; };
class CheckpointStats { Stat\<float> time_ms; Stat\<int> cache_misses; Stat\<int> cache_hits; Stat\<float> cache_hit_rate; Stat\<int> instructions_executed; Stat\<int> cycles_executed; Stat\<int> branches; Stat\<float> gpu_load; //Temperatures? Clock speeds? Some stats might be too expensive to retrieve every checkpoint? };
Could I try to determine the cause of a hiccup? If it was GPU time, or which thread didn't get enough CPU time, if there were more cache misses than the average frame, maybe CPU clock speed changed, maybe something else on the system was using the CPU
Maybe with BTS I could count how many instructions were executed to see if a frame executed more instructions than average, or if more jumps were executed than average? It sounds like enabling it slows things down a lot though. https://stackoverflow.com/a/4531402
The FramePacer class could also determine how long certain checkpoints took to run for the frame. It might also be able to track all those other metrics per checkpoint. Imagine it telling you which part of the frame caused the extra cache misses that caused the stutter.
Maybe target_frame_time should be a member instead of function argument? Checkpoints could return how ahead/behind schedule they are/were? But if it sleeps when ahead, how will the program adapt to being ahead of schedule?