Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add performance output in badblocks summary #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion misc/badblocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ static ext2_badblocks_list bb_list = NULL;
static FILE *out;
static blk_t next_bad = 0;
static ext2_badblocks_iterate bb_iter = NULL;
static unsigned long perf_last_count = 0;
static struct timespec perf_last_time;

enum error_types { READ_ERROR, WRITE_ERROR, CORRUPTION_ERROR };

Expand Down Expand Up @@ -215,6 +217,20 @@ static float calc_percent(unsigned long current, unsigned long total) {
return percent;
}

static float calc_performance(unsigned long current_count) {
float blocks_per_second = 0.0;
struct timespec current_time;
clock_gettime(CLOCK_REALTIME, &current_time);

float secs = (current_time.tv_sec-perf_last_time.tv_sec) + (current_time.tv_nsec-perf_last_time.tv_nsec)/1e9;
if (secs > 0)
blocks_per_second = ( (float) (current_count-perf_last_count) ) / secs;

perf_last_time = current_time;
perf_last_count = current_count;
return blocks_per_second;
}

static void print_status(void)
{
struct timeval time_end;
Expand All @@ -226,10 +242,11 @@ static void print_status(void)

gettimeofday(&time_end, 0);
len = snprintf(line_buf, sizeof(line_buf),
_("%6.2f%% done, %s elapsed. "
_("%6.2f%% done, %6.f blk/sec, %s elapsed. "
"(%d/%d/%d errors)"),
calc_percent((unsigned long) currently_testing,
(unsigned long) num_blocks),
calc_performance((unsigned long) currently_testing),
time_diff_format(&time_end, &time_start, diff_buf),
num_read_errors,
num_write_errors,
Expand Down