Link to Download the Script
You can start the shell script by (Don't forget to give executable permissions for the script as
chmod +x script_name.sh
)
/path_to_the_script/top_tracer.sh
Script will ask for the following parameters.
Process ID for the process which you are interested.
A name for an intermediate text file which will be included whole top heading and record of the particular process. (text file will be created in the current location of the shell unless you give an absolute path)
Script will begin to record the top after pressing enter.
After the required time press CTRL + C to end the record.
Then script will ask for an absolute path with a name for the CSV.
Eg Steps:-
/bin/top_tracer.sh
Enter the process ID :16986
Enter a text file name for write the top :/home/udara/blog_post_trace.txt
^CProvide the CSV path : /home/udara/blog_post_trace.csv
Eg CSV:-
load_avg, idle, res, processing
0.02, 94.0, 200960, 6.7
0.02, 98.9, 200960, 2.0
0.02, 98.2, 200960, 2.7
0.02, 98.4, 200960, 2.0
0.02, 97.9, 200960, 2.3
0.02, 98.1, 200960, 2.0
0.02, 95.1, 200960, 2.3
0.01, 96.6, 200960, 2.3
Eg TXT:-
top - 10:58:21 up 2:46, 5 users, load average: 0.02, 0.06, 0.11
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
%Cpu(s): 4.3 us, 0.9 sy, 0.0 ni, 94.0 id, 0.8 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 3940488 total, 329064 free, 2268192 used, 1343232 buff/cache
KiB Swap: 4063228 total, 4050076 free, 13152 used. 1110260 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
16986 udara 20 0 559444 200960 66972 S 6.7 5.1 2:44.25 skype