eta: don't count TD_SETTING_UP as a running process
[fio.git] / eta.c
diff --git a/eta.c b/eta.c
index 7500082f4e2398da125b8a1a01cc7e981a021222..baada7bc48ad51604978d7cffc6051115325239e 100644 (file)
--- 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);
 }
 
 /*
@@ -372,10 +392,9 @@ int calc_thread_status(struct jobs_eta *je, int force)
                } else if (td->runstate == TD_RAMP) {
                        je->nr_running++;
                        je->nr_ramp++;
-               } else if (td->runstate == TD_SETTING_UP) {
-                       je->nr_running++;
+               } else if (td->runstate == TD_SETTING_UP)
                        je->nr_setting_up++;
-               else if (td->runstate < TD_RUNNING)
+               else if (td->runstate < TD_RUNNING)
                        je->nr_pending++;
 
                if (je->elapsed_sec >= 3)
@@ -446,7 +465,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 +564,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_number * sizeof(char) + 1;
-       je = malloc(size);
-       memset(je, 0, size);
+       *size = sizeof(*je) + THREAD_RUNSTR_SZ;
+       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 +598,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);
 }