clinuxperfpage-fault

Measure page faults from a c program


I am comparing a few system calls where I read/write from/to memory. Is there any API defined to measure page faults (pages in/out) in C ?

I found this library libperfstat.a but it is for AIX, I couldn't find anything for linux.

Edit: I am aware of time & perf-stat commands in linux, just exploring if there is anything available for me to use inside the C program.


Solution

  • There is getrusage function (SVr4, 4.3BSD. POSIX.1-2001; but not all fields are defined in standard). In linux there are several broken fields, but man getrusage lists several interesting fields:

    long   ru_minflt;        /* page reclaims (soft page faults) */
    long   ru_majflt;        /* page faults (hard page faults) */
    
    long   ru_inblock;       /* block input operations */
    long   ru_oublock;       /* block output operations */
    

    The rusage is also reported in wait4 (only usable in external program). This one is used by /usr/bin/time program (it prints minor/major pagefault counts).