strace
can only strace
executable files.
funk_a
is a function, a programming construct of the shell, not something you can execute.
The only thing strace
could strace would be a new shell that evalutes the body of that function like:
strace -o trace_output.txt -Ttt bash -c "$(typeset -f funk_a); funk_a"
(I removed -c
as it makes no sense with -Ttt
).
But you'll then see all the system called made by bash
to load and initialise (and after to clean-up and exit) in addition to that one write
system call made by that funk_a
function.
Or you could tell strace
to trace the pid of the shell while it evaluates the funk_a
function:
strace -o trace_output.txt -Ttt -p "$$" &
funk_a
kill "$!"
Though, by the time strace
attaches to the PID of the shell, the shell could very well have finished interpreting the function. You could try some synchronisation like
strace -o trace_output.txt -Ttt -p "$$" &
tail -F trace_output.txt | read # wait for some output in trace_output.txt
funk_a
kill "$!"
But even then depending on timing, trace_output.txt
would include some of the system calls used interpret tail|read
, or kill
could kill strace
before it has had the time to write the trace for the echo
command to the output file.
A better approach could be to wrap the call to funk_a
between two recognisable system calls like
strace -fo >(sed -n '1,\|open("///dev/null|d
\|open("/dev///null|q;p' > trace_output.txt
) -Ttt -p "$$" &
sleep 1 # give enough time for strace to start
exec 3< ///dev/null # start signal
funk_a
exec 3< /dev///null # end signal
type funk_a
? – ctrl-alt-delor Jan 22 '17 at 11:34