[PATCH v2] Decode RUSAGE_THREAD
Victor Krapivensky
krapivenskiy.va at phystech.edu
Wed Mar 15 22:01:40 UTC 2017
* xlat/usagewho.in: Add values for existing values, add RUSAGE_THREAD.
* tests/getrusage.c: Test decoding of RUSAGE_THREAD.
---
tests/getrusage.c | 31 +++++++++++++++++++++++++------
xlat/usagewho.in | 7 ++++---
2 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/tests/getrusage.c b/tests/getrusage.c
index 8b76eff..e84f23d 100644
--- a/tests/getrusage.c
+++ b/tests/getrusage.c
@@ -35,18 +35,23 @@
# include <stdint.h>
# include <sys/resource.h>
# include <unistd.h>
+# include <errno.h>
+
+# include "xlat.h"
+# include "xlat/usagewho.h"
int
-main(void)
+invoke_print(int who, const char *who_str, struct rusage *usage)
{
- struct rusage *const usage = tail_alloc(sizeof(struct rusage));
- int rc = syscall(__NR_getrusage, RUSAGE_SELF, usage);
- printf("getrusage(RUSAGE_SELF, {ru_utime={tv_sec=%jd, tv_usec=%jd}"
+ int rc = syscall(__NR_getrusage, who, usage);
+ int saved_errno = errno;
+ printf("getrusage(%s, {ru_utime={tv_sec=%jd, tv_usec=%jd}"
", ru_stime={tv_sec=%jd, tv_usec=%jd}, ru_maxrss=%lu"
", ru_ixrss=%lu, ru_idrss=%lu, ru_isrss=%lu, ru_minflt=%lu"
", ru_majflt=%lu, ru_nswap=%lu, ru_inblock=%lu"
", ru_oublock=%lu, ru_msgsnd=%lu, ru_msgrcv=%lu"
- ", ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}) = %d\n",
+ ", ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}) = %s\n",
+ who_str,
(intmax_t) usage->ru_utime.tv_sec,
(intmax_t) usage->ru_utime.tv_usec,
(intmax_t) usage->ru_stime.tv_sec,
@@ -55,7 +60,21 @@ main(void)
usage->ru_isrss, usage->ru_minflt, usage->ru_majflt,
usage->ru_nswap, usage->ru_inblock, usage->ru_oublock,
usage->ru_msgsnd, usage->ru_msgrcv, usage->ru_nsignals,
- usage->ru_nvcsw, usage->ru_nivcsw, rc);
+ usage->ru_nvcsw, usage->ru_nivcsw, sprintrc(rc));
+ errno = saved_errno;
+ return rc;
+}
+
+int
+main(void)
+{
+ struct rusage *const usage = tail_alloc(sizeof(struct rusage));
+ if (invoke_print(ARG_STR(RUSAGE_SELF), usage)) {
+ return 1;
+ }
+ if (invoke_print(ARG_STR(RUSAGE_THREAD), usage) && errno != EINVAL) {
+ return 1;
+ }
puts("+++ exited with 0 +++");
return 0;
diff --git a/xlat/usagewho.in b/xlat/usagewho.in
index e2153b3..1b1255c 100644
--- a/xlat/usagewho.in
+++ b/xlat/usagewho.in
@@ -1,3 +1,4 @@
-RUSAGE_SELF
-RUSAGE_CHILDREN
-RUSAGE_BOTH
+RUSAGE_SELF 0
+RUSAGE_CHILDREN (-1)
+RUSAGE_BOTH (-2)
+RUSAGE_THREAD 1
--
2.10.2
More information about the Strace-devel
mailing list