aboutsummaryrefslogtreecommitdiffstats
path: root/trace-recorder.c
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2011-10-14 15:58:19 -0400
committerSteven Rostedt <rostedt@goodmis.org>2011-10-14 15:58:19 -0400
commit099a2dbde50bb23a0c22098c52c6143f9fb940d2 (patch)
tree51e63b0a29944171f5be4168057d9782922dfb7a /trace-recorder.c
parent954cbf8b759dc8b7b372132e872ac8d695ce8f47 (diff)
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 <rostedt@goodmis.org>
Diffstat (limited to 'trace-recorder.c')
-rw-r--r--trace-recorder.c37
1 files changed, 25 insertions, 12 deletions
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)
156 return ret; 156 return ret;
157} 157}
158 158
159long tracecmd_flush_recording(struct tracecmd_recorder *recorder)
160{
161 char *buf[recorder->page_size];
162 long total = 0;
163 long ret;
164
165 do {
166 ret = splice_data(recorder);
167 if (ret < 0)
168 return ret;
169 total += ret;
170 } while (ret);
171
172 /* splice only reads full pages */
173 do {
174 ret = read(recorder->trace_fd, buf, recorder->page_size);
175 if (ret > 0)
176 write(recorder->fd, buf, ret);
177 } while (ret > 0);
178
179 return total;
180}
181
159int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep) 182int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep)
160{ 183{
161 struct timespec req; 184 struct timespec req;
162 char *buf[recorder->page_size];
163 long ret; 185 long ret;
164 186
165 recorder->stop = 0; 187 recorder->stop = 0;
@@ -175,21 +197,12 @@ int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long s
175 return ret; 197 return ret;
176 } while (!recorder->stop); 198 } while (!recorder->stop);
177 199
178 /* Flush via splice first */ 200 /* Flush out the rest */
179 do { 201 ret = tracecmd_flush_recording(recorder);
180 ret = splice_data(recorder);
181 } while (ret > 0);
182 202
183 if (ret < 0) 203 if (ret < 0)
184 return ret; 204 return ret;
185 205
186 /* splice only reads full pages */
187 do {
188 ret = read(recorder->trace_fd, buf, recorder->page_size);
189 if (ret > 0)
190 write(recorder->fd, buf, ret);
191 } while (ret > 0);
192
193 return 0; 206 return 0;
194} 207}
195 208