From: Bijan Tabatabai <bijan311@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org, Bijan Tabatabai <bijan311@yahoo.com>
Subject: [PATCH RESEND] trace-cmd: Stop recording when processes traced with -P exit
Date: Sat, 18 Apr 2020 18:30:22 -0500 [thread overview]
Message-ID: <20200418233022.31033-1-bijan311@gmail.com> (raw)
From: Bijan Tabatabai <bijan311@yahoo.com>
When the -F flag is used in trace-cmd record, trace-cmd stops recording
when the executable it is tracing terminates.
This patch makes the -P flag act similarly.
Signed-off-by: Bijan Tabatabai <bijan311@yahoo.com>
---
Resending this because the mailing server did not like my original
email address.
tracecmd/trace-record.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index d89b32d..b5cd4c4 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -121,8 +121,10 @@ struct filter_pids {
};
static struct filter_pids *filter_pids;
+static struct filter_pids *process_pids;
static int nr_filter_pids;
static int len_filter_pids;
+static int nr_process_pids = 0;
static int have_set_event_pid;
static int have_event_fork;
@@ -5799,7 +5801,9 @@ static void parse_record_options(int argc,
while (pid) {
add_filter_pid(atoi(pid), 0);
pid = strtok_r(NULL, ",", &sav);
+ nr_process_pids++;
}
+ process_pids = filter_pids;
free(pids);
break;
case 'c':
@@ -6273,10 +6277,19 @@ static void record_trace(int argc, char **argv,
ptrace_attach(pid->pid);
}
}
- /* sleep till we are woken with Ctrl^C */
- printf("Hit Ctrl^C to stop recording\n");
- while (!finished)
- trace_or_sleep(type);
+ if (nr_process_pids) {
+ for (pid = process_pids; pid && nr_process_pids; pid = pid->next) {
+ if (!pid->exclude)
+ /* Wait for the process to end */
+ while(!kill(pid->pid, 0));
+ nr_process_pids--;
+ }
+ } else {
+ /* sleep till we are woken with Ctrl^C */
+ printf("Hit Ctrl^C to stop recording\n");
+ while (!finished)
+ trace_or_sleep(type);
+ }
}
tell_guests_to_stop();
--
2.17.1
reply other threads:[~2020-04-18 23:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20200418233022.31033-1-bijan311@gmail.com \
--to=bijan311@gmail.com \
--cc=bijan311@yahoo.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.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).