aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (Google) <rostedt@goodmis.org>2022-05-13 22:47:52 -0400
committerSteven Rostedt (Google) <rostedt@goodmis.org>2022-05-21 20:01:09 -0400
commit4ec34dd1cd5037c9253803f3d7ca9a2219352ffe (patch)
tree00734d1d5131e8901089cba621506cfaf129e859
parentd45104e444487e862801171d7eab9bf25e1648a1 (diff)
downloadtrace-cmd-4ec34dd1cd5037c9253803f3d7ca9a2219352ffe.tar.gz
trace-cmd agent proxy: Allow agent to send more meta data after trace
The options of the agent proxy trace file will need to include timings and guest data that is added after the trace has completed. Do not close the network handle for the meta data before the trace. Keep it open for the proxy agent and finish writing the options at the end of the trace. Link: https://lore.kernel.org/linux-trace-devel/20220514024756.1319681-23-rostedt@goodmis.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r--tracecmd/include/trace-local.h5
-rw-r--r--tracecmd/trace-record.c39
2 files changed, 39 insertions, 5 deletions
diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h
index 92d005c7..295be5dd 100644
--- a/tracecmd/include/trace-local.h
+++ b/tracecmd/include/trace-local.h
@@ -280,6 +280,8 @@ struct buffer_instance {
int buffer_size;
int cpu_count;
+ int proxy_fd;
+
int argc;
char **argv;
@@ -308,6 +310,9 @@ extern struct buffer_instance *first_instance;
#define is_guest(instance) ((instance)->flags & BUFFER_FL_GUEST)
#define is_proxy(instance) ((instance)->flags & BUFFER_FL_PROXY)
#define is_network(instance) ((instance)->flags & BUFFER_FL_NETWORK)
+#define is_proxy_server(instance) \
+ ((instance)->msg_handle && \
+ (instance)->msg_handle->flags & TRACECMD_MSG_FL_PROXY)
#define START_PORT_SEARCH 1500
#define MAX_PORT_SEARCH 6000
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 266ba421..2e9ef18c 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -720,8 +720,15 @@ static void tell_guests_to_stop(struct common_record_context *ctx)
/* Send close message to guests */
for_all_instances(instance) {
- if (is_guest(instance))
+ if (is_guest(instance)) {
tracecmd_msg_send_close_msg(instance->msg_handle);
+ if (is_proxy(instance) && instance->proxy_fd >= 0) {
+ /* The proxy will send more data now */
+ if (tracecmd_msg_read_data(instance->msg_handle, instance->proxy_fd))
+ warning("Failed receiving finishing metadata");
+ close(instance->proxy_fd);
+ }
+ }
}
for_all_instances(instance) {
@@ -3973,7 +3980,15 @@ static void setup_guest(struct buffer_instance *instance)
/* Start reading tracing metadata */
if (tracecmd_msg_read_data(msg_handle, fd))
die("Failed receiving metadata");
- close(fd);
+
+ /*
+ * If connected to a proxy, then it still needs to send
+ * the host / guest timings from its POV.
+ */
+ if (is_proxy(instance))
+ instance->proxy_fd = fd;
+ else
+ close(fd);
}
static void setup_agent(struct buffer_instance *instance,
@@ -3986,9 +4001,14 @@ static void setup_agent(struct buffer_instance *instance,
tracecmd_write_cmdlines(network_handle);
tracecmd_write_cpus(network_handle, instance->cpu_count);
tracecmd_write_buffer_info(network_handle);
- tracecmd_write_options(network_handle);
- tracecmd_write_meta_strings(network_handle);
- tracecmd_msg_finish_sending_data(instance->msg_handle);
+ if (instance->msg_handle->flags & TRACECMD_MSG_FL_PROXY) {
+ tracecmd_prepare_options(network_handle, 0, SEEK_CUR);
+ tracecmd_msg_flush_data(instance->msg_handle);
+ } else {
+ tracecmd_write_options(network_handle);
+ tracecmd_write_meta_strings(network_handle);
+ tracecmd_msg_finish_sending_data(instance->msg_handle);
+ }
instance->network_handle = network_handle;
}
@@ -4015,6 +4035,9 @@ static void start_threads(enum trace_type type, struct common_record_context *ct
int *brass = NULL;
int x, pid;
+ /* May be set by setup_guest() but all others is -1 */
+ instance->proxy_fd = -1;
+
if (is_agent(instance)) {
setup_agent(instance, ctx);
} else if (is_guest(instance)) {
@@ -6891,6 +6914,12 @@ static void record_trace(int argc, char **argv,
if (!latency)
wait_threads();
+ if (is_proxy_server(ctx->instance) && ctx->instance->network_handle) {
+ tracecmd_write_options(ctx->instance->network_handle);
+ tracecmd_write_meta_strings(ctx->instance->network_handle);
+ tracecmd_msg_finish_sending_data(ctx->instance->msg_handle);
+ }
+
if (IS_RECORD(ctx)) {
record_data(ctx);
delete_thread_data();