bash - Performance profiling tools for shell scripts -


i'm attempting speed collection of scripts invoke subshells , sorts of things. wonder if there tools available time execution of shell script , nested shells , report on parts of script expensive.

for example, if had script following.

#!/bin/bash  echo "hello" echo $(date) echo "goodbye" 

i know how long each of 3 lines took. time only give me total time script. bash -x interesting not include timestamps or other timing information.

you can set ps4 show time , line number. doing doesn't require installing utilities , works without redirecting stderr stdout.

for script:

#!/bin/bash -x # note -x flag above, required work ps4='$(date "+%s.%n ($lineno) + ")' in {0..2}     echo $i done sleep 1 echo done 

the output looks like:

+ ps4='$(date "+%s.%n ($lineno) + ")' 1291311776.108610290 (3) + in '{0..2}' 1291311776.120680354 (5) + echo 0 0 1291311776.133917546 (3) + in '{0..2}' 1291311776.146386339 (5) + echo 1 1 1291311776.158646585 (3) + in '{0..2}' 1291311776.171003138 (5) + echo 2 2 1291311776.183450114 (7) + sleep 1 1291311777.203053652 (8) + echo done done 

this assumes gnu date, can change output specification or whatever matches version of date use.

note: if have existing script want without modifying it, can this:

ps4='$(date "+%s.%n ($lineno) + ")' bash -x scriptname 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -