X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=eta.c;h=0105cda605aa85d513fab2fac7f4412e77007b07;hp=7500082f4e2398da125b8a1a01cc7e981a021222;hb=05bff935cf3b8d5b3cba3958ec8ea9205bdc9f86;hpb=25f488581e510c1b440f2e76842ec23f3dad7b57 diff --git a/eta.c b/eta.c index 7500082f..0105cda6 100644 --- a/eta.c +++ b/eta.c @@ -7,14 +7,33 @@ #include "fio.h" -static char run_str[REAL_MAX_JOBS + 1]; +static char __run_str[REAL_MAX_JOBS + 1]; +static char run_str[__THREAD_RUNSTR_SZ(REAL_MAX_JOBS)]; + +static void update_condensed_str(char *run_str, char *run_str_condensed) +{ + if (*run_str) { + while (*run_str) { + int nr = 1; + + *run_str_condensed++ = *run_str++; + while (*(run_str - 1) == *run_str) { + run_str++; + nr++; + } + run_str_condensed += sprintf(run_str_condensed, "(%u),", nr); + } + run_str_condensed--; + } + *run_str_condensed = '\0'; +} /* * Sets the status of the 'td' in the printed status map. */ static void check_str_update(struct thread_data *td) { - char c = run_str[td->thread_number - 1]; + char c = __run_str[td->thread_number - 1]; switch (td->runstate) { case TD_REAPED: @@ -91,7 +110,8 @@ static void check_str_update(struct thread_data *td) log_err("state %d\n", td->runstate); } - run_str[td->thread_number - 1] = c; + __run_str[td->thread_number - 1] = c; + update_condensed_str(__run_str, run_str); } /* @@ -446,7 +466,8 @@ int calc_thread_status(struct jobs_eta *je, int force) return 0; je->nr_threads = thread_number; - memcpy(je->run_str, run_str, thread_number * sizeof(char)); + update_condensed_str(__run_str, run_str); + memcpy(je->run_str, run_str, strlen(run_str)); return 1; } @@ -544,19 +565,33 @@ void display_thread_status(struct jobs_eta *je) fflush(stdout); } -void print_thread_status(void) +struct jobs_eta *get_jobs_eta(int force, size_t *size) { struct jobs_eta *je; - size_t size; if (!thread_number) - return; + return NULL; + + *size = sizeof(*je) + THREAD_RUNSTR_SZ; + je = malloc(*size); + memset(je, 0, *size); - size = sizeof(*je) + thread_number * sizeof(char) + 1; - je = malloc(size); - memset(je, 0, size); + if (!calc_thread_status(je, 0)) { + free(je); + return NULL; + } + + *size = sizeof(*je) + strlen((char *) je->run_str) + 1; + return je; +} + +void print_thread_status(void) +{ + struct jobs_eta *je; + size_t size; - if (calc_thread_status(je, 0)) + je = get_jobs_eta(0, &size); + if (je) display_thread_status(je); free(je); @@ -564,5 +599,6 @@ void print_thread_status(void) void print_status_init(int thr_number) { - run_str[thr_number] = 'P'; + __run_str[thr_number] = 'P'; + update_condensed_str(__run_str, run_str); }