Finding the exact Time Value for the Computer Programs with the aid of Kernel Timers
Hello Guys, Basicaaly i am working no finding the exact time which is taken by a particular program or a sort of algorithm when executed....Although there are many inbuilt funtions for calculating for example : ( endvalue - startvalue ) / CLKS_PER_SEC
it doesn't give the exact value when executed by the processeor, in other words if there are 3 processes interleaved in the short term sheduler queue the above method gives me the time where in it includes the time slices of the other processes also the best example would be the turn around time of a Round Robin Scheduling Algorithm for 3 processes . Now my requirement is say suppose i want to mesure the execution time of a process 1 then i should get only its amount of time spent for execution with the processor not the other 2 processes time slices added with it, i heard using or setting kernel timers we can achive this so any one out there ready to help me with that? |
I guess you need to read these http://www.linuxtopia.org/online_boo...nel_index.html
|
It kind of depends on what you are actually looking for. If you want the CPU time a process takes, you can always install some process accounting, and get the pacct file that has that time.
If you are trying to time a function of a program (different subject) then you need to use the library function "clock" - which reports the CPU time used (man 3p clock). To use it to time a (quick) function, you get the cpu time when you start, then call the function 100 times, get the CPU time again - subtract first from the second, divide by 100. Use different iterations depending on the rough time it takes the function to run. Another and better reference should be "info clock". |
Your not going to get exact timings - for anything. Taking the measurement influences the environment. And possibly displaces the process being timed from the CPU it was running on.
For a reproducible environment, I'd disable hiper-threading and use cgroups to isolate the process to a particular CPU (no competing non-kernel processes). Run it enough times to get a reasonable average. |
Quote:
Hyper-threading and cgroups will do nothing to change that. What it does affect is the elapsed time at test is running. |
All times are GMT -5. The time now is 06:01 AM. |