| 228 | } |
| 229 | |
| 230 | void ScriptConsole::sampleIoRate(void) |
| 231 | { |
| 232 | // The window closes twice a second: often enough to react to a stall, |
| 233 | // seldom enough that the figure on screen is a speed and not a flicker. |
| 234 | // The clock read itself is per call — it lands on the copy loop, so keep |
| 235 | // this function to exactly that one syscall-free read and no allocation. |
| 236 | const auto now = std::chrono::steady_clock::now(); |
| 237 | const double secs = std::chrono::duration<double>(now - mIoRateAt).count(); |
| 238 | if (secs < 0.5) { |
| 239 | return; |
| 240 | } |
| 241 | const double sample = (double)(mIo.done - mIoRateDone) / secs; |
| 242 | // Smoothed, or the figure jitters by megabytes between frames and reads as |
| 243 | // noise rather than as a speed. |
| 244 | mIo.rate = mIo.rate > 0.0 ? mIo.rate * 0.6 + sample * 0.4 : sample; |
| 245 | mIoRateAt = now; |
| 246 | mIoRateDone = mIo.done; |
| 247 | } |
| 248 | |
| 249 | void ScriptConsole::setIo(long long done) |
| 250 | { |