[PATCH] Decode RUSAGE_THREAD

Victor Krapivensky krapivenskiy.va at phystech.edu
Wed Mar 15 15:25:32 UTC 2017


* xlat/usagewho.in: Add RUSAGE_THREAD.
* tests/getrusage.c: Test decoding of RUSAGE_THREAD.
---
 tests/getrusage.c | 21 +++++++++++++++------
 xlat/usagewho.in  |  1 +
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/tests/getrusage.c b/tests/getrusage.c
index 8b76eff..ba1a7ef 100644
--- a/tests/getrusage.c
+++ b/tests/getrusage.c
@@ -25,7 +25,6 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
 #include "tests.h"
 #include <asm/unistd.h>
 
@@ -36,17 +35,16 @@
 # include <sys/resource.h>
 # include <unistd.h>
 
-int
-main(void)
+int 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);
+	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",
+	       who_str,
 	       (intmax_t) usage->ru_utime.tv_sec,
 	       (intmax_t) usage->ru_utime.tv_usec,
 	       (intmax_t) usage->ru_stime.tv_sec,
@@ -56,6 +54,17 @@ main(void)
 	       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);
+	return rc;
+}
+
+int
+main(void)
+{
+	struct rusage *const usage = tail_alloc(sizeof(struct rusage));
+	(void) invoke_print(RUSAGE_SELF, "RUSAGE_SELF", usage);
+# ifdef RUSAGE_THREAD
+	(void) invoke_print(RUSAGE_THREAD, "RUSAGE_THREAD", usage);
+# endif
 
 	puts("+++ exited with 0 +++");
 	return 0;
diff --git a/xlat/usagewho.in b/xlat/usagewho.in
index e2153b3..62e7352 100644
--- a/xlat/usagewho.in
+++ b/xlat/usagewho.in
@@ -1,3 +1,4 @@
 RUSAGE_SELF
 RUSAGE_CHILDREN
 RUSAGE_BOTH
+RUSAGE_THREAD
-- 
2.10.2





More information about the Strace-devel mailing list