diff options
author | наб <[email protected]> | 2021-04-02 14:10:31 +0200 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2021-04-07 14:50:03 -0700 |
commit | 3bc3eef9c3f1c71bae09ef546bdc990621771c87 (patch) | |
tree | 7dc30379f05999b56d3d5bc384d6efb421bbbe2b | |
parent | 7367be0da935cc01dc9f7d048bcba367a147d2c7 (diff) |
zed: print combined system/user time after ZEDLET death
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #11834
-rw-r--r-- | cmd/zed/zed_exec.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/cmd/zed/zed_exec.c b/cmd/zed/zed_exec.c index 1fbac4296..b1756c538 100644 --- a/cmd/zed/zed_exec.c +++ b/cmd/zed/zed_exec.c @@ -20,6 +20,7 @@ #include <string.h> #include <stddef.h> #include <sys/avl.h> +#include <sys/resource.h> #include <sys/stat.h> #include <sys/wait.h> #include <time.h> @@ -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); |