| 386 | } |
| 387 | |
| 388 | void |
| 389 | EThread::Metrics::summarize(Metrics &global) |
| 390 | { |
| 391 | // Accumulate in local first so each sample only needs to be processed once, |
| 392 | // not N_EVENT_TIMESCALES times. |
| 393 | Slice sum; |
| 394 | |
| 395 | // To avoid race conditions, we back up one from the current metric block. It's close enough |
| 396 | // and won't be updated during the time this method runs so it should be thread safe. |
| 397 | // The acquire fence ensures we see all the preceeding updates to the previous slice. |
| 398 | Slice *slice = this->prev_slice(current_slice.load(std::memory_order_acquire)); |
| 399 | |
| 400 | for (unsigned t = 0; t < N_TIMESCALES; ++t) { |
| 401 | int count = SLICE_SAMPLE_COUNT[t]; |
| 402 | if (t > 0) { |
| 403 | count -= SLICE_SAMPLE_COUNT[t - 1]; |
| 404 | } |
| 405 | while (--count >= 0) { |
| 406 | if (0 != slice->_duration._start) { |
| 407 | sum += *slice; |
| 408 | } |
| 409 | slice = this->prev_slice(slice); |
| 410 | } |
| 411 | global._slice[t] += sum; // push out to return vector. |
| 412 | } |
| 413 | |
| 414 | // Only summarize if there's no outstanding decay. |
| 415 | if (0 == _decay_count) { |
| 416 | global._loop_timing += _loop_timing; |
| 417 | global._api_timing += _api_timing; |
| 418 | } |
| 419 | } |
no test coverage detected