This is not a great approach, for various reasons - ideally you should modify your program's outer loop so that it can process all the files on the command line, then you can just do everything in one run:
$ shark -i
$ mycprog $SomeDirectory/*
If you can't do that then you will need to set your Shark configuration for system-wide profiling and start profiling before your bash loop and stop profiling afterwards. When you subsequently view the profile in Shark you'll be able to filter out the processes that you're not interested in.
Firstly open Shark (the GUI app), set up your configuration and enable remote control (Sampling
=> Programmatic
). Make sure you have Time Profile
and Everything
selected.
Then from the command line:
$ chudRemoteCtrl -s "mycprog"
$ sleep 1
$ for f in $SomeDirectory/*
$ do
$ mycprog $SomeDirectory/$f
$ done
$ chudRemoteCtrl -e