1

I want to measure the running time of a specific system call, for example, I want to know a pread need how many time on both CPU and I/O.

Which function should I use?

Now I usetimes, and it works.

gettimeofday is get the current time, and that may not just calculate the running time of a specific process, right?

clock is return the CPU time this program used so far, does this include the I/O time? If there are other programs running, will this influence the time of this function? I mean something like switching running process.

getrusage seems like a ideal one, but it also returns the CPU time of a specific process.

Does anyone know how benchmark tools like iozone calculate system calls time? I've read its code, and still have no idea.

osgx
  • 90,338
  • 53
  • 357
  • 513
bxshi
  • 2,252
  • 5
  • 31
  • 50
  • iozone uses `gettimeofday` (full time; wall time; astronomic time. this has almost highest resolution) and `getrusage` (cpu time, sometimes rounded to 1-10 ms units) on posix platforms (and may use `times`), according to its sources (iozone.c). It calls both functions before and after I/O operations and calculate difference. For measuring syscall time there is also `strace -T`, which uses `gettimeofday` and tries to estimate and subtract its overhead. – osgx Jun 24 '16 at 19:54

1 Answers1

2

You're looking for times(2).

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • I've tried this function, `pread` a 131072 bytes buffer, and the total ticks is always zero, is that normal? I've changed that to 1310720, still always zero, sometimes it is 1. does `times` really include I/O time? – bxshi Apr 04 '12 at 16:33
  • Are you looking at the user time or the system time? – Ignacio Vazquez-Abrams Apr 04 '12 at 16:45
  • I'm not pretty sure about that. I want to get the total time of a system call. like how many time the program spend on read 131072 bytes from hard disk. @IgnacioVazquez-Abrams – bxshi Apr 04 '12 at 16:47