Get current rate of a performance element, based on approximately the past one second of data */
| 151 | |
| 152 | /** Get current rate of a performance element, based on approximately the past one second of data */ |
| 153 | double GetRate() |
| 154 | { |
| 155 | /* Start at last recorded point, end at latest when reaching the earliest recorded point */ |
| 156 | int point = this->prev_index; |
| 157 | int last_point = this->next_index - this->num_valid; |
| 158 | if (last_point < 0) last_point += NUM_FRAMERATE_POINTS; |
| 159 | |
| 160 | /* Number of data points collected */ |
| 161 | int count = 0; |
| 162 | /* Time of previous data point */ |
| 163 | TimingMeasurement last = this->timestamps[point]; |
| 164 | /* Total duration covered by collected points */ |
| 165 | TimingMeasurement total = 0; |
| 166 | |
| 167 | /* We have nothing to compare the first point against */ |
| 168 | point--; |
| 169 | if (point < 0) point = NUM_FRAMERATE_POINTS - 1; |
| 170 | |
| 171 | while (point != last_point) { |
| 172 | /* Only record valid data points, but pretend the gaps in measurements aren't there */ |
| 173 | if (this->durations[point] != INVALID_DURATION) { |
| 174 | total += last - this->timestamps[point]; |
| 175 | count++; |
| 176 | } |
| 177 | last = this->timestamps[point]; |
| 178 | if (total >= TIMESTAMP_PRECISION) break; // end after 1 second has been collected |
| 179 | point--; |
| 180 | if (point < 0) point = NUM_FRAMERATE_POINTS - 1; |
| 181 | } |
| 182 | |
| 183 | if (total == 0 || count == 0) return 0; |
| 184 | return (double)count * TIMESTAMP_PRECISION / total; |
| 185 | } |
| 186 | }; |
| 187 | |
| 188 | /** %Game loop rate, cycles per second */ |
no outgoing calls
no test coverage detected