2
0

getrusage.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <errno.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <sys/resource.h>
  5. #include "test_helpers.h"
  6. void ptimeval(struct timeval* val) {
  7. printf("{ tv_sec: %ld, tv_usec: %ld }\n", val->tv_sec, val->tv_usec);
  8. }
  9. int main(void) {
  10. struct rusage r_usage;
  11. int status = getrusage(RUSAGE_SELF, &r_usage);
  12. ERROR_IF(getrusage, status, == -1);
  13. UNEXP_IF(getrusage, status, != 0);
  14. printf("ru_utime:");
  15. ptimeval(&r_usage.ru_utime);
  16. printf("ru_stime:");
  17. ptimeval(&r_usage.ru_utime);
  18. printf("ru_maxrss: %ld\n", r_usage.ru_maxrss);
  19. printf("ru_ixrss: %ld\n", r_usage.ru_ixrss);
  20. printf("ru_idrss: %ld\n", r_usage.ru_idrss);
  21. printf("ru_isrss: %ld\n", r_usage.ru_isrss);
  22. printf("ru_minflt: %ld\n", r_usage.ru_minflt);
  23. printf("ru_majflt: %ld\n", r_usage.ru_majflt);
  24. printf("ru_nswap: %ld\n", r_usage.ru_nswap);
  25. printf("ru_inblock: %ld\n", r_usage.ru_inblock);
  26. printf("ru_oublock: %ld\n", r_usage.ru_oublock);
  27. printf("ru_msgsnd: %ld\n", r_usage.ru_msgsnd);
  28. printf("ru_msgrcv: %ld\n", r_usage.ru_msgrcv);
  29. printf("ru_nsignals: %ld\n", r_usage.ru_nsignals);
  30. printf("ru_nvcsw: %ld\n", r_usage.ru_nvcsw);
  31. printf("ru_nivcsw: %ld\n", r_usage.ru_nivcsw);
  32. }