linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH] trace-cmd: Have trace-cmd start wait for command unless --fork is specified
Date: Mon, 8 Jun 2020 16:39:58 -0400	[thread overview]
Message-ID: <20200608163958.3dd8761f@oasis.local.home> (raw)
In-Reply-To: <20200608153540.06b08942@oasis.local.home>

[ I just realized I already pushed your patch. Here's an update to what
  I would like. ]

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

Instead of forking a command specified on the command line and returning
right away, have it wait for the process to finish before returning. Unless
"--fork" is specified as well.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/trace-cmd-start.1.txt |  7 +++++++
 tracecmd/trace-record.c             | 18 +++++++++++++-----
 tracecmd/trace-usage.c              |  2 ++
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/Documentation/trace-cmd-start.1.txt b/Documentation/trace-cmd-start.1.txt
index 63d2034c..07f2ed3a 100644
--- a/Documentation/trace-cmd-start.1.txt
+++ b/Documentation/trace-cmd-start.1.txt
@@ -23,6 +23,13 @@ OPTIONS
 The options are the same as 'trace-cmd-record(1)', except that it does not
 take options specific to recording (*-s*, *-o*, *-N*, and *-t*).
 
+*--fork* ::
+   This option is only available for trace-cmd start. It tells trace-cmd
+   to not wait for the process to finish before returning.
+   With this option, trace-cmd start will return right after it forks
+   the process on the command line. This option only has an effect if
+   trace-cmd start also executes a command.
+
 SEE ALSO
 --------
 trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-stop(1),
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 4d2039a1..143b736e 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -86,6 +86,8 @@ static char *host;
 
 static bool quiet;
 
+static bool fork_process;
+
 /* Max size to let a per cpu file get */
 static int max_kb;
 
@@ -1604,7 +1606,7 @@ static void run_cmd(enum trace_type type, const char *user, int argc, char **arg
 		/* child */
 		update_task_filter();
 		tracecmd_enable_tracing();
-		if (type != TRACE_TYPE_START)
+		if (!fork_process)
 			enable_ptrace();
 		/*
 		 * If we are using stderr for stdout, switch
@@ -1626,13 +1628,15 @@ static void run_cmd(enum trace_type type, const char *user, int argc, char **arg
 			die("Failed to exec %s", argv[0]);
 		}
 	}
-	if (type & TRACE_TYPE_START)
+	if (fork_process)
 		exit(0);
 	if (do_ptrace) {
 		ptrace_attach(NULL, pid);
 		ptrace_wait(type);
 	} else
 		trace_waitpid(type, pid, &status, 0);
+	if (type & TRACE_TYPE_START)
+		exit(0);
 }
 
 static void
@@ -5535,6 +5539,7 @@ void init_top_instance(void)
 }
 
 enum {
+	OPT_fork		= 241,
 	OPT_tsyncinterval	= 242,
 	OPT_user		= 243,
 	OPT_procmap		= 244,
@@ -5851,6 +5856,7 @@ static void parse_record_options(int argc,
 			{"user", required_argument, NULL, OPT_user},
 			{"module", required_argument, NULL, OPT_module},
 			{"tsync-interval", required_argument, NULL, OPT_tsyncinterval},
+			{"fork", no_argument, NULL, OPT_fork},
 			{NULL, 0, NULL, 0}
 		};
 
@@ -6204,6 +6210,11 @@ static void parse_record_options(int argc,
 			top_instance.tsync.loop_interval = atoi(optarg);
 			guest_sync_set = true;
 			break;
+		case OPT_fork:
+			if (!IS_START(ctx))
+				die("--fork option used for 'start' command only");
+			fork_process = true;
+			break;
 		case OPT_quiet:
 		case 'q':
 			quiet = true;
@@ -6266,9 +6277,6 @@ static void parse_record_options(int argc,
 		}
 	}
 
-	if (do_ptrace && IS_START(ctx))
-		die("ptrace not supported with command start");
-
 	for_all_instances(instance) {
 		if (instance->get_procmap && !instance->nr_filter_pids) {
 			warning("--proc-map is ignored for instance %s, "
diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c
index 58bca9e4..1e832be8 100644
--- a/tracecmd/trace-usage.c
+++ b/tracecmd/trace-usage.c
@@ -71,6 +71,8 @@ static struct usage_help usage_help[] = {
 		" %s start [-e event][-p plugin][-d][-O option ][-P pid]\n"
 		"          Uses same options as record.\n"
 		"          It only enables the tracing and exits\n"
+		"\n"
+		"        --fork: If a command is specified, then return right after it forks\n"
 	},
 	{
 		"extract",
-- 
2.25.4


  reply	other threads:[~2020-06-08 20:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03 12:15 [PATCH v3 0/5] New trace-cmd "set" command and changes in "start" Tzvetomir Stoyanov (VMware)
2020-06-03 12:15 ` [PATCH v3 1/5] trace-cmd: Enable "trace-cmd start" to run a command Tzvetomir Stoyanov (VMware)
2020-06-08 19:35   ` Steven Rostedt
2020-06-08 20:39     ` Steven Rostedt [this message]
2020-06-03 12:15 ` [PATCH v3 2/5] trace-cmd: Add new subcommand "set" Tzvetomir Stoyanov (VMware)
2020-06-03 12:15 ` [PATCH v3 3/5] trace-cmd: Man page for "set" subcommand Tzvetomir Stoyanov (VMware)
2020-06-04 15:50   ` Steven Rostedt
2020-06-03 12:15 ` [PATCH v3 4/5] trace-cmd: Extend option "-v" to delete an ftrace instance Tzvetomir Stoyanov (VMware)
2020-06-03 12:15 ` [PATCH v3 5/5] trace-cmd: Add description of "-G" option Tzvetomir Stoyanov (VMware)
2020-06-04 15:51   ` Steven Rostedt
2020-06-08 21:42     ` 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=20200608163958.3dd8761f@oasis.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=tz.stoyanov@gmail.com \
    /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).