linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Subject: [PATCH 35/38] trace-cmd: Have msg_handle part of the buffer instance
Date: Wed, 03 Jan 2018 12:52:37 -0500	[thread overview]
Message-ID: <20180103175339.924196033@goodmis.org> (raw)
In-Reply-To: 20180103175202.044283643@goodmis.org

[-- Attachment #1: 0035-trace-cmd-Have-msg_handle-part-of-the-buffer-instanc.patch --]
[-- Type: text/plain, Size: 6126 bytes --]

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

To allow for recording of the host as well as for the network, we need to
have the msg_handle associated to the buffer instance and not global. This
also will allow for recording buffer instances to network and host, as well
as sending data to multiple hosts.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 trace-local.h  |  2 ++
 trace-record.c | 56 +++++++++++++++++++++++++++++++++-----------------------
 2 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/trace-local.h b/trace-local.h
index 0d85fda416e2..0665ec3c11c5 100644
--- a/trace-local.h
+++ b/trace-local.h
@@ -189,6 +189,8 @@ struct buffer_instance {
 
 	struct tracecmd_input	*handle;
 
+	struct tracecmd_msg_handle *msg_handle;
+
 	int			tracing_on_init_val;
 	int			tracing_on_fd;
 	int			keep;
diff --git a/trace-record.c b/trace-record.c
index 9b389e7d9134..5f7231b0fda2 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -2912,21 +2912,14 @@ static void finish_network(struct tracecmd_msg_handle *msg_handle)
 	free(host);
 }
 
-static struct tracecmd_msg_handle *start_threads(enum trace_type type, int global)
+void start_threads(enum trace_type type, int global)
 {
-	struct tracecmd_msg_handle *msg_handle = NULL;
 	struct buffer_instance *instance;
 	int *brass = NULL;
 	int total_cpu_count = 0;
 	int i = 0;
 	int ret;
 
-	if (host) {
-		msg_handle = setup_connection();
-		if (!msg_handle)
-			die("Failed to make connection");
-	}
-
 	for_all_instances(instance)
 		total_cpu_count += instance->cpu_count;
 
@@ -2939,6 +2932,13 @@ static struct tracecmd_msg_handle *start_threads(enum trace_type type, int globa
 
 	for_all_instances(instance) {
 		int x, pid;
+
+		if (host) {
+			instance->msg_handle = setup_connection();
+			if (!instance->msg_handle)
+				die("Failed to make connection");
+		}
+
 		for (x = 0; x < instance->cpu_count; x++) {
 			if (type & TRACE_TYPE_STREAM) {
 				brass = pids[i].brass;
@@ -2966,8 +2966,6 @@ static struct tracecmd_msg_handle *start_threads(enum trace_type type, int globa
 		}
 	}
 	recorder_threads = i;
-
-	return msg_handle;
 }
 
 static void touch_file(const char *file)
@@ -3090,21 +3088,26 @@ enum {
 	DATA_FL_OFFSET		= 2,
 };
 
-static void record_data(struct tracecmd_msg_handle *msg_handle,
-			char *date2ts, int flags)
+static void record_data(char *date2ts, int flags)
 {
 	struct tracecmd_option **buffer_options;
 	struct tracecmd_output *handle;
 	struct buffer_instance *instance;
+	bool local = false;
 	int max_cpu_count = local_cpu_count;
 	char **temp_files;
 	int i;
 
-	if (msg_handle) {
-		finish_network(msg_handle);
-		return;
+	for_all_instances(instance) {
+		if (instance->msg_handle)
+			finish_network(instance->msg_handle);
+		else
+			local = true;
 	}
 
+	if (!local)
+		return;
+
 	if (latency)
 		handle = tracecmd_create_file_latency(output_file, local_cpu_count);
 	else {
@@ -3112,9 +3115,12 @@ static void record_data(struct tracecmd_msg_handle *msg_handle,
 			return;
 
 		/* Allocate enough temp files to handle each instance */
-		for_all_instances(instance)
+		for_all_instances(instance) {
+			if (instance->msg_handle)
+				continue;
 			if (instance->cpu_count > max_cpu_count)
 				max_cpu_count = instance->cpu_count;
+		}
 
 		temp_files = malloc(sizeof(*temp_files) * max_cpu_count);
 		if (!temp_files)
@@ -3128,7 +3134,7 @@ static void record_data(struct tracecmd_msg_handle *msg_handle,
 		 * If top_instance was not used, we still need to create
 		 * empty trace.dat files for it.
 		 */
-		if (no_top_instance()) {
+		if (no_top_instance() || top_instance.msg_handle) {
 			for (i = 0; i < local_cpu_count; i++)
 				touch_file(temp_files[i]);
 		}
@@ -3151,7 +3157,7 @@ static void record_data(struct tracecmd_msg_handle *msg_handle,
 		}
 
 		/* Only record the top instance under TRACECMD_OPTION_CPUSTAT*/
-		if (!no_top_instance()) {
+		if (!no_top_instance() && !top_instance.msg_handle) {
 			struct trace_seq *s = top_instance.s_save;
 
 			for (i = 0; i < local_cpu_count; i++)
@@ -3175,6 +3181,9 @@ static void record_data(struct tracecmd_msg_handle *msg_handle,
 				int cpus = instance->cpu_count != local_cpu_count ?
 					instance->cpu_count : 0;
 
+				if (instance->msg_handle)
+					continue;
+
 				buffer_options[i++] = tracecmd_add_buffer_option(handle,
 										 instance->name,
 										 cpus);
@@ -3182,7 +3191,7 @@ static void record_data(struct tracecmd_msg_handle *msg_handle,
 			}
 		}
 
-		if (!no_top_instance())
+		if (!no_top_instance() && !top_instance.msg_handle)
 			print_stat(&top_instance);
 
 		tracecmd_append_cpu_data(handle, local_cpu_count, temp_files);
@@ -3193,6 +3202,8 @@ static void record_data(struct tracecmd_msg_handle *msg_handle,
 		if (buffers) {
 			i = 0;
 			for_each_instance(instance) {
+				if (instance->msg_handle)
+					continue;
 				print_stat(instance);
 				append_buffer(handle, buffer_options[i++], instance, temp_files);
 			}
@@ -4895,7 +4906,6 @@ static void record_trace(int argc, char **argv,
 			 struct common_record_context *ctx)
 {
 	enum trace_type type = get_trace_cmd_type(ctx->curr_cmd);
-	struct tracecmd_msg_handle *msg_handle = NULL;
 	struct buffer_instance *instance;
 
 	/*
@@ -4968,7 +4978,7 @@ static void record_trace(int argc, char **argv,
 	if (type & (TRACE_TYPE_RECORD | TRACE_TYPE_STREAM)) {
 		signal(SIGINT, finish);
 		if (!latency)
-			msg_handle = start_threads(type, ctx->global);
+			start_threads(type, ctx->global);
 	} else {
 		update_task_filter();
 		tracecmd_enable_tracing();
@@ -4999,7 +5009,7 @@ static void record_trace(int argc, char **argv,
 		tracecmd_disable_all_tracing(0);
 
 	if (IS_RECORD(ctx)) {
-		record_data(msg_handle, ctx->date2ts, ctx->data_flags);
+		record_data(ctx->date2ts, ctx->data_flags);
 		delete_thread_data();
 	} else
 		print_stats();
@@ -5079,7 +5089,7 @@ void trace_extract(int argc, char **argv)
 		ctx.date2ts = get_date_to_ts();
 	}
 
-	record_data(NULL, ctx.date2ts, ctx.data_flags);
+	record_data(ctx.date2ts, ctx.data_flags);
 	delete_thread_data();
 	destroy_stats();
 	finalize_record_trace(&ctx);
-- 
2.13.2

  parent reply	other threads:[~2018-01-03 17:53 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-03 17:52 [PATCH 00/38] trace-cmd: Simplify the msg handling Steven Rostedt
2018-01-03 17:52 ` [PATCH 01/38] trace-cmd recorder: Check if pipe_size was modified by fcntl(F_GETPIPE_SZ) Steven Rostedt
2018-01-03 17:52 ` [PATCH 02/38] pevent: Simplify pointer print logic and fix %pF Steven Rostedt
2018-01-03 17:52 ` [PATCH 03/38] pevent: Handle new pointer processing of bprint strings Steven Rostedt
2018-01-03 17:52 ` [PATCH 04/38] trace-cmd record: Fix clearing out the ctx->instance when used in for_all_instances() Steven Rostedt
2018-01-03 17:52 ` [PATCH 05/38] trace-cmd: Remove the creating of msg out of tracecmd_msg_send() Steven Rostedt
2018-01-03 17:52 ` [PATCH 06/38] trace-cmd: Move tracecmd_msg_send_and_wait_for_msg() into its only user Steven Rostedt
2018-01-03 17:52 ` [PATCH 07/38] trace-cmd: Turn tracecmd_msg data into an anonymous union Steven Rostedt
2018-01-03 17:52 ` [PATCH 08/38] trace-cmd: Remove unused structure tracecmd_msg_error Steven Rostedt
2018-01-03 17:52 ` [PATCH 09/38] trace-cmd: Move size and cmd in tracecmd_msg into its own header struct Steven Rostedt
2018-01-03 17:52 ` [PATCH 10/38] trace-cmd: Move the tracecmd_msg pointers into their own union Steven Rostedt
2018-01-03 17:52 ` [PATCH 11/38] trace-cmd: Just use the buf field for sending pointers Steven Rostedt
2018-01-03 17:52 ` [PATCH 12/38] trace-cmd: Use an array to map msg types and min sizes Steven Rostedt
2018-01-03 17:52 ` [PATCH 13/38] trace-cmd: Merge msg_do_write_check() into msg_write() Steven Rostedt
2018-01-03 17:52 ` [PATCH 14/38] trace-cmd: Simplify msg_free() by using min sizes Steven Rostedt
2018-01-03 17:52 ` [PATCH 15/38] trace-cmd: Add tracecmd_msg_init() helper function Steven Rostedt
2018-01-03 17:52 ` [PATCH 16/38] trace-cmd: Remove mulitplexer tracecmd_msg_create() Steven Rostedt
2018-01-03 17:52 ` [PATCH 17/38] trace-cmd: Simplify msg_read_extra() Steven Rostedt
2018-01-03 17:52 ` [PATCH 18/38] trace-cmd: Have msg_free() zero out msg contents Steven Rostedt
2018-01-03 17:52 ` [PATCH 19/38] trace-cmd: Verify RINIT was received after TINIT msg sent Steven Rostedt
2018-01-03 17:52 ` [PATCH 20/38] trace-cmd: Make send_metadata a flag in the output handle Steven Rostedt
2018-01-03 17:52 ` [PATCH 21/38] trace-cmd: Pass cpu count and port array to make_rinit() Steven Rostedt
2018-01-03 17:52 ` [PATCH 22/38] trace-cmd: Pass cpu_count instead of having it as a global Steven Rostedt
2018-01-03 17:52 ` [PATCH 23/38] trace-cmd: Pass in client_ports instead of using a global variable Steven Rostedt
2018-01-03 17:52 ` [PATCH 24/38] trace-cmd msg: Add debug prints of messages sent and received Steven Rostedt
2018-01-03 17:52 ` [PATCH 25/38] trace-cmd msg: Move the saved closing fd to the caller Steven Rostedt
2018-01-03 17:52 ` [PATCH 26/38] trace-cmd listen: Add better output on error of connections Steven Rostedt
2018-01-03 17:52 ` [PATCH 27/38] trace-cmd msg: Create a msg_handle to pass around for saved state Steven Rostedt
2018-01-03 17:52 ` [PATCH 28/38] trace-cmd msg: Add server structure of msg_handler Steven Rostedt
2018-01-03 20:31   ` [PATCH 28/38 v2] " Steven Rostedt
2018-01-03 17:52 ` [PATCH 29/38] trace-cmd: Remove global use_tcp variable Steven Rostedt
2018-01-03 17:52 ` [PATCH 30/38] trace-cmd: Move protocol version into msg_handler Steven Rostedt
2018-01-03 17:52 ` [PATCH 31/38] tracecmd: Clean up handling of cpu_count Steven Rostedt
2018-01-03 17:52 ` [PATCH 32/38] tracecmd listen: Have pagesize passed as return not parameter Steven Rostedt
2018-01-03 17:52 ` [PATCH 33/38] trace-cmd: Have cpu_count reside in instances and not be global Steven Rostedt
2018-01-03 17:52 ` [PATCH 34/38] trace-cmd: Add option CPUCOUNT to buffer instance options Steven Rostedt
2018-01-03 17:52 ` Steven Rostedt [this message]
2018-01-03 17:52 ` [PATCH 36/38] trace-cmd record: Allow instances to be recorded over the network Steven Rostedt
2018-01-03 17:52 ` [PATCH 37/38] trace-cmd: Have keep and profile be flags of buffer instance Steven Rostedt
2018-01-03 17:52 ` [PATCH 38/38] trace-cmd: Add network handle into " Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180103175339.924196033@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).