Skip to contentSkip to conversation

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

PATCH In review Bijan Tabatabai 2 participants 2 messages May 14, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v4 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.

---
v4 fixes a bug where trace-cmd would stop tracing after the processes in the first instance exited.

---
 tracecmd/include/trace-local.h |  2 +
 tracecmd/trace-record.c        | 91 +++++++++++++++++++++++++++++++++-
 2 files changed, 92 insertions(+), 1 deletion(-)
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 +90 -1

128 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw
Quoted 6 lines · On Thu, 14 May 2020 11:42:44 -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.

Quoted 6 lines

---
v4 fixes a bug where trace-cmd would stop tracing after the processes in the first instance exited.
---

Looks good, but there's one small nit.

tracecmd/trace-record.c static void record_trace(int argc, char **argv, · line 6450

Quoted 12 lines
tracecmd/trace-record.c +7 -1
@@ -6361,7 +6441,16 @@ static void record_trace(int argc, char **argv,
 		}
 		/* sleep till we are woken with Ctrl^C */
 		printf("Hit Ctrl^C to stop recording\n");
-		while (!finished)
+		for_all_instances(instance) {
+			/* If an instance is not tracing individual processes
+			 * or there is an error while waiting for a process to
+			 * exit, fallback to waiting indefinitely.
+			 */
+			if (!instance->nr_process_pids
+			    || trace_wait_for_processes(instance))

My preference is:

			if (!instance->nr_process_pids ||
			    trace_wait_for_processes(instance))

But I can make this change.

Thanks!

-- Steve

Quoted 6 lines
tracecmd/trace-record.c +3 -0
+				wait_indefinitely = true;
+		}
+		while (!finished && wait_indefinitely)
 			trace_or_sleep(type, pwait);
 	}