summaryrefslogtreecommitdiffstats
blob: 11fb0d2a730604a6f7efb56cebdaadd01cb97507 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash

if [ "$#" -lt "1" ]; then
    echo "Usage: ctprof_sync.sh cmd [options]"
    echo "       ctprof_sync.sh will start ctprof_srv, wait for the clinet to"
    echo "       start a trace session, execute the cmd, and then wait for the"
    echo "       client to disconnect from ctprof_srv, terminating the session."
    exit
fi

# Start the server
ctprof_srv -Pt &

pipe=./ctprof_fifo

# Wait for ctprof_srv to create the pipe
while true
do 
    if [[ -p $pipe ]]; then
        break
    fi
done

# First 4 bytes from ctprof_srv is it's pid
# which can be discarded.
head -c 4 $pipe >/dev/null 

# Wait for ctprof_srv to report recording state 
while true
do
    if read line <$pipe; then
        if [[ "$line" == 'ctprof recording' ]]; then
            break
        fi
    fi
done

# Execute the argument
echo "execute:$@"
eval $@

# Wait for ctprof_srv to report client disconnect
while true
do
    if read line <$pipe; then
        if [[ "$line" == 'client terminate' ]]; then
            break
        fi
    fi
    if [[ ! -f $pipe ]]; then
        break
    fi

done

echo "ctprof_sync exiting"