diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-01-02 16:29:10 -0500 |
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-01-02 16:29:10 -0500 |
| commit | 69ad7329284d9d5af6d23a4fb4a6f605228ea52a (patch) | |
| tree | 4e083ef14e51edb4355364090736c7f12510adcf /src | |
| parent | 9be1567765803341e252e87262dc43d790d8e770 (diff) | |
| download | stasis-69ad7329284d9d5af6d23a4fb4a6f605228ea52a.tar.gz | |
Consolidate timer data
* Add MultiProcessingTimer struct
* Replace raw timespec and double counters with MultiProcessingTimer(s)
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/core/include/multiprocessing.h | 16 | ||||
| -rw-r--r-- | src/lib/core/multiprocessing.c | 29 |
2 files changed, 23 insertions, 22 deletions
diff --git a/src/lib/core/include/multiprocessing.h b/src/lib/core/include/multiprocessing.h index 933f7d6..874777c 100644 --- a/src/lib/core/include/multiprocessing.h +++ b/src/lib/core/include/multiprocessing.h @@ -12,27 +12,27 @@ #include <sys/stat.h> #include <math.h> +struct MultiProcessingTimer { + struct timespec t_start; + struct timespec t_stop; + double duration; +}; + struct MultiProcessingTask { pid_t pid; ///< Program PID pid_t parent_pid; ///< Program PID (parent process) int status; ///< Child process exit status int signaled_by; ///< Last signal received, if any int timeout; ///< Seconds to elapse before killing the process - struct timespec _interval_start; ///< Current time, start of interval - struct timespec _interval_stop; ///< Time elapsed since status interval (used by MultiprocessingPool.status_interval) - double interval_elapsed; time_t _startup; ///< Time elapsed since task started - double 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) char working_dir[PATH_MAX]; ///< Path to directory `cmd` should be executed in char log_file[PATH_MAX]; ///< Full path to stdout/stderr log file char parent_script[PATH_MAX]; ///< Path to temporary script executing the task - struct { - struct timespec t_start; - struct timespec t_stop; - } time_data; ///< Wall-time counters + struct MultiProcessingTimer time_data; ///< Wall-time counters + struct MultiProcessingTimer interval_data; ///< Progress report counters }; struct MultiProcessingPool { diff --git a/src/lib/core/multiprocessing.c b/src/lib/core/multiprocessing.c index 91b668a..f39f74b 100644 --- a/src/lib/core/multiprocessing.c +++ b/src/lib/core/multiprocessing.c @@ -16,14 +16,14 @@ static double get_task_duration(const struct MultiProcessingTask *task) { } static double get_task_interval_duration(const struct MultiProcessingTask *task) { - const struct timespec *start = &task->_interval_start; - const struct timespec *stop = &task->_interval_stop; + const struct timespec *start = &task->interval_data.t_start; + const struct timespec *stop = &task->interval_data.t_stop; return get_duration(*stop, *start); } static void update_task_interval_start(struct MultiProcessingTask *task) { // Record the task stop time - if (clock_gettime(CLOCK_REALTIME, &task->_interval_start) < 0) { + if (clock_gettime(CLOCK_REALTIME, &task->interval_data.t_start) < 0) { perror("clock_gettime"); exit(1); } @@ -31,11 +31,11 @@ static void update_task_interval_start(struct MultiProcessingTask *task) { static void update_task_interval_elapsed(struct MultiProcessingTask *task) { // Record the interval stop time - if (clock_gettime(CLOCK_REALTIME, &task->_interval_stop) < 0) { + if (clock_gettime(CLOCK_REALTIME, &task->interval_data.t_stop) < 0) { perror("clock_gettime"); exit(1); } - task->interval_elapsed = get_task_interval_duration(task); + task->interval_data.duration = get_task_interval_duration(task); } static void update_task_start(struct MultiProcessingTask *task) { @@ -51,7 +51,7 @@ static void update_task_elapsed(struct MultiProcessingTask *task) { perror("clock_gettime"); exit(1); } - task->elapsed = get_task_duration(task); + task->time_data.duration = get_task_duration(task); } static struct MultiProcessingTask *mp_pool_next_available(struct MultiProcessingPool *pool) { @@ -244,7 +244,7 @@ void mp_pool_show_summary(struct MultiProcessingPool *pool) { strcpy(status_str, "FAIL"); } - printf("%-4s %10d %10s %-10s\n", status_str, task->parent_pid, seconds_to_human_readable(task->elapsed), task->ident) ; + printf("%-4s %10d %10s %-10s\n", status_str, task->parent_pid, seconds_to_human_readable(task->time_data.duration), task->ident) ; //printf("%-4s %10d %7lds %-10s\n", status_str, task->parent_pid, task->elapsed, task->ident) ; } puts(""); @@ -363,7 +363,7 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { int task_timed_out = false; if (slot->timeout) { - task_timed_out = slot->elapsed >= (double) slot->timeout; + task_timed_out = slot->time_data.duration >= (double) slot->timeout; if (task_timed_out && pid == 0 && slot->pid != 0) { printf("%s Task timed out after %s (pid: %d)\n", progress, seconds_to_human_readable(slot->timeout), slot->pid); if (kill(slot->pid, SIGKILL) == 0) { @@ -419,7 +419,7 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { semaphore_wait(&pool->semaphore); update_task_elapsed(slot); semaphore_post(&pool->semaphore); - fprintf(stderr, "%s Task failed after %s\n", progress, seconds_to_human_readable(slot->elapsed)); + fprintf(stderr, "%s Task failed after %s\n", progress, seconds_to_human_readable(slot->time_data.duration)); failures++; if (flags & MP_POOL_FAIL_FAST && pool->num_used > 1) { @@ -427,7 +427,7 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { return -2; } } else { - printf("%s Task finished after %s\n", progress, seconds_to_human_readable(slot->elapsed)); + printf("%s Task finished after %s\n", progress, seconds_to_human_readable(slot->time_data.duration)); } // Clean up logs and scripts left behind by the task @@ -450,11 +450,12 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) { // When a task has executed for longer than status_intervals, print a status update // interval_elapsed represents the time between intervals, not the total runtime of the task semaphore_wait(&pool->semaphore); - if (fabs(slot->interval_elapsed) > pool->status_interval) { - slot->interval_elapsed = 0.0; + if (fabs(slot->interval_data.duration) > pool->status_interval) { + slot->interval_data.duration = 0.0; } - if (slot->interval_elapsed == 0.0) { - printf("[%s:%s] Task is running (pid: %d, elapsed: %s)\n", pool->ident, slot->ident, slot->parent_pid, seconds_to_human_readable(slot->elapsed)); + if (slot->interval_data.duration == 0.0) { + printf("[%s:%s] Task is running (pid: %d, elapsed: %s)\n", + pool->ident, slot->ident, slot->parent_pid, seconds_to_human_readable(slot->time_data.duration)); update_task_interval_start(slot); } |
