aboutsummaryrefslogtreecommitdiffstats
path: root/trace-recorder.c
diff options
context:
space:
mode:
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