From 099a2dbde50bb23a0c22098c52c6143f9fb940d2 Mon Sep 17 00:00:00 2001 From: Steven Rostedt Date: Fri, 14 Oct 2011 15:58:19 -0400 Subject: trace-cmd: Do not use threads for extract Currently the trace-cmd extract function uses the forked threads to read the data from the ring buffers. As this is not a live trace and the program does not end till all the buffers are flushed to disk, there is no need to use the threads. Just serially read each buffer into a file and then pull them together normally. This also fixes a bug that was triggered in the kernel where reading the trace_pipe_raw file after EOF will yield the last page again, causing the trace-cmd extract to produce duplicate pages. Signed-off-by: Steven Rostedt --- trace-recorder.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'trace-recorder.c') diff --git a/trace-recorder.c b/trace-recorder.c index e57ef9b..4a01fb9 100644 --- a/trace-recorder.c +++ b/trace-recorder.c @@ -156,10 +156,32 @@ static long splice_data(struct tracecmd_recorder *recorder) return ret; } +long tracecmd_flush_recording(struct tracecmd_recorder *recorder) +{ + char *buf[recorder->page_size]; + long total = 0; + long ret; + + do { + ret = splice_data(recorder); + if (ret < 0) + return ret; + total += ret; + } while (ret); + + /* splice only reads full pages */ + do { + ret = read(recorder->trace_fd, buf, recorder->page_size); + if (ret > 0) + write(recorder->fd, buf, ret); + } while (ret > 0); + + return total; +} + int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep) { struct timespec req; - char *buf[recorder->page_size]; long ret; recorder->stop = 0; @@ -175,21 +197,12 @@ int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long s return ret; } while (!recorder->stop); - /* Flush via splice first */ - do { - ret = splice_data(recorder); - } while (ret > 0); + /* Flush out the rest */ + ret = tracecmd_flush_recording(recorder); if (ret < 0) return ret; - /* splice only reads full pages */ - do { - ret = read(recorder->trace_fd, buf, recorder->page_size); - if (ret > 0) - write(recorder->fd, buf, ret); - } while (ret > 0); - return 0; } -- cgit v1.2.2