summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Deao2013-08-09 11:03:53 -0500
committerDoug Deao2013-08-09 11:03:53 -0500
commit0b2d677e1a958092321fe3b64be90e9cccd6e67f (patch)
treeeda3d9f372844dc869452a127bf77e5632933aca
parent656421425b7ca41064d4e726d8c6e6f453d83851 (diff)
downloadctprof_srv-0b2d677e1a958092321fe3b64be90e9cccd6e67f.tar.gz
ctprof_srv-0b2d677e1a958092321fe3b64be90e9cccd6e67f.tar.xz
ctprof_srv-0b2d677e1a958092321fe3b64be90e9cccd6e67f.zip
Release 1.0. See the RELEASE_NOTES file for details.
-rw-r--r--RELEASE_NOTES16
-rw-r--r--example_app/ctprof_utility.c28
-rw-r--r--example_app/makefile24
-rw-r--r--server/ctoolsprof_srv_main.c22
-rw-r--r--server/etb_handler.c34
-rw-r--r--server/makefile21
-rw-r--r--server/remote_commands.c100
-rw-r--r--server/remote_commands.h1
-rw-r--r--server/signal_handler.c1
-rw-r--r--server/socket.c6
10 files changed, 150 insertions, 103 deletions
diff --git a/RELEASE_NOTES b/RELEASE_NOTES
index 60b59d2..2631017 100644
--- a/RELEASE_NOTES
+++ b/RELEASE_NOTES
@@ -1,19 +1,19 @@
1ctprof_srv 1ctprof_srv
2 2
3Version 1.0 3Version 1.0
4Release Date: 7/32/2013 4Release Date: 8/6/2013
5 5
6Description 6Description
7=========== 7===========
8 8
9Ctprof provides system level bus profiling use cases for any slave in the 9Ctprof provides system level bus profiling use cases for any slave bus in
10device that has a CP Tracer. Ctprof is made up of two components; ctprof 10the device that has a CP Tracer. Ctprof is made up of two components; ctprof
11which is the host client application, and ctprof_srv which is the target 11which is the host client application, and ctprof_srv which is the target
12server application. The client is delivered with TI's CCS emupacks (see 12server application. The client is delivered with TI's CCS emupacks (see
13System Requirements for minimum emupack revision for this release) and can be 13System Requirements for minimum emupack revision for this release) and can be
14installed independent of CCS. The server is delivered as source with an example 14installed independent of CCS. The server is delivered as source with an example
15application which also contains a small "C" file that can be integrated with 15application which also contains a small "C" file that can be integrated with
16your application for coordinating collection activity with ctprof_srv. 16your application for coordinating ctprof_srv's trace collection activity.
17 17
18Organization 18Organization
19============ 19============
@@ -49,7 +49,7 @@ system's Linux bin directory.
49System Requirements 49System Requirements
50=================== 50===================
51 51
52- A Host Linux machine (Ubuntu 10.4 or higher) with emupack 5.1.NNN.0 installed. 52- A Host Linux machine (Ubuntu 10.4 or higher) with emupack M8 installed.
53- A TCI6414 EVM or equivalent target system with a working network connection 53- A TCI6414 EVM or equivalent target system with a working network connection
54 (TCP is used). 54 (TCP is used).
55- Requires the SC-MCSDK 02.02.00 Linux image. 55- Requires the SC-MCSDK 02.02.00 Linux image.
@@ -67,13 +67,13 @@ The client 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 67use case commands (like measure utilized bandwidth or latency of a specific
68slave) that are serviced by ctprof_srv through a socket interface. 68slave) that are serviced by ctprof_srv through a socket interface.
69 69
70See http://processors.wiki.ti.com/index.php/CToolsLib/ctoolsprof for 70See http://processors.wiki.ti.com/index.php/Ctprof for documentation and
71documentation and examples. 71examples.
72 72
73History 73History
74======= 74=======
75 75
76July 31/2013 - First release 768/6/2013 - First release
77 77
78 78
79Known Deficiencies 79Known Deficiencies
diff --git a/example_app/ctprof_utility.c b/example_app/ctprof_utility.c
index 3d1320d..1778a9c 100644
--- a/example_app/ctprof_utility.c
+++ b/example_app/ctprof_utility.c
@@ -43,23 +43,24 @@
43#include <unistd.h> 43#include <unistd.h>
44#include <fcntl.h> 44#include <fcntl.h>
45#include <signal.h> 45#include <signal.h>
46#include <errno.h>
46#include "ctprof_utility.h" 47#include "ctprof_utility.h"
47 48
48static char * fifo_filename = "ctprof_fifo"; 49static char * fifo_filename = "ctprof_fifo";
49//static FILE * fp; 50//static FILE * fp;
50static int ctprof_pipe_fd; 51static int ctprof_pipe_fd;
51static bool fifo_opened = false; 52static bool fifo_opened = false;
52static char readbuf[32];
53 53
54/* State definitions 54/* State definitions
55 * ready - ctprof_srv is ready for a signal 55 * ready - ctprof_srv is ready for a signal
56 * recording - ctprof_srv is recording 56 * recording - ctprof_srv is recording
57 * stopped - ctprof_srv has stopped recording 57 * stopped - ctprof_srv has stopped recording
58 * Note - all messages are the same size in bytes.
58 */ 59 */
59static const char msg_recording[] = "ctprof recording\n"; 60static const char msg_recording[] = "ctprof recording\n";
60static const char msg_stopped[] = "ctprof stopped\n"; 61static const char msg_stopped[] = "ctprof stopped \n";
61static const char msg_ready[] = "ctprof ready\n"; 62static const char msg_ready[] = "ctprof ready \n";
62 63static char readbuf[sizeof(msg_recording)];
63 64
64 65
65/* Note: This implementation uses named pipes for very 66/* Note: This implementation uses named pipes for very
@@ -70,6 +71,20 @@ static const char msg_ready[] = "ctprof ready\n";
70 71
71static pid_t ctprof_srv_pid; 72static pid_t ctprof_srv_pid;
72 73
74void ctprof_pipe_read(char * rd_buf_p, size_t rd_bytecnt)
75{
76 while(rd_bytecnt > 0) {
77 size_t rc = read(ctprof_pipe_fd, rd_buf_p, rd_bytecnt);
78
79 if (( rc == -1) && (errno = EINTR)) {
80 continue;
81 }
82
83 rd_buf_p += rc;
84 rd_bytecnt -= rc;
85 }
86}
87
73int ctprof_pipe_open(void) 88int ctprof_pipe_open(void)
74{ 89{
75 /* If fifo can't be opend then return -1 */ 90 /* If fifo can't be opend then return -1 */
@@ -80,8 +95,7 @@ int ctprof_pipe_open(void)
80 fifo_opened = true; 95 fifo_opened = true;
81 } 96 }
82 97
83 read(ctprof_pipe_fd, &ctprof_srv_pid, sizeof(pid_t)); 98 ctprof_pipe_read((char *)&ctprof_srv_pid, sizeof(pid_t));
84
85} 99}
86 100
87void ctprof_pipe_close(void) 101void ctprof_pipe_close(void)
@@ -108,7 +122,7 @@ ctprof_state_t ctprof_get_state(void)
108 * until data is avaiable. 122 * until data is avaiable.
109 */ 123 */
110 if (fifo_opened) { 124 if (fifo_opened) {
111 read(ctprof_pipe_fd, readbuf, sizeof(readbuf)); 125 ctprof_pipe_read(readbuf, sizeof(readbuf));
112 126
113 if (0 == strcmp(readbuf, msg_recording)) { 127 if (0 == strcmp(readbuf, msg_recording)) {
114 return CTPROF_RECORDING; 128 return CTPROF_RECORDING;
diff --git a/example_app/makefile b/example_app/makefile
index 6371d48..1b5a5c4 100644
--- a/example_app/makefile
+++ b/example_app/makefile
@@ -2,22 +2,22 @@
2# makefile for ctoolsprof server 2# makefile for ctoolsprof server
3# 3#
4# examples: 4# examples:
5# make debug install 5# make clean debug CC=your-favorite-gcc DESTDIR=your-destination-dir install
6# make release install 6# make clean release CC=your-favorite-gcc DESTDIR=your-destination-dir install
7# make clean debug install 7# To Use CROSS_COMPILE:
8# make clean release install OR make all 8# make clean debug arm DESTDIR=your-destination-dir install
9# make clean release arm DESTDIR=your-destination-dir install
10# make arm all DESTDIR=your-destination-dir
9 11
10ifeq ($(findstring arm, $(MAKECMDGOALS)), arm) 12ifeq ($(findstring arm, $(MAKECMDGOALS)), arm)
11 CC= $(CROSS_COMPILE)gcc --static 13 CC= $(CROSS_COMPILE)gcc
12else
13 CC = gcc
14endif 14endif
15 15
16ifeq ($(findstring debug, $(MAKECMDGOALS)), debug) 16ifeq ($(findstring debug, $(MAKECMDGOALS)), debug)
17 CFLAGS= -std=c99 -c -g -Wall $(INC_PATH) -D DEBUG -D _GNU_SOURCE $(TEST) 17 CFLAGS= -std=c99 -c -g -Wall $(INC_PATH) -D DEBUG -D _GNU_SOURCE
18 OBJDIR= ./debug 18 OBJDIR= ./debug
19else 19else
20 CFLAGS= -std=c99 -c -O2 $(INC_PATH) -D SERVER -D _GNU_SOURCE $(TEST) 20 CFLAGS= -std=c99 -c -O2 $(INC_PATH) -D SERVER -D _GNU_SOURCE
21 OBJDIR= ./release 21 OBJDIR= ./release
22endif 22endif
23LFLAGS = 23LFLAGS =
@@ -27,7 +27,7 @@ INCLUDE_PATH = -I ../example_app
27 27
28.PHONY: clean debug release install arm 28.PHONY: clean debug release install arm
29 29
30all: clean release install 30all: clean release arm install
31 31
32# 32#
33# Declare.c and .h dependencies 33# Declare.c and .h dependencies
@@ -52,7 +52,7 @@ $(OBJDIR)/%.o: %.c
52 52
53ctprof_ex: $(OBJECTS) 53ctprof_ex: $(OBJECTS)
54 @echo "Building target" $@ 54 @echo "Building target" $@
55 $(CC) $(LFLAGS) $(LIBS_PATH) -o $@ $(OBJECTS) $(LIBS) 55 $(CC) $(LFLAGS) $(LIBS_PATH) -o $(OBJDIR)/$@ $(OBJECTS) $(LIBS)
56 56
57debug: ctprof_ex 57debug: ctprof_ex
58 @echo "debug build complete" 58 @echo "debug build complete"
@@ -64,7 +64,7 @@ arm: ctprof_ex
64 @echo "ARM version built" 64 @echo "ARM version built"
65 65
66install: 66install:
67 mv ctprof_ex ~/bin/ctprof_ex 67 mv $(OBJDIR)/ctprof_ex $(DESTDIR)
68 68
69clean: 69clean:
70 -rm $(OBJECTS) 70 -rm $(OBJECTS)
diff --git a/server/ctoolsprof_srv_main.c b/server/ctoolsprof_srv_main.c
index c5c79d9..fd7d03e 100644
--- a/server/ctoolsprof_srv_main.c
+++ b/server/ctoolsprof_srv_main.c
@@ -293,7 +293,7 @@ int main(int argc, char *argv[])
293 * client connects. 293 * client connects.
294 */ 294 */
295 if (global_state.socket_disconnect) { 295 if (global_state.socket_disconnect) {
296 LOGMSG2("%s:global_state.socket_disconnect is true", __func__); 296 LOGMSG1("%s:socket disconnect detected. listening for client connection.", __func__);
297 socket_connect(); 297 socket_connect();
298 } 298 }
299 299
@@ -304,7 +304,7 @@ int main(int argc, char *argv[])
304 "Waiting on pipe to be open for reading.\n", 304 "Waiting on pipe to be open for reading.\n",
305 g_whoami); 305 g_whoami);
306 306
307 LOGMSG2("%s:Opening pipe for writing.", __func__); 307 LOGMSG1("%s:Opening %s for writing.", __func__, fifo_filename);
308 308
309 if ((g_fifo_fd = open(fifo_filename, O_WRONLY)) == -1) { 309 if ((g_fifo_fd = open(fifo_filename, O_WRONLY)) == -1) {
310 fprintf(g_stderr, "%s:Can't open %s fifo file", g_whoami, 310 fprintf(g_stderr, "%s:Can't open %s fifo file", g_whoami,
@@ -313,28 +313,24 @@ int main(int argc, char *argv[])
313 } 313 }
314 314
315 fprintf(g_stdout,"%s:pipe open for reading\n", g_whoami); 315 fprintf(g_stdout,"%s:pipe open for reading\n", g_whoami);
316 LOGMSG2("%s:pipe open for reading", __func__); 316 LOGMSG1("%s:%s open for reading", __func__, fifo_filename);
317 } 317 }
318 318
319 /* If the fifo is used (set by command line -P option) but it is not 319 /* If the fifo is used (set by command line -P option) but it is not
320 * enabled, time to enable it and send the first message (the server's pid). 320 * enabled, time to enable it and send the first message (the server's pid).
321 */ 321 */
322 if ((g_fifo_used == true) && (g_fifo_enabled == false)) { 322 if ((g_fifo_used == true) && (g_fifo_enabled == false)) {
323 size_t wr_bytecnt;
324 g_fifo_enabled = true; 323 g_fifo_enabled = true;
325 324
326 /* First message written is this task's pid */ 325 /* First message written is this task's pid */
327 pid_t mypid = getpid(); 326 pid_t mypid = getpid();
328 wr_bytecnt = write(g_fifo_fd, &mypid, sizeof(pid_t));
329 327
330 if ((wr_bytecnt == -1) && (errno == EPIPE)) { 328 char * broken_pipe_msg = "ctprof_srv's pid";
331 fprintf(g_stdout,"%s:warning - pipe reading end closed when sending pid.\n" 329 remote_pipe_write((char *)&mypid, sizeof(pid_t), broken_pipe_msg);
332 "%s: This can be caused by issuing a client operation before\n"
333 "%s: starting the task that opens the pipe's reading end.\n",
334 g_whoami, g_whoami, g_whoami);
335 }
336 330
337 LOGMSG2("%s:write my pid %d to pipe", __func__, mypid); 331 LOGMSG1("%s:write to the pipe %d", __func__, mypid);
332
333 LOGMSG1("%s:wrote ctprof_srv pid %d to %s", __func__, mypid, fifo_filename);
338 } 334 }
339 335
340#if DEBUG 336#if DEBUG
diff --git a/server/etb_handler.c b/server/etb_handler.c
index 1d6d498..d820da2 100644
--- a/server/etb_handler.c
+++ b/server/etb_handler.c
@@ -87,6 +87,7 @@ static const int etb_word_size = sizeof(uint32_t);
87#endif 87#endif
88 88
89static bool etb_is_enabled = false; 89static bool etb_is_enabled = false;
90static bool etb_disabled_wrapped = false;
90static int etb_words_queued = 0; 91static int etb_words_queued = 0;
91 92
92/***************************************************************************** 93/*****************************************************************************
@@ -162,7 +163,8 @@ void etb_config(etb_bufmode_t mode, etb_core_id_t core_id)
162 */ 163 */
163 { 164 {
164#ifndef TEST_MODE 165#ifndef TEST_MODE
165 LOGMSG1("%s:Calling ETB_open, mode is %d, core id is %d", __func__, etb_mode, etb_core_id); 166 LOGMSG1("%s:Calling ETB_open, mode is %d, core id is %d", __func__,
167 etb_mode, etb_core_id);
166 ETB_errorCallback etb_err_callback = NULL; 168 ETB_errorCallback etb_err_callback = NULL;
167 etb_ret = ETB_open(etb_err_callback, etb_mode, etb_core_id, 169 etb_ret = ETB_open(etb_err_callback, etb_mode, etb_core_id,
168 &etb_handle, &etb_size); 170 &etb_handle, &etb_size);
@@ -296,6 +298,7 @@ void etb_enable()
296#endif 298#endif
297 299
298 etb_is_enabled = true; 300 etb_is_enabled = true;
301 etb_disabled_wrapped = false;
299} 302}
300 303
301/***************************************************************************** 304/*****************************************************************************
@@ -317,6 +320,17 @@ void etb_disable()
317 LOGMSG1("%s:ETB_disable error %d", __func__, etb_ret); 320 LOGMSG1("%s:ETB_disable error %d", __func__, etb_ret);
318 err_handler(ERR_TYPE_LOCAL, ERR_ETB_ISSUE); 321 err_handler(ERR_TYPE_LOCAL, ERR_ETB_ISSUE);
319 } 322 }
323
324 /* Need to cache the wrapped status before any ETB_reads. */
325 ETBStatus etb_status;
326 etb_ret = ETB_status(etb_handle, &etb_status);
327 if (etb_ret != eETB_Success) {
328
329 LOGMSG1("%s:ETB_status error %d", __func__, etb_ret);
330 err_handler(ERR_TYPE_LOCAL, ERR_ETB_ISSUE);
331 }
332 etb_disabled_wrapped = (etb_status.isWrapped) ? true : false;
333
320#endif 334#endif
321 etb_is_enabled = false; 335 etb_is_enabled = false;
322} 336}
@@ -341,7 +355,9 @@ void etb_add_queue(etb_queue_limit_t limit)
341 int etb_word_cnt = etb_data_available(&is_wrapped); 355 int etb_word_cnt = etb_data_available(&is_wrapped);
342 356
343 if (etb_queue_cnt == max_queue_depth) { 357 if (etb_queue_cnt == max_queue_depth) {
344 LOGMSG1("%s:Max queue depth reached - this most likely indicates the trace data capture rate is to high. Try decreasing the sample rate", __func__); 358 LOGMSG1("%s:Max queue depth reached - this most likely indicates the "
359 "trace data capture rate is to high. Try decreasing the sample "
360 "rate", __func__);
345 err_handler(ERR_TYPE_LOCAL, ERR_ETB_ISSUE); 361 err_handler(ERR_TYPE_LOCAL, ERR_ETB_ISSUE);
346 } 362 }
347 363
@@ -479,7 +495,14 @@ static int etb_data_available(bool * wrapped)
479 LOGMSG1("%s: overflow 0x%x", __func__, etb_status.overflow); 495 LOGMSG1("%s: overflow 0x%x", __func__, etb_status.overflow);
480 } 496 }
481 497
482 *wrapped = (etb_status.isWrapped) ? true : false; 498 /* ETB wrapped status is only valid while the etb is enabled. Once the ETB
499 * is disabled and any data read the wrapped status is not valid from ETBLib.
500 */
501 if (etb_is_enabled) {
502 *wrapped = (etb_status.isWrapped) ? true : false;
503 } else {
504 *wrapped = etb_disabled_wrapped;
505 }
483 506
484 if ((global_state.etb_mode == ETB_MODE_DRAIN) && (etb_status.overflow)) { 507 if ((global_state.etb_mode == ETB_MODE_DRAIN) && (etb_status.overflow)) {
485 508
@@ -614,8 +637,9 @@ static void etb_process_data(int etb_word_cnt)
614#else 637#else
615 read_size = fread(etb_queue_element->buf_start, sizeof(uint32_t), 638 read_size = fread(etb_queue_element->buf_start, sizeof(uint32_t),
616 (size_t)etb_word_cnt, test_fp); 639 (size_t)etb_word_cnt, test_fp);
617 //TODO Remove to optimize 640
618 LOGMSG1("%s:Test Mode, requested %d words, read %d words", __func__,etb_word_cnt, read_size); 641 LOGMSG1("%s:Test Mode, requested %d words, read %d words", __func__,
642 etb_word_cnt, read_size);
619 if ((read_size < etb_word_cnt) && (ferror(test_fp))) { 643 if ((read_size < etb_word_cnt) && (ferror(test_fp))) {
620 etb_ret = eETB_Error_Cannot_Read; 644 etb_ret = eETB_Error_Cannot_Read;
621 645
diff --git a/server/makefile b/server/makefile
index 8e529ea..de76d0e 100644
--- a/server/makefile
+++ b/server/makefile
@@ -2,16 +2,15 @@
2# makefile for ctprof_srv 2# makefile for ctprof_srv
3# 3#
4# examples: 4# examples:
5# make debug arm install 5# make clean debug CC=your-favorite-gcc DESTDIR=your-destination-dir install
6# make release arm install 6# make clean release CC=your-favorite-gcc DESTDIR=your-destination-dir install
7# make clean debug arm install 7# To Use CROSS_COMPILE:
8# make clean release arm install OR make all 8# make clean debug arm DESTDIR=your-destination-dir install
9# make debug arm test - Replaces ETBLib with a simulation of the ETB using a bin trace file 9# make clean release arm DESTDIR=your-destination-dir install
10# make arm all DESTDIR=your-destination-dir
10 11
11ifeq ($(findstring arm, $(MAKECMDGOALS)), arm) 12ifeq ($(findstring arm, $(MAKECMDGOALS)), arm)
12 CC= $(CROSS_COMPILE)gcc --static 13 CC= $(CROSS_COMPILE)gcc
13else
14 CC = gcc
15endif 14endif
16ifeq ($(findstring test, $(MAKECMDGOALS)), test) 15ifeq ($(findstring test, $(MAKECMDGOALS)), test)
17 TEST = -D TEST_MODE 16 TEST = -D TEST_MODE
@@ -28,7 +27,7 @@ else
28endif 27endif
29COMMON = ../common 28COMMON = ../common
30LFLAGS = 29LFLAGS =
31LIBS= -lpthread 30LIBS=
32LIB_PATH= 31LIB_PATH=
33INCLUDE_PATH = -I $(COMMON) -I ../server 32INCLUDE_PATH = -I $(COMMON) -I ../server
34 33
@@ -38,7 +37,7 @@ VPATH = $(COMMON)
38 37
39.PHONY: clean debug release install arm 38.PHONY: clean debug release install arm
40 39
41all: clean release install 40all: clean release arm install
42 41
43# 42#
44# Declare.c and .h dependencies 43# Declare.c and .h dependencies
@@ -82,7 +81,7 @@ test: ctprof_srv
82 @echo "Test version built - ETB file simulation" 81 @echo "Test version built - ETB file simulation"
83 82
84install: 83install:
85 mv ctprof_srv ~/bin/ctprof_srv 84 mv $(OBJDIR)/ctprof_srv $(DESTDIR)
86 85
87clean: 86clean:
88 -rm $(OBJECTS) 87 -rm $(OBJECTS)
diff --git a/server/remote_commands.c b/server/remote_commands.c
index 151c845..e459937 100644
--- a/server/remote_commands.c
+++ b/server/remote_commands.c
@@ -98,9 +98,10 @@ static char * etb_mode_table[] = {
98 [ETB_MODE_DRAIN] = "drain" 98 [ETB_MODE_DRAIN] = "drain"
99}; 99};
100 100
101/* Note these strings must all be the same size */
101static const char msg_recording[] = "ctprof recording\n"; 102static const char msg_recording[] = "ctprof recording\n";
102static const char msg_stopped[] = "ctprof stopped\n"; 103static const char msg_stopped[] = "ctprof stopped \n";
103static const char msg_ready[] = "ctprof ready\n"; 104static const char msg_ready[] = "ctprof ready \n";
104 105
105/***************************************************************************** 106/*****************************************************************************
106 * Internal Function Prototypes 107 * Internal Function Prototypes
@@ -236,7 +237,7 @@ void set_command_handler(int argc, char *argv[], char * rbuf, size_t rsp_size)
236 *****************************************************************************/ 237 *****************************************************************************/
237void version_command_handler(int argc, char *argv[], char * rbuf, size_t rsp_size) 238void version_command_handler(int argc, char *argv[], char * rbuf, size_t rsp_size)
238{ 239{
239 int sn_size; 240 LOGFUNC();
240 241
241#if DEBUG 242#if DEBUG
242 if ((argv == NULL) || (rbuf == NULL)) { 243 if ((argv == NULL) || (rbuf == NULL)) {
@@ -244,11 +245,16 @@ void version_command_handler(int argc, char *argv[], char * rbuf, size_t rsp_siz
244 } 245 }
245#endif 246#endif
246 247
247 sn_size = snprintf(rbuf, rsp_size,"%d.%d", g_major_version, g_minor_version); 248 char * msg;
249 int sn_size;
250
251 sn_size = snprintf(rbuf, rsp_size,"server version %d.%d, copyright %d,",
252 g_major_version, g_minor_version, g_copyright_year);
253
248#if DEBUG 254#if DEBUG
249 if (sn_size > rsp_size) { 255 if (sn_size > rsp_size) {
250 err_handler(ERR_TYPE_LOCAL, ERR_DEBUG); 256 err_handler(ERR_TYPE_LOCAL, ERR_DEBUG);
251 } 257 }
252#endif 258#endif
253 259
254} 260}
@@ -639,17 +645,10 @@ void start_recording()
639 } 645 }
640 646
641 if (g_fifo_enabled) { 647 if (g_fifo_enabled) {
642 size_t wr_bytecnt; 648 char * broken_pipe_msg = "recording status";
643 649 remote_pipe_write(msg_recording, sizeof(msg_recording), broken_pipe_msg);
644 LOGMSG2("%s:write msg_recording to pipe", __func__);
645 650
646 wr_bytecnt = write(g_fifo_fd, msg_recording, sizeof(msg_recording)); 651 LOGMSG1("%s:write to the pipe %s", __func__, msg_recording);
647 if ((wr_bytecnt == -1) && (errno == EPIPE)) {
648 fprintf(g_stdout,"%s:WARNING - pipe reading end closed when sending recording status.\n"
649 "%s: This can be caused by early termination of the task that\n"
650 "%s: opened the pipe's reading end.\n",
651 g_whoami, g_whoami, g_whoami);
652 }
653 } 652 }
654 653
655 fprintf(g_stdout, "\r%s:Recording started\n", g_whoami); 654 fprintf(g_stdout, "\r%s:Recording started\n", g_whoami);
@@ -704,17 +703,13 @@ void stop_recording()
704 } 703 }
705 704
706 if (g_fifo_enabled) { 705 if (g_fifo_enabled) {
707 size_t wr_bytecnt;
708 706
709 LOGMSG2("%s:write msg_stopped to pipe", __func__); 707 LOGMSG2("%s:write msg_stopped to pipe", __func__);
710 708
711 wr_bytecnt = write(g_fifo_fd, msg_stopped, sizeof(msg_stopped)); 709 char * broken_pipe_msg = "stopped status";
712 if ((wr_bytecnt == -1) && (errno == EPIPE)) { 710 remote_pipe_write(msg_stopped, sizeof(msg_stopped), broken_pipe_msg);
713 fprintf(g_stdout,"%s:WARNING - pipe reading end closed when sending stopped status.\n" 711
714 "%s: This can be caused by early termination of the task that\n" 712 LOGMSG1("%s:write to the pipe %s", __func__, msg_stopped);
715 "%s: opened the pipe's reading end.\n",
716 g_whoami, g_whoami, g_whoami);
717 }
718 713
719 g_fifo_enabled = false; 714 g_fifo_enabled = false;
720 } 715 }
@@ -894,19 +889,10 @@ void start_command_handler(int argc, char *argv[], char * rbuf, size_t rsp_size)
894 889
895 /* If signal_active is true send the ready message to the app. */ 890 /* If signal_active is true send the ready message to the app. */
896 if ((global_state.signal_active == true) && (g_fifo_enabled)) { 891 if ((global_state.signal_active == true) && (g_fifo_enabled)) {
897 size_t wr_bytecnt; 892 char * broken_pipe_msg = "ready status";
898 893 remote_pipe_write(msg_ready, sizeof(msg_ready), broken_pipe_msg);
899 wr_bytecnt = write(g_fifo_fd, msg_ready, sizeof(msg_ready));
900
901 LOGMSG2("%s:write msg_ready to pipe - write return value is %d errno"
902 " is %d", __func__, wr_bytecnt, errno);
903 if ((wr_bytecnt == -1) && (errno == EPIPE)) {
904 fprintf(g_stdout,"%s:WARNING - pipe reading end closed when sending ready status.\n"
905 "%s: This can be caused by issuing a client operation before\n"
906 "%s: starting the task that opens the pipe's reading end.\n",
907 g_whoami, g_whoami, g_whoami);
908 }
909 894
895 LOGMSG1("%s:write to the pipe %s", __func__, msg_ready);
910 } 896 }
911 897
912} 898}
@@ -967,9 +953,8 @@ void end_command_handler(int argc, char *argv[], char * rbuf, size_t rsp_size)
967 * The client is requesting status: 953 * The client is requesting status:
968 * 954 *
969 * - The status format is: 955 * - The status format is:
970 * recording or stopped, etb_bytes_available, server version x.y, copyright year, wrapped 956 * recording or stopped, etb_bytes_available, wrapped
971 * 957 *
972 * TODO - Separate version and copyright into a separate command (just ran out of time)!
973 *****************************************************************************/ 958 *****************************************************************************/
974void status_command_handler(int argc, char *argv[], char * rbuf, size_t rsp_size) 959void status_command_handler(int argc, char *argv[], char * rbuf, size_t rsp_size)
975{ 960{
@@ -1004,12 +989,10 @@ void status_command_handler(int argc, char *argv[], char * rbuf, size_t rsp_size
1004 etb_bytes_avaiable = 0; 989 etb_bytes_avaiable = 0;
1005 } 990 }
1006 991
1007 sn_size = snprintf(rbuf, rsp_size,"%s, %d, server version %d.%d, copyright %d,", 992 sn_size = snprintf(rbuf, rsp_size,"%s, %d", msg, etb_bytes_avaiable);
1008 msg, etb_bytes_avaiable, g_major_version, g_minor_version, g_copyright_year);
1009
1010 993
1011 if (is_wrapped) { 994 if (is_wrapped) {
1012 sn_size += snprintf(rbuf + sn_size, rsp_size - sn_size," wrapped"); 995 sn_size += snprintf(rbuf + sn_size, rsp_size - sn_size,", wrapped");
1013 } 996 }
1014 997
1015#if DEBUG 998#if DEBUG
@@ -1128,6 +1111,35 @@ int remote_memory_read(uint32_t addr, size_t byte_cnt, uint32_t * pbuf)
1128} 1111}
1129 1112
1130/***************************************************************************** 1113/*****************************************************************************
1114 * remote_pipe_write()
1115 *
1116 * This function performs the g_fifo_fd write.
1117 *
1118 *****************************************************************************/
1119void remote_pipe_write(const char * wr_buf_p, size_t wr_bytecnt, char * broken_pipe_msg)
1120{
1121 LOGFUNC();
1122
1123 while ( wr_bytecnt > 0) {
1124 size_t rc = write(g_fifo_fd, wr_buf_p, wr_bytecnt);
1125
1126 if ((rc == -1) && (errno == EPIPE)) {
1127 fprintf(g_stdout,"%s:warning - pipe reading end closed when sending %s.\n"
1128 "%s: This can be caused by issuing a client operation before\n"
1129 "%s: starting the task that opens the pipe's reading end OR\n"
1130 "%s: early termination of the task that opens the pipe's reading end.\n",
1131 g_whoami, broken_pipe_msg, g_whoami, g_whoami, g_whoami);
1132 break;
1133 }
1134 if ((rc == -1) && (errno == EINTR)) {
1135 continue;
1136 }
1137 wr_buf_p += rc;
1138 wr_bytecnt -= rc;
1139 }
1140}
1141
1142/*****************************************************************************
1131 * Private Functions 1143 * Private Functions
1132 *****************************************************************************/ 1144 *****************************************************************************/
1133 1145
diff --git a/server/remote_commands.h b/server/remote_commands.h
index 1d29d42..aefc763 100644
--- a/server/remote_commands.h
+++ b/server/remote_commands.h
@@ -65,6 +65,7 @@ void debug_command_handler(int argc, char *argv[], char * rbuf, size_t rsp_size)
65void get_set_value(set_element_t element, unsigned int *value, bool *is_valid); 65void get_set_value(set_element_t element, unsigned int *value, bool *is_valid);
66int remote_memory_write(uint32_t addr, size_t byte_cnt, uint32_t * pbuf); 66int remote_memory_write(uint32_t addr, size_t byte_cnt, uint32_t * pbuf);
67int remote_memory_read(uint32_t addr, size_t byte_cnt, uint32_t * pbuf); 67int remote_memory_read(uint32_t addr, size_t byte_cnt, uint32_t * pbuf);
68void remote_pipe_write(const char * wr_buf_p, size_t wr_bytecnt, char * broken_pipe_msg);
68 69
69void start_recording(); 70void start_recording();
70void stop_recording(); 71void stop_recording();
diff --git a/server/signal_handler.c b/server/signal_handler.c
index 728ae36..50e64ac 100644
--- a/server/signal_handler.c
+++ b/server/signal_handler.c
@@ -41,6 +41,7 @@
41#include <string.h> 41#include <string.h>
42#include <stdint.h> 42#include <stdint.h>
43#include <signal.h> 43#include <signal.h>
44#include <unistd.h>
44#include "error_handler.h" 45#include "error_handler.h"
45#include "logging.h" 46#include "logging.h"
46#include "ctoolsprof.h" 47#include "ctoolsprof.h"
diff --git a/server/socket.c b/server/socket.c
index 3f0a707..e34a922 100644
--- a/server/socket.c
+++ b/server/socket.c
@@ -119,7 +119,7 @@ void socket_open()
119int socket_server_create(int port) 119int socket_server_create(int port)
120{ 120{
121 LOGFUNC(); 121 LOGFUNC();
122 LOGMSG2("%s:Create socket for port %d", __func__, port); 122 LOGMSG1("%s:create socket for port %d", __func__, port);
123 123
124 int socket_fd, client_socket_fd; 124 int socket_fd, client_socket_fd;
125 struct sockaddr_in server, client; 125 struct sockaddr_in server, client;
@@ -140,7 +140,7 @@ int socket_server_create(int port)
140 err_handler(ERR_TYPE_SYSTEM, ERR_SOCKET_OPTION); 140 err_handler(ERR_TYPE_SYSTEM, ERR_SOCKET_OPTION);
141 } 141 }
142 142
143 LOGMSG2("%s:socket file descriptor opened for AF_INET & SOCK_STERAM", __func__); 143 LOGMSG1("%s:socket file descriptor opened for AF_INET & SOCK_STERAM", __func__);
144 144
145 memset(&server,0,sizeof(struct sockaddr_in)); 145 memset(&server,0,sizeof(struct sockaddr_in));
146 server.sin_family = AF_INET; 146 server.sin_family = AF_INET;
@@ -163,7 +163,7 @@ int socket_server_create(int port)
163 client_socket_fd = accept(socket_fd, (struct sockaddr *)&client, 163 client_socket_fd = accept(socket_fd, (struct sockaddr *)&client,
164 &client_size); 164 &client_size);
165 if(-1 == client_socket_fd) { 165 if(-1 == client_socket_fd) {
166 LOGMSG2("%s:client accept error is %d", __func__, client_socket_fd); 166 LOGMSG1("%s:client accept error is %d", __func__, client_socket_fd);
167 err_handler(ERR_TYPE_SYSTEM, ERR_SOCKET_ACCEPT); 167 err_handler(ERR_TYPE_SYSTEM, ERR_SOCKET_ACCEPT);
168 } 168 }
169 169