trace-cmd: Add debug option to tell msg protocol not to timeout
In order to debug the message protocol, we do not want to time out, as we
need to run gdb on the client and server, and timeouts kill the connections
we want to debug.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
diff --git a/trace-cmd.h b/trace-cmd.h
index 451771a..cef2458 100644
--- a/trace-cmd.h
+++ b/trace-cmd.h
@@ -285,6 +285,9 @@
int tracecmd_msg_send_port_array(int fd, int total_cpus, int *ports);
int tracecmd_msg_collect_metadata(int ifd, int ofd);
+/* msg debugging */
+void tracecmd_msg_set_debug(int debug);
+
/* --- Plugin handling --- */
extern struct pevent_plugin_option trace_ftrace_options[];
diff --git a/trace-listen.c b/trace-listen.c
index 16375f8..420b68d 100644
--- a/trace-listen.c
+++ b/trace-listen.c
@@ -936,6 +936,9 @@
signal_setup(SIGINT, finish);
signal_setup(SIGTERM, finish);
+ if (debug)
+ tracecmd_msg_set_debug(debug);
+
do_listen(port);
return;
diff --git a/trace-msg.c b/trace-msg.c
index cacdc1c..98c330a 100644
--- a/trace-msg.c
+++ b/trace-msg.c
@@ -411,6 +411,15 @@
}
#define MSG_WAIT_MSEC 5000
+static int msg_wait_to = MSG_WAIT_MSEC;
+
+void tracecmd_msg_set_debug(int debug)
+{
+ if (debug)
+ msg_wait_to = -1;
+ else
+ msg_wait_to = MSG_WAIT_MSEC;
+}
/*
* A return value of 0 indicates time-out
@@ -422,7 +431,7 @@
pfd.fd = fd;
pfd.events = POLLIN;
- ret = poll(&pfd, 1, MSG_WAIT_MSEC);
+ ret = poll(&pfd, 1, msg_wait_to);
if (ret < 0)
return -errno;
else if (ret == 0)
diff --git a/trace-record.c b/trace-record.c
index 4706f90..e483994 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -4103,6 +4103,7 @@
}
enum {
+ OPT_debug = 247,
OPT_tsoffset = 249,
OPT_bycomm = 250,
OPT_stderr = 251,
@@ -4142,6 +4143,7 @@
int topt = 0;
int do_child = 0;
int data_flags = 0;
+ int debug = 0;
int c;
@@ -4309,6 +4311,7 @@
{"stderr", no_argument, NULL, OPT_stderr},
{"by-comm", no_argument, NULL, OPT_bycomm},
{"ts-offset", required_argument, NULL, OPT_tsoffset},
+ {"debug", no_argument, NULL, OPT_debug},
{"help", no_argument, NULL, '?'},
{NULL, 0, NULL, 0}
};
@@ -4571,6 +4574,9 @@
die("Can not use both --date and --ts-offset");
data_flags |= DATA_FL_OFFSET;
break;
+ case OPT_debug:
+ debug = 1;
+ break;
default:
usage(argv);
}
@@ -4598,6 +4604,10 @@
if (profile && !buffer_instances)
top_instance.profile = 1;
+ /* Let msg protocol know if we are debugging */
+ if (debug)
+ tracecmd_msg_set_debug(debug);
+
/*
* If top_instance doesn't have any plugins or events, then
* remove it from being processed.