summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Deao2013-08-21 15:34:01 -0500
committerDoug Deao2013-08-21 15:34:01 -0500
commit2905d556c486fafa1bfdbeaee5177c53ff9cba28 (patch)
tree9547ef76ce2262233b0f6e274b8b345b06dfd8b9
parent0b2d677e1a958092321fe3b64be90e9cccd6e67f (diff)
downloadctprof_srv-2905d556c486fafa1bfdbeaee5177c53ff9cba28.tar.gz
ctprof_srv-2905d556c486fafa1bfdbeaee5177c53ff9cba28.tar.xz
ctprof_srv-2905d556c486fafa1bfdbeaee5177c53ff9cba28.zip
Added ctprof_sync.sh to release and updated ctprof_srv to supportBUILD_CTOOLSPROF_1.0_080913
a termination option when the clinet disconnects.
-rw-r--r--RELEASE_NOTES35
-rw-r--r--ctprof_sync.sh52
-rw-r--r--example_app/ctprof_utility.c7
-rw-r--r--server/ctoolsprof.h1
-rw-r--r--server/ctoolsprof_srv_main.c32
-rw-r--r--server/remote_commands.c15
6 files changed, 115 insertions, 27 deletions
diff --git a/RELEASE_NOTES b/RELEASE_NOTES
index 2631017..2781a40 100644
--- a/RELEASE_NOTES
+++ b/RELEASE_NOTES
@@ -1,7 +1,7 @@
1ctprof_srv 1ctprof_srv
2 2
3Version 1.0 3Version 1.0
4Release Date: 8/6/2013 4Release Date: 8/21/2013
5 5
6Description 6Description
7=========== 7===========
@@ -29,22 +29,27 @@ Both the server and example_app have makefiles.
29Make & Installation 29Make & Installation
30=================== 30===================
31 31
32If using SC-MCSDK 02.02.00 then ctprof_srv and ctprof_ex should be 32If using SC-MCSDK 02.02.00 then ctprof_srv, ctprof_ex, and ctprof_sync.sh are
33pre-installed in the /usr directory. Otherwise: 33pre-installed in the /usr/bin directory. Otherwise, the server and example_app
34 34directories contain makefiles that utilizes the CROSS_COMPILE environment
35The server and example_app directories contain makefiles that utilizes the 35variable. Both release and debug versions can be made. The executable is
36CROSS_COMPILE environment variable. Both release and debug versions can be made. 36saved in the release or debug directories.
37The executable is saved in the release or debug directories.
38 37
39Examples: 38Examples:
40 39
41make clean debug 40make with CROSS_COMPILE:
42make clean release 41make clean debug arm install DESTDIR=/your/favorite/utility/dir
43make clean release install DESTDIR=/your/favorite/utility/dir 42make clean release arm install DESTDIR=/your/favorite/utility/dir
44make clean all (make both the debug and release versions) 43
44Make with your favorite compiler:
45make CC=target-gcc clean debug install DESTDIR=/your/favorite/utility/dir
46make CC=target-gcc clean release install DESTDIR=/your/favorite/utility/dir
47
48make all:
49make all DESTDIR=/your/favorite/utility/dir (same as: make clean release arm
50 install DESTDIR=)
45 51
46Typically the executable files will need to be copied to the appropriate target 52The ctprof_srv directory
47system's Linux bin directory.
48 53
49System Requirements 54System Requirements
50=================== 55===================
@@ -63,7 +68,7 @@ $ctprof_srv &
63 68
64Use -h to see options. 69Use -h to see options.
65 70
66The client is then used from a host to connect to the server and issue 71The ctprof utility is then used from a host to connect to the server and issue
67use case commands (like measure utilized bandwidth or latency of a specific 72use case commands (like measure utilized bandwidth or latency of a specific
68slave) that are serviced by ctprof_srv through a socket interface. 73slave) that are serviced by ctprof_srv through a socket interface.
69 74
@@ -73,7 +78,7 @@ examples.
73History 78History
74======= 79=======
75 80
768/6/2013 - First release 818/21/2013 - First release
77 82
78 83
79Known Deficiencies 84Known Deficiencies
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"
diff --git a/example_app/ctprof_utility.c b/example_app/ctprof_utility.c
index 1778a9c..d3a836d 100644
--- a/example_app/ctprof_utility.c
+++ b/example_app/ctprof_utility.c
@@ -58,11 +58,10 @@ static bool fifo_opened = false;
58 * Note - all messages are the same size in bytes. 58 * Note - all messages are the same size in bytes.
59 */ 59 */
60static const char msg_recording[] = "ctprof recording\n"; 60static const char msg_recording[] = "ctprof recording\n";
61static const char msg_stopped[] = "ctprof stopped \n"; 61static const char msg_stopped[] = "ctprof stopped__\n";
62static const char msg_ready[] = "ctprof ready \n"; 62static const char msg_ready[] = "ctprof ready____\n";
63static char readbuf[sizeof(msg_recording)]; 63static char readbuf[sizeof(msg_recording)];
64 64
65
66/* Note: This implementation uses named pipes for very 65/* Note: This implementation uses named pipes for very
67 * simple ipc. This could be changed in the future to 66 * simple ipc. This could be changed in the future to
68 * use sockets or some other ipc so check the requirements 67 * use sockets or some other ipc so check the requirements
@@ -122,7 +121,7 @@ ctprof_state_t ctprof_get_state(void)
122 * until data is avaiable. 121 * until data is avaiable.
123 */ 122 */
124 if (fifo_opened) { 123 if (fifo_opened) {
125 ctprof_pipe_read(readbuf, sizeof(readbuf)); 124 ctprof_pipe_read(readbuf, sizeof(readbuf)-1);
126 125
127 if (0 == strcmp(readbuf, msg_recording)) { 126 if (0 == strcmp(readbuf, msg_recording)) {
128 return CTPROF_RECORDING; 127 return CTPROF_RECORDING;
diff --git a/server/ctoolsprof.h b/server/ctoolsprof.h
index 0674057..83e31e6 100644
--- a/server/ctoolsprof.h
+++ b/server/ctoolsprof.h
@@ -52,6 +52,7 @@ extern char * g_whoami;
52extern bool g_fifo_used; 52extern bool g_fifo_used;
53extern bool g_fifo_enabled; 53extern bool g_fifo_enabled;
54extern int g_fifo_fd; 54extern int g_fifo_fd;
55extern bool g_terminate;
55 56
56extern bool g_interactive_mode; 57extern bool g_interactive_mode;
57 58
diff --git a/server/ctoolsprof_srv_main.c b/server/ctoolsprof_srv_main.c
index fd7d03e..4d17b43 100644
--- a/server/ctoolsprof_srv_main.c
+++ b/server/ctoolsprof_srv_main.c
@@ -74,6 +74,13 @@ bool g_fifo_enabled = false;
74int g_fifo_fd = -1; 74int g_fifo_fd = -1;
75static char * fifo_filename = "ctprof_fifo"; 75static char * fifo_filename = "ctprof_fifo";
76 76
77/* g_terminate is used to terminate the server on a disconnect from the client.
78 * AND it will not allow g_fifo_enabled to be set false (which causes
79 * the server to block trying to open the pipe again).
80 */
81bool g_terminate = false;
82static const char msg_terminate[] = "client terminate\n";
83
77static int cmd_port = 54242; 84static int cmd_port = 54242;
78static int etb_port = 54243; 85static int etb_port = 54243;
79//static int log_port = 54244; 86//static int log_port = 54244;
@@ -205,9 +212,11 @@ int main(int argc, char *argv[])
205 {"quiet", no_argument, 0,'q'}, 212 {"quiet", no_argument, 0,'q'},
206 {"help", no_argument, 0, 'h'}, 213 {"help", no_argument, 0, 'h'},
207 {"logging", required_argument, 0, 'l'}, 214 {"logging", required_argument, 0, 'l'},
208 {"version", no_argument, 0, 'v'} 215 {"version", no_argument, 0, 'v'},
216 {"terminate", no_argument, 0, 't'}
209 }; 217 };
210 char * short_options = "p:qhl:vP"; 218
219 char * short_options = "p:qhl:vPt";
211 int option, option_index = 0; 220 int option, option_index = 0;
212 221
213 option = getopt_long(argc, argv, short_options, long_options, &option_index); 222 option = getopt_long(argc, argv, short_options, long_options, &option_index);
@@ -255,6 +264,7 @@ int main(int argc, char *argv[])
255 fprintf(g_stdout, " --port/-p <ip port> Set port value\n"); 264 fprintf(g_stdout, " --port/-p <ip port> Set port value\n");
256 fprintf(g_stdout, " --pipe/-P Issue server recording state over a named pipe\n"); 265 fprintf(g_stdout, " --pipe/-P Issue server recording state over a named pipe\n");
257 fprintf(g_stdout, " --quiet/-q Send stdout to /dev/null\n"); 266 fprintf(g_stdout, " --quiet/-q Send stdout to /dev/null\n");
267 fprintf(g_stdout, " --terminate/-t Terminate server on disconnect from client\n");
258 fprintf(g_stdout, " --version/-v Print version\n"); 268 fprintf(g_stdout, " --version/-v Print version\n");
259 fprintf(g_stdout, "\n"); 269 fprintf(g_stdout, "\n");
260 exit(0); 270 exit(0);
@@ -273,6 +283,9 @@ int main(int argc, char *argv[])
273 g_whoami); 283 g_whoami);
274 break; 284 break;
275 } 285 }
286 case 't':
287 g_terminate = true;
288 break;
276 case 'v': 289 case 'v':
277 fprintf(g_stdout, "%s:version %d.%d\n", g_whoami, g_major_version, 290 fprintf(g_stdout, "%s:version %d.%d\n", g_whoami, g_major_version,
278 g_minor_version); 291 g_minor_version);
@@ -286,6 +299,8 @@ int main(int argc, char *argv[])
286 299
287 } 300 }
288 301
302 socket_connect();
303
289 /* This loop is the heart of the server! */ 304 /* This loop is the heart of the server! */
290 do { 305 do {
291 306
@@ -294,6 +309,19 @@ int main(int argc, char *argv[])
294 */ 309 */
295 if (global_state.socket_disconnect) { 310 if (global_state.socket_disconnect) {
296 LOGMSG1("%s:socket disconnect detected. listening for client connection.", __func__); 311 LOGMSG1("%s:socket disconnect detected. listening for client connection.", __func__);
312
313 if (g_terminate) {
314 if (g_fifo_enabled) {
315 char * broken_pipe_msg = "terminating";
316 remote_pipe_write(msg_terminate, strlen(msg_terminate), broken_pipe_msg);
317
318 LOGMSG1("%s:write to the pipe %s", __func__, msg_terminate);
319 }
320
321 clean_up();
322 exit(0);
323 }
324
297 socket_connect(); 325 socket_connect();
298 } 326 }
299 327
diff --git a/server/remote_commands.c b/server/remote_commands.c
index e459937..90d06a9 100644
--- a/server/remote_commands.c
+++ b/server/remote_commands.c
@@ -100,8 +100,8 @@ static char * etb_mode_table[] = {
100 100
101/* Note these strings must all be the same size */ 101/* Note these strings must all be the same size */
102static const char msg_recording[] = "ctprof recording\n"; 102static const char msg_recording[] = "ctprof recording\n";
103static const char msg_stopped[] = "ctprof stopped \n"; 103static const char msg_stopped[] = "ctprof stopped__\n";
104static const char msg_ready[] = "ctprof ready \n"; 104static const char msg_ready[] = "ctprof ready____\n";
105 105
106/***************************************************************************** 106/*****************************************************************************
107 * Internal Function Prototypes 107 * Internal Function Prototypes
@@ -646,7 +646,7 @@ void start_recording()
646 646
647 if (g_fifo_enabled) { 647 if (g_fifo_enabled) {
648 char * broken_pipe_msg = "recording status"; 648 char * broken_pipe_msg = "recording status";
649 remote_pipe_write(msg_recording, sizeof(msg_recording), broken_pipe_msg); 649 remote_pipe_write(msg_recording, strlen(msg_recording), broken_pipe_msg);
650 650
651 LOGMSG1("%s:write to the pipe %s", __func__, msg_recording); 651 LOGMSG1("%s:write to the pipe %s", __func__, msg_recording);
652 } 652 }
@@ -707,11 +707,14 @@ void stop_recording()
707 LOGMSG2("%s:write msg_stopped to pipe", __func__); 707 LOGMSG2("%s:write msg_stopped to pipe", __func__);
708 708
709 char * broken_pipe_msg = "stopped status"; 709 char * broken_pipe_msg = "stopped status";
710 remote_pipe_write(msg_stopped, sizeof(msg_stopped), broken_pipe_msg); 710 remote_pipe_write(msg_stopped, strlen(msg_stopped), broken_pipe_msg);
711 711
712 LOGMSG1("%s:write to the pipe %s", __func__, msg_stopped); 712 LOGMSG1("%s:write to the pipe %s", __func__, msg_stopped);
713 713
714 g_fifo_enabled = false; 714 if (!g_terminate) {
715 g_fifo_enabled = false;
716 }
717
715 } 718 }
716 719
717 fprintf(g_stdout, "\r%s:Recording stopped\n", g_whoami); 720 fprintf(g_stdout, "\r%s:Recording stopped\n", g_whoami);
@@ -890,7 +893,7 @@ void start_command_handler(int argc, char *argv[], char * rbuf, size_t rsp_size)
890 /* If signal_active is true send the ready message to the app. */ 893 /* If signal_active is true send the ready message to the app. */
891 if ((global_state.signal_active == true) && (g_fifo_enabled)) { 894 if ((global_state.signal_active == true) && (g_fifo_enabled)) {
892 char * broken_pipe_msg = "ready status"; 895 char * broken_pipe_msg = "ready status";
893 remote_pipe_write(msg_ready, sizeof(msg_ready), broken_pipe_msg); 896 remote_pipe_write(msg_ready, strlen(msg_ready), broken_pipe_msg);
894 897
895 LOGMSG1("%s:write to the pipe %s", __func__, msg_ready); 898 LOGMSG1("%s:write to the pipe %s", __func__, msg_ready);
896 } 899 }