+
+ if (now >= coverage_run_time) {
+ size_t i, j;
+ /* Computes the number of COVERAGE_RUN_INTERVAL slots, since
+ * it is possible that the actual run interval is multiple of
+ * COVERAGE_RUN_INTERVAL. */
+ int slots = (now - coverage_run_time) / COVERAGE_RUN_INTERVAL + 1;
+
+ for (i = 0; i < n_coverage_counters; i++) {
+ unsigned int count, portion;
+ unsigned int m_idx = min_idx;
+ unsigned int h_idx = hr_idx;
+ unsigned int idx = idx_count;
+
+ /* Computes the differences between the current total and the one
+ * recorded in last invocation of coverage_run(). */
+ count = c[i]->total - c[i]->last_total;
+ c[i]->last_total = c[i]->total;
+ /* The count over the time interval is evenly distributed
+ * among slots by calculating the portion. */
+ portion = count / slots;
+
+ for (j = 0; j < slots; j++) {
+ /* Updates the index variables. */
+ /* The m_idx is increased from 0 to MIN_AVG_LEN - 1. Every
+ * time the m_idx finishes a cycle (a cycle is one minute),
+ * the h_idx is incremented by 1. */
+ m_idx = idx % MIN_AVG_LEN;
+ h_idx = idx / MIN_AVG_LEN;
+
+ c[i]->min[m_idx] = portion + (j == (slots - 1)
+ ? count % slots : 0);
+ c[i]->hr[h_idx] = m_idx == 0
+ ? c[i]->min[m_idx]
+ : (c[i]->hr[h_idx] + c[i]->min[m_idx]);
+ /* This is to guarantee that h_idx ranges from 0 to 59. */
+ idx = (idx + 1) % (MIN_AVG_LEN * HR_AVG_LEN);