summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'ctprof_sync.sh')
-rw-r--r--ctprof_sync.sh52
1 files changed, 52 insertions, 0 deletions
diff --git a/ctprof_sync.sh b/ctprof_sync.sh
new file mode 100644
index 0000000..5819670
--- /dev/null
+++ b/ctprof_sync.sh
@@ -0,0 +1,52 @@
1#!/bin/bash
2
3if [ "$#" -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
9fi
10
11# Start the server
12ctprof_srv -Pt &
13
14pipe=./ctprof_fifo
15
16# Wait for ctprof_srv to create the pipe
17while true
18do
19 if [[ -p $pipe ]]; then
20 break
21 fi
22done
23
24# First 4 bytes from ctprof_srv is it's pid
25# which can be discarded.
26head -c 4 $pipe >/dev/null
27
28# Wait for ctprof_srv to report recording state
29while true
30do
31 if read line <$pipe; then
32 if [[ "$line" == 'ctprof recording' ]]; then
33 break
34 fi
35 fi
36done
37
38# Execute the argument
39echo "execute:$@"
40eval $@
41
42# Wait for ctprof_srv to report client disconnect
43while true
44do
45 if read line <$pipe; then
46 if [[ "$line" == 'client terminate' ]]; then
47 break
48 fi
49 fi
50done
51
52echo "ctprof_sync exiting"