Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is getrusage broken in Linux (2.6.30)

This code

 void print_usage(char * msg)
{
    struct rusage usage;
    getrusage(RUSAGE_SELF, &usage);
    printf("Limits: %s\n", msg);
    printf("  %s, %li\n",  " maximum resident set size "    , usage.ru_maxrss  );
    printf("  %s, %li\n",  " integral shared memory size "  , usage.ru_ixrss   );
    printf("  %s, %li\n",  " integral unshared data size "  , usage.ru_idrss   );
    printf("  %s, %li\n",  " integral unshared stack size " , usage.ru_isrss   );
    printf("  %s, %li\n",  " page reclaims "                , usage.ru_minflt  );
    printf("  %s, %li\n",  " page faults "                  , usage.ru_majflt  );
    printf("  %s, %li\n",  " swaps "                        , usage.ru_nswap   );
    printf("  %s, %li\n",  " block input operations "       , usage.ru_inblock );
    printf("  %s, %li\n",  " block output operations "      , usage.ru_oublock );
    printf("  %s, %li\n",  " messages sent "                , usage.ru_msgsnd  );
    printf("  %s, %li\n",  " messages received "            , usage.ru_msgrcv  );
    printf("  %s, %li\n",  " signals received "             , usage.ru_nsignals);
    printf("  %s, %li\n",  " voluntary context switches "   , usage.ru_nvcsw   );
    printf("  %s, %li\n",  " involuntary context switches " , usage.ru_nivcsw  );

}

reports only zeroes for many fields, even if I use it in rather big program (after jvm start)

   maximum resident set size , 0
   integral shared memory size , 0
   integral unshared data size , 0
   integral unshared stack size , 0
   page reclaims , 2514
   page faults , 0
   swaps , 0
   block input operations , 0
   block output operations , 0
   messages sent , 0
   messages received , 0
   signals received , 0
   voluntary context switches , 137
   involuntary context switches , 1

The non-zero fields are "*vcsw", "*flt".

All *rss, *swap, msg*, *block, *signals are Zero.

Is there something broken?

Linux is x86 2.6.30.

like image 799
osgx Avatar asked Aug 26 '11 14:08

osgx


People also ask

What does Getrusage return?

getrusage() returns resource usage measures for who, which can be one of the following: RUSAGE_SELF Return resource usage statistics for the calling process, which is the sum of resources used by all threads in the process.

What does Getrusage do in C?

The getrusage() function shall provide measures of the resources used by the current process or its terminated and waited-for child processes. If the value of the who argument is RUSAGE_SELF, information shall be returned about resources used by the current process.

What is struct Rusage?

Data Type: struct rusage. This data type stores various resource usage statistics. It has the following members, and possibly others: struct timeval ru_utime. Time spent executing user instructions.


1 Answers

Yes it is partly broken. Not all fields are filled by kernel. http://www.kernel.org/doc/man-pages/online/pages/man2/getrusage.2.html

Working fields:

   ru_utime
   ru_stime
   ru_maxrss (since Linux 2.6.32)
   ru_minflt
   ru_majflt
   ru_inblock (since Linux 2.6.22)
   ru_oublock (since Linux 2.6.22)
   ru_nvcsw (since Linux 2.6)
   ru_nivcsw (since Linux 2.6)

Unused fields:

   ru_ixrss (unmaintained)
   ru_idrss (unmaintained)
   ru_isrss (unmaintained)
   ru_nswap (unmaintained)
   ru_msgsnd (unmaintained)
   ru_msgrcv (unmaintained)
   ru_nsignals (unmaintained)
like image 164
osgx Avatar answered Nov 15 '22 06:11

osgx