After reading the following blog below, I was inspired to write a wrapper around /usr/bin/time (not to be confused with the time shell built-in) in order to help me to learn more about process and system internals and to provide a synopsis of a programs performance for troubleshooting.
There is a -v flag to /usr/bin/time which displays exactly the same information, however I didn’t like how the information is formatted.
valgrind would typically be used for deeper level performance profiling, by developers to look at cache hit misses, memory leaks etc.
I have uploaded the script onto GitHub : https://github.com/dazdaz/pstats
./pstats.sh /etc/cron.daily/mlocate.cron Time 0:01.16 Elapsed real time (in [hours:]minutes:seconds). 1.16 Elapsed real time (in seconds). 0.73 Total number of CPU-seconds that the process spent in kernel mode. 0.21 Total number of CPU-seconds that the process spent in user mode. 81% Percentage of the CPU that this job got, computed as (0.21 + 0.73) / 0:01.16. Memory 4352 Maximum resident set size of the process during its lifetime, in Kbytes. 0 Average resident set size of the process, in Kbytes. 0 Average total (data+stack+text) memory use of the process, in Kbytes. 0 Average size of the process's shared data area, in Kbytes. 0 Average size of the process's shared stack space, in Kbytes. 0 Average size of the process's shared text space, in Kbytes. 4096 System's page size, in bytes. This is a per-system constant, but varies between systems. 0 Number of major page faults that occurred while the process was running. These are faults where the page has to be read in from disk. 1545 Number of minor, or recoverable, page faults. These are faults for pages that are not valid but which have not yet been claimed by other virtual pages. Thus the data in the page is still valid but the system tables must be updated. 0 Number of times the process was swapped out of main memory. 198 Number of times the process was context-switched involuntarily (because the time slice expired). 75 Number of waits: times that the program was context-switched voluntarily, for instance while waiting for an I/O operation to complete. I/O 528 Number of file system inputs by the process. 7328 Number of file system outputs by the process. 0 Number of socket messages received by the process. 0 Number of socket messages sent by the process. 0 Number of signals delivered to the process. 0 Exit Status
Some other commands that you may like to experiment with : ./pstats.sh dd if=/dev/zero of=/dev/null bs=10M count=1 1>/dev/null ./pstats.sh sleep 5 ./pstats.sh bash