From b73e40a5ad1d0231f73b810732f1dc254869718d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Fri, 2 Apr 2021 14:10:31 +0200 Subject: [PATCH] zed: print combined system/user time after ZEDLET death MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Brian Behlendorf Signed-off-by: Ahelenia ZiemiaƄska Closes #11834 --- cmd/zed/zed_exec.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/cmd/zed/zed_exec.c b/cmd/zed/zed_exec.c index 1fbac42968..b1756c5386 100644 --- a/cmd/zed/zed_exec.c +++ b/cmd/zed/zed_exec.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -175,6 +176,7 @@ _zed_exec_fork_child(uint64_t eid, const char *dir, const char *prog, node->pid = pid; node->eid = eid; node->name = strdup(prog); + (void) pthread_mutex_lock(&_launched_processes_lock); avl_add(&_launched_processes, node); (void) pthread_mutex_unlock(&_launched_processes_lock); @@ -191,6 +193,7 @@ _reap_children(void *arg) struct launched_process_node node, *pnode; pid_t pid; int status; + struct rusage usage; struct sigaction sa = {}; (void) sigfillset(&sa.sa_mask); @@ -203,7 +206,7 @@ _reap_children(void *arg) (void) sigaction(SIGCHLD, &sa, NULL); for (_reap_children_stop = B_FALSE; !_reap_children_stop; ) { - pid = waitpid(0, &status, 0); + pid = wait4(0, &status, 0, &usage); if (pid == (pid_t)-1) { if (errno == ECHILD) @@ -227,21 +230,37 @@ _reap_children(void *arg) __atomic_add_fetch(&_launched_processes_limit, 1, __ATOMIC_SEQ_CST); + usage.ru_utime.tv_sec += usage.ru_stime.tv_sec; + usage.ru_utime.tv_usec += usage.ru_stime.tv_usec; + usage.ru_utime.tv_sec += + usage.ru_utime.tv_usec / (1000 * 1000); + usage.ru_utime.tv_usec %= 1000 * 1000; + if (WIFEXITED(status)) { zed_log_msg(LOG_INFO, - "Finished \"%s\" eid=%llu pid=%d exit=%d", + "Finished \"%s\" eid=%llu pid=%d " + "time=%llu.%06us exit=%d", node.name, node.eid, pid, + (unsigned long long) usage.ru_utime.tv_sec, + (unsigned int) usage.ru_utime.tv_usec, WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { zed_log_msg(LOG_INFO, - "Finished \"%s\" eid=%llu pid=%d sig=%d/%s", - node.name, node.eid, pid, WTERMSIG(status), + "Finished \"%s\" eid=%llu pid=%d " + "time=%llu.%06us sig=%d/%s", + node.name, node.eid, pid, + (unsigned long long) usage.ru_utime.tv_sec, + (unsigned int) usage.ru_utime.tv_usec, + WTERMSIG(status), strsignal(WTERMSIG(status))); } else { zed_log_msg(LOG_INFO, "Finished \"%s\" eid=%llu pid=%d " - "status=0x%X", - node.name, node.eid, (unsigned int) status); + "time=%llu.%06us status=0x%X", + node.name, node.eid, + (unsigned long long) usage.ru_utime.tv_sec, + (unsigned int) usage.ru_utime.tv_usec, + (unsigned int) status); } free(node.name);