diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2025-02-12 16:39:11 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2025-02-12 16:39:11 -0500 |
commit | 3acd9c8bd8c28660bc42ebb9e8320b183bff0ff7 (patch) | |
tree | c174b5205da4b0eb6a96b236f4de2d95b76800c0 | |
parent | a10079501c1e7de6767871592ebe95aa6ed0cc39 (diff) | |
download | stasis-3acd9c8bd8c28660bc42ebb9e8320b183bff0ff7.tar.gz |
Display time elapsed in multiprocessing progress-related output
-rw-r--r-- | src/lib/core/include/multiprocessing.h | 4 | ||||
-rw-r--r-- | src/lib/core/multiprocessing.c | 8 |
2 files changed, 8 insertions, 4 deletions
diff --git a/src/lib/core/include/multiprocessing.h b/src/lib/core/include/multiprocessing.h index ec7c1ad..ff674e9 100644 --- a/src/lib/core/include/multiprocessing.h +++ b/src/lib/core/include/multiprocessing.h @@ -16,7 +16,9 @@ struct MultiProcessingTask { int status; ///< Child process exit status int signaled_by; ///< Last signal received, if any time_t _now; ///< Current time - time_t _seconds; ///< Time elapsed (used by MultiprocessingPool.status_interval) + time_t _seconds; ///< Time elapsed since status interval (used by MultiprocessingPool.status_interval) + time_t _startup; ///< Time elapsed since task started + long elapsed; ///< Total time elapsed in seconds char ident[255]; ///< Identity of the pool task char *cmd; ///< Shell command(s) to be executed size_t cmd_len; ///< Length of command string (for mmap/munmap) diff --git a/src/lib/core/multiprocessing.c b/src/lib/core/multiprocessing.c index 252bab9..4f64f2e 100644 --- a/src/lib/core/multiprocessing.c +++ b/src/lib/core/multiprocessing.c @@ -261,6 +261,7 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { for (size_t i = lower_i; i < upper_i; i++) { struct MultiProcessingTask *slot = &pool->task[i]; if (slot->status == MP_POOL_TASK_STATUS_INITIAL) { + slot->_startup = time(NULL); if (mp_task_fork(pool, slot)) { fprintf(stderr, "%s: mp_task_fork failed\n", slot->ident); kill(0, SIGTERM); @@ -331,7 +332,7 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { } if (status >> 8 != 0 || (status & 0xff) != 0) { - fprintf(stderr, "%s Task failed\n", progress); + fprintf(stderr, "%s Task failed after %lus\n", progress, slot->elapsed); failures++; if (flags & MP_POOL_FAIL_FAST && pool->num_used > 1) { @@ -339,7 +340,7 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { return -2; } } else { - printf("%s Task finished\n", progress); + printf("%s Task finished after %lus\n", progress, slot->elapsed); } // Clean up logs and scripts left behind by the task @@ -365,9 +366,10 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { slot->_seconds = 0; } if (slot->_seconds == 0) { - printf("[%s:%s] Task is running (pid: %d)\n", pool->ident, slot->ident, slot->parent_pid); + printf("[%s:%s] Task is running (pid: %d, elapsed: %lus)\n", pool->ident, slot->ident, slot->parent_pid, slot->elapsed); } } + slot->elapsed = time(NULL) - slot->_startup; } if (tasks_complete == pool->num_used) { |