I'm trying to get an estimate of the total cpu ressource usage of a process. The idea is to track ameliorations in programs through the careful monitoring of each test timing before and after a commit (for instance) and retrieve only a meaningful metric highlighting a measurable difference.
Some of these tests are pretty quick to run, and I need at least microseconds precision if I'm to count time. But can't we count cycles allocated but the scheduler to the process ? Or have you other suggestions of specific metrics that would properly keep track of the efficiency of a process ? If yes, which tool do you recommand ? I need CLI launching and output so as to process the measurement further.
Note about jitter: I'm aware that there are numerous reason why these estimates may not be portable between machines, or that inevitable big jitter is happening even on the same machine. I'll also apply some statistics fiddle (averaging, removal of extreme records, and only keeping differences in dB with a precision of 0.1dB, which will only start spotting differences greater than 20%...), and some obvious way to reduce jitter (like ruing the tests consecutively on the same machine) to stabilize the estimates, and these work quite well already.
I was quite disappointed by the bash shell keyword time, and /usr/bin/time provided on my ubuntu box (package time-1.7-25.1). Their precision is not great enough (no microseconds), and no access to CPU cycles they used...
This is what I'm using currentyl, with some success, but I'm looking for a better (more efficient, and more accurate) way to do it:
## bash function
## stores the time of execution in nanoseconds in "$time"
time_exec() {
local errlvl start end
start=$(date +%s.%N)
"$@"
errlvl=$?
end=$(date +%s.%N)
time=$(
echo "scale=3; ($end - $start) * 1000000" |
bc | cut -f 1 -d ".")
retu $errlvl
}
I'm unhappy with this solution because: - this is system time and not process time, so it is not immune to context switching and is very rough. - start and end measurement points are in subshells in different processes and this is jitter prone.
any suggestions ? I'm not against a small C program that would do the equivalent with a proper call to ask for the process time and not the system time and get nanoseconds precision also. But I was hoping for an existent profiling command somewhere that could do this already.
