From 0b372da80e5e5fee5e24a5877d73daefe24b72fe Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Tue, 9 Sep 2014 22:33:09 +0200 Subject: [PATCH] Updates the CPU usage using the last 100 seconds data. --- HISTORY | 2 +- cmdline/state.c | 17 +++++++++++++---- cmdline/state.h | 2 ++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/HISTORY b/HISTORY index 7be333e5..23575fbc 100644 --- a/HISTORY +++ b/HISTORY @@ -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 diff --git a/cmdline/state.c b/cmdline/state.c index 0d9cc922..43e0ec47 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -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; diff --git a/cmdline/state.h b/cmdline/state.h index b61af92b..71921428 100644 --- a/cmdline/state.h +++ b/cmdline/state.h @@ -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. */