Measure page faults from a c program

后端 未结 3 2085
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-08 17:18

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

3条回答
  •  无人及你
    2020-12-08 18:06

    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).

提交回复
热议问题