Version 1.1 Update
[ctprof_srv/ctprof_srv.git] / ctprof_sync.sh
1 #!/bin/bash
3 if [ "$#" -lt "1" ]; then
4     echo "Usage: ctprof_sync.sh cmd [options]"
5     echo "       ctprof_sync.sh will start ctprof_srv, wait for the clinet to"
6     echo "       start a trace session, execute the cmd, and then wait for the"
7     echo "       client to disconnect from ctprof_srv, terminating the session."
8     exit
9 fi
11 # Start the server
12 ctprof_srv -Pt &
14 pipe=./ctprof_fifo
16 # Wait for ctprof_srv to create the pipe
17 while true
18 do 
19     if [[ -p $pipe ]]; then
20         break
21     fi
22 done
24 # First 4 bytes from ctprof_srv is it's pid
25 # which can be discarded.
26 head -c 4 $pipe >/dev/null 
28 # Wait for ctprof_srv to report recording state 
29 while true
30 do
31     if read line <$pipe; then
32         if [[ "$line" == 'ctprof recording' ]]; then
33             break
34         fi
35     fi
36 done
38 # Execute the argument
39 echo "execute:$@"
40 eval $@
42 # Wait for ctprof_srv to report client disconnect
43 while true
44 do
45     if read line <$pipe; then
46         if [[ "$line" == 'client terminate' ]]; then
47             break
48         fi
49     fi
50     if [[ ! -f $pipe ]]; then
51         break
52     fi
54 done
56 echo "ctprof_sync exiting"