Updates the CPU usage using the last 100 seconds data.

This commit is contained in:
Andrea Mazzoleni 2014-09-09 22:33:09 +02:00
parent b8e25228f4
commit 0b372da80e
3 changed files with 16 additions and 5 deletions

View file

@ -4,7 +4,7 @@ SnapRAID HISTORY
6.4 2014/9
==========
* Keeps and print the time spent waiting for each disk also in 'scrub'.
* The speed and ETA estimations are now based on the last 100
* The CPU usage, speed and ETA estimations are now based on the last 100
seconds rather than from the start.
6.3 2014/7

View file

@ -4346,12 +4346,12 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off
/* if the previous measure is different */
if (state->progress_tick == 0 || state->progress_time[pred] != now) {
uint64_t tick_total;
printf("%u%%, %u MiB", countpos * 100 / countmax, (unsigned)(countsize / (1024*1024)));
uint64_t tick_cpu;
tick_total = state->tick_cpu + state->tick_io;
if (tick_total != 0)
printf(", CPU %"PRIu64"%%", state->tick_cpu * 100U / tick_total);
tick_cpu = state->tick_cpu;
printf("%u%%, %u MiB", countpos * 100 / countmax, (unsigned)(countsize / (1024*1024)));
/* if we have at least 5 measures */
if (state->progress_tick >= 5) {
@ -4360,6 +4360,8 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off
time_t delta_time;
block_off_t delta_pos;
data_off_t delta_size;
uint64_t delta_tick_total;
uint64_t delta_tick_cpu;
/* number of past measures */
past = state->progress_tick;
@ -4383,10 +4385,15 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off
delta_time = now - state->progress_time[oldest];
delta_pos = countpos - state->progress_pos[oldest];
delta_size = countsize - state->progress_size[oldest];
delta_tick_total = tick_total - state->progress_tick_total[oldest];
delta_tick_cpu = tick_cpu - state->progress_tick_cpu[oldest];
if (delta_time != 0)
printf(", %u MiB/s", (unsigned)(delta_size / (1024*1024) / delta_time));
if (delta_tick_total != 0)
printf(", CPU %"PRIu64"%%", delta_tick_cpu * 100U / delta_tick_total);
/* estimate the remaining time */
if (delta_pos != 0) {
unsigned m, h;
@ -4407,6 +4414,8 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off
state->progress_time[state->progress_ptr] = now;
state->progress_pos[state->progress_ptr] = countpos;
state->progress_size[state->progress_ptr] = countsize;
state->progress_tick_cpu[state->progress_ptr] = tick_cpu;
state->progress_tick_total[state->progress_ptr] = tick_total;
/* next position */
++state->progress_ptr;

View file

@ -171,6 +171,8 @@ struct snapraid_state {
time_t progress_time[PROGRESS_MAX]; /**< Last times of progress. */
block_off_t progress_pos[PROGRESS_MAX]; /**< Last positions of progress. */
data_off_t progress_size[PROGRESS_MAX]; /**< Last sizes of progress. */
uint64_t progress_tick_cpu[PROGRESS_MAX]; /**< Last cpu ticks of progress. */
uint64_t progress_tick_total[PROGRESS_MAX]; /**< Last total ticks of progress. */
int progress_ptr; /**< Pointer to the next position to fill. Rolling over. */
int progress_tick; /**< Number of measures done. */