Skip to contentSkip to conversation

trace-cmd: Stop recording when processes traced with -P exit

PATCH Superseded Bijan Tabatabai 2 participants 4 messages May 13, 2020 – May 14, 2020

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 trace-cmd: Stop recording when processes traced with -P exit

From: Bijan Tabatabai <[email protected]>

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.

---
This patch has changed to use the pidfd interface to determine if a process has ended.
It also has changed to work with the patch "trace-cmd: Handle filtered PIDs per ftarce instance" (5502bcef0f962cda).

---
 tracecmd/include/trace-local.h |  2 +
 tracecmd/trace-record.c        | 84 ++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+)
tracecmd/include/trace-local.h +2 -0
index 4c6a63d..5d58550 100644
@@ -215,9 +215,11 @@ struct buffer_instance {
 
 	struct opt_list		*options;
 	struct filter_pids	*filter_pids;
+	struct filter_pids	*process_pids;
 	char			*common_pid_filter;
 	int			nr_filter_pids;
 	int			len_filter_pids;
+	int			nr_process_pids;
 	bool			ptrace_child;
 
 	int			have_set_event_pid;
tracecmd/trace-record.c +84 -0

115 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw
Quoted 12 lines · On Wed, 13 May 2020 12:05:29 -0500 Bijan Tabatabai <[email protected]> wrote:

From: Bijan Tabatabai <[email protected]>

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.

---
This patch has changed to use the pidfd interface to determine if a process has ended.
It also has changed to work with the patch "trace-cmd: Handle filtered PIDs per ftarce instance" (5502bcef0f962cda).

Quoted 5 lines
---
 tracecmd/include/trace-local.h |  2 +
 tracecmd/trace-record.c        | 84 ++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+)

Nice!

Although I just tried it out and noticed that if I run the following command:

 # sleep 20& sleep 50&
[1] 2216
[2] 2218
 # trace-cmd record -e sched -P 2216 -B foo -e all -P 2218

It will exit out after the first sleep (20 second) and before the second is done.

It appears to exit as soon as the first process is finished. We should want to wait till the last one is finished.

-- Steve

#2 lore raw

I just tried that and discovered an interesting problem. After the first sleep ended, my computer completely locked up, and after a few minutes I decided to reset my computer.
Then after rebooting, I checked out the master branch, recompiled, and tried running the same set of commands again.
This time, my computer locked up shortly after I pressed Ctrl+C after both sleeps exited.
I am running Ubuntu 20.04 with Ubuntu's version of the 5.4 kernel.

Is this a bug that has been reported before? If not, what is the process for "officially" reporting it?

Thank,
Bijan

Quoted 39 lines · Steven Rostedt
Quoted 12 lines · On Wed, 13 May 2020 12:05:29 -0500 Bijan Tabatabai <[email protected]> wrote:

From: Bijan Tabatabai <[email protected]>

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.

---
This patch has changed to use the pidfd interface to determine if a process has ended.
It also has changed to work with the patch "trace-cmd: Handle filtered PIDs per ftarce instance" (5502bcef0f962cda).

Quoted 5 lines
---
 tracecmd/include/trace-local.h |  2 +
 tracecmd/trace-record.c        | 84 ++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+)

Nice!

Although I just tried it out and noticed that if I run the following command:

 # sleep 20& sleep 50&
[1] 2216
[2] 2218
 # trace-cmd record -e sched -P 2216 -B foo -e all -P 2218

It will exit out after the first sleep (20 second) and before the second is done.

It appears to exit as soon as the first process is finished. We should want to wait till the last one is finished.

-- Steve

#3 lore raw
Quoted 9 lines · On Wed, 13 May 2020 20:25:46 -0500 Bijan Tabatabai <[email protected]> wrote:

I just tried that and discovered an interesting problem. After the first sleep ended, my computer completely locked up, and after a few minutes I decided to reset my computer.
Then after rebooting, I checked out the master branch, recompiled, and tried running the same set of commands again.
This time, my computer locked up shortly after I pressed Ctrl+C after both sleeps exited.
I am running Ubuntu 20.04 with Ubuntu's version of the 5.4 kernel.

Quoted 3 lines

Is this a bug that has been reported before? If not, what is the process for "officially" reporting it?

It's a kernel bug, and we just hit it a couple of weeks ago. The fix is here:

https://lore.kernel.org/r/[email protected]

It has been already added to Linus's tree and is filtering into the stable branches (should soon be in your Ubuntu kernel).

The discussion around it is here (with the first attempted fix).

https://lore.kernel.org/r/[email protected]

The above is really just a work around, and the real fix is being proposed and discussed here.

https://lore.kernel.org/r/[email protected]

-- Steve