ASIC/FPGA Design and Verification Out Source Services
A simple script to measure the time for a job pending in lsf.
- This script simply measures the time a job is pending in lsf.
- It can be a base for similar scripts, which measure a process duration, or trigger action upon process end detection.
- First, statement in the script, a grep command is prepared. Then a while loop starts and continues as long as the grep command returns success status. The script has a 5 second sleep command in the while loop, in order not to load too much the CPU. The script calculates the elapsed time in seconds. Although I could just add 5 to a simple counter, in the script, (because the 5 second sleep command), I decided to use date command, as shown below.
eval $cmd
sleep 5
time_end=`date +%s`
time_tot=$(($time_end - $time_start))
echo -ne "${time_tot} seconds\r"
Note: that
date +%s
did not work on SunOS and did work
well a linux machine.
Instead I use perl to get the time for the
bash script:
time_start=
`perl -e '$t=time(); print("$t\n")'`
A nice display for the total time consumed is also added. The number of seconds is converted to minutes and hours if the value is greater than 60 / 3600 respectively.
- div="60"
- if [ "${time_tot}" -gt "$div" ] ; then
- time_tot_m=$(($time_tot / $div))
- time_tot=$(($time_tot % $div))
- if [ "${time_tot_m}" -gt "$div" ] ; then
- time_tot_h=$(($time_tot_m / $div))
- time_tot_m=$(($time_tot_m % $div))
- else
- echo "job is not pending any more "${time_start}" "$time_end" "${time_tot_m}" minutes "${time_tot}" seconds"
- fi
- else
- echo "job is not pending any more "${time_start}" "$time_end" "${time_tot}" seconds"
- fi
- The script is available at:
pending time measure bash script
- Script invocation is as simple as:
~/bin/lsf_pend_time_measure.unx 1616161
Where 1616161 is the job number in lsf.
|