/usr/bin/time, interpret the output - linux

I wanted to record the cpu time of running some programs, I put /usr/bin/time command in from the the command, like the following:
/usr/bin/time command_name_and_args
the result I got as follow:
652.25user 5.29system 11:53.85elapsed 92%CPU (0avgtext+0avgdata 5109232maxresident)k
3800352inputs+1620608outputs (2major+319449minor)pagefaults 0swaps
would it be correct for the cpu time is 652.25 + 5.29 = 657.54 seconds?
and does 11:53.85elapsed mean 11 minutes 53.85 seconds on wall clock?
Thanks for help.

Exactly. CPU time might exceed wall clock time if you have more than one thread.

Related

How to find the average CPU of a process over X amount of time in Linux

I'm trying to find out how I can get \ calculate the CPU utilization of a specific process over X amount of time ( I write my code in python over a Linux based system ).
What I want to get for example is the average CPU of a process in the last hour\day\10 minutes...
Is there a command or a calculation I can run?
*I can't run a command like "top" in the background for X time and calculate the CPU, I need it to be in one set of commands or calculation.
I tried top research on top command but I didn't found useful info for my case.
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu - give the average consumption on the process lifetime
Can there be a way to use uptime or proc[pid]\stat to calculate this?
Thanks,
What about using pidstat?
$ pidstat -p 12345 10
Will output the stats for pid 12345 every 10 seconds. This include CPU%
From there you can run it on background, and redirect output to a file:
$ pidstat -p 12345 10 > my_pid_stats.txt &
Here is a Link with several examples. There is a lot of flexibility in the output, so you can probably customize it to better suit your needs:
https://www.thegeekstuff.com/2014/11/pidstat-examples/
pidstat is part of the sysstat package on ubuntu, in case you decide to install it.

Linux iostat "averaged" result over a period of time

I am using the iostat utility on my RedHat Linux server to monitor the performance of a disk. When I use "iostat -xd sdh 1", I get the perf result printed every one second. When I use "iostat -xd sdh 5", I get the perf result printed every five second. My feeling is the latter command is printing a snapshot of the perf every five second, rather than averaging over the past 5 seconds. Am I correct in my understanding?
If so, is there a way I can make iostat print the perf. number averaged over n seconds, or is there some other utility that will do that.
Currently, the perf number is fluctuating within a range, and I want to get a somewhat "stable" number. I am hoping that averaging over a period of time will give me such a number.
Thank you,
Ahmed.

Find Mysqldump Execution Time?

I want to find how much it takes to run my mysqldump and compare it with my I/O rate at the end of mysqldump command.
looking for someting like :
bash:> time .dumpscript
--and at the end he will calculate my I/O rate from starting point to finish point giving me something like :
Dumpsize Time I/O per sec
30 gb 30 min 5mb/sec
Thx all!
You can use the time command in bash to see how long your command takes. This will give the execution time in seconds:
{ time -p ./dumpscript; } 2>&1 | tail -3 | awk 'NR==1{print $2}'
Presumably you know the location of the dump file, so you can find the size of that with stat. Since you now know the size of the file, and the time it took to create it, you can calculate the I/O rate with some basic arithmetic.

Times in linux Time output

I run time on my c program and the following was printed:
0.00user 0.03system 0:00.03elapsed 91%CPU (0avgtext+0avgdata 1632maxresident)k
0inputs+112outputs (0major+143minor)pagefaults 0swaps
My main question concerns the numbers before user, system, and elapsed. Does the output say:
user takes 0.00 seconds, system takes 0.03 seconds, and elapsed takes 0.03 seconds?
Well, that would depend on what your c program is displaying. c programs by default don't print any timestamps, etc.
From what you listed above, it looks similar to the output of the standard linux TOP program that is included in most/all distros.
It would indicate what percentage of CPU time has been spent on that classification of code (user space code, system space code, etc). The 0:00.03 would be the total uptime for your system usually.

Display execution time of shell command with better accuracy

The following will display the time it took for a given command to execute. How would I do the same but with better precision (i.e 5.23 seconds)?
[root#localhost ~]# start=`date +%s`; sleep 5 && echo execution time is $(expr `date +%s` - $start) seconds
execution time is 5 seconds
[root#localhost ~]#
You could try using the time command.
time sleep 5
In addition to elapsed wall clock time it will tell you how much CPU time the process consumed, and how much of the CPU time was spent in the application and how much in operating system calls.
Use the time command:
time COMMAND
You can also use the SECONDS variable:
In the Bash Variables section of the reference manual you'll read:
SECONDS This variable expands to the number of seconds since the shell was started. Assignment to this variable resets the count to the value assigned, and the expanded value becomes the value assigned plus the number of seconds since the assignment.
Hence, the following:
SECONDS=0; sleep 5; echo "I slept for $SECONDS seconds"
should output 5. It's only good for measuring times with precision of 1 second, but it sure is much better than the way you showed using the date command.
If you need more precision, you can use the time command, but it's a bit tricky to get the output of this command in a variable. You'll find all the information in the BashFAQ/032: How can I redirect the output of time to a variable or file?.

Resources