diff options
Diffstat (limited to 'trace-recorder.c')
-rw-r--r-- | trace-recorder.c | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/trace-recorder.c b/trace-recorder.c index 2a754b9..e57ef9b 100644 --- a/trace-recorder.c +++ b/trace-recorder.c | |||
@@ -128,11 +128,39 @@ struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu) | |||
128 | return recorder; | 128 | return recorder; |
129 | } | 129 | } |
130 | 130 | ||
131 | /* | ||
132 | * Returns -1 on error. | ||
133 | * or bytes of data read. | ||
134 | */ | ||
135 | static long splice_data(struct tracecmd_recorder *recorder) | ||
136 | { | ||
137 | long ret; | ||
138 | |||
139 | ret = splice(recorder->trace_fd, NULL, recorder->brass[1], NULL, | ||
140 | recorder->page_size, 1 /* SPLICE_F_MOVE */); | ||
141 | if (ret < 0) { | ||
142 | warning("recorder error in splice input"); | ||
143 | return -1; | ||
144 | } | ||
145 | |||
146 | ret = splice(recorder->brass[0], NULL, recorder->fd, NULL, | ||
147 | recorder->page_size, 3 /* and NON_BLOCK */); | ||
148 | if (ret < 0) { | ||
149 | if (errno != EAGAIN) { | ||
150 | warning("recorder error in splice output"); | ||
151 | return -1; | ||
152 | } | ||
153 | ret = 0; | ||
154 | } | ||
155 | |||
156 | return ret; | ||
157 | } | ||
158 | |||
131 | int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep) | 159 | int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep) |
132 | { | 160 | { |
133 | struct timespec req; | 161 | struct timespec req; |
134 | char *buf[recorder->page_size]; | 162 | char *buf[recorder->page_size]; |
135 | int ret; | 163 | long ret; |
136 | 164 | ||
137 | recorder->stop = 0; | 165 | recorder->stop = 0; |
138 | 166 | ||
@@ -142,21 +170,19 @@ int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long s | |||
142 | req.tv_nsec = (sleep % 1000000) * 1000; | 170 | req.tv_nsec = (sleep % 1000000) * 1000; |
143 | nanosleep(&req, NULL); | 171 | nanosleep(&req, NULL); |
144 | } | 172 | } |
145 | 173 | ret = splice_data(recorder); | |
146 | ret = splice(recorder->trace_fd, NULL, recorder->brass[1], NULL, | 174 | if (ret < 0) |
147 | recorder->page_size, 1 /* SPLICE_F_MOVE */); | 175 | return ret; |
148 | if (ret < 0) { | ||
149 | warning("recorder error in splice input"); | ||
150 | return -1; | ||
151 | } | ||
152 | ret = splice(recorder->brass[0], NULL, recorder->fd, NULL, | ||
153 | recorder->page_size, 3 /* and NON_BLOCK */); | ||
154 | if (ret < 0 && errno != EAGAIN) { | ||
155 | warning("recorder error in splice output"); | ||
156 | return -1; | ||
157 | } | ||
158 | } while (!recorder->stop); | 176 | } while (!recorder->stop); |
159 | 177 | ||
178 | /* Flush via splice first */ | ||
179 | do { | ||
180 | ret = splice_data(recorder); | ||
181 | } while (ret > 0); | ||
182 | |||
183 | if (ret < 0) | ||
184 | return ret; | ||
185 | |||
160 | /* splice only reads full pages */ | 186 | /* splice only reads full pages */ |
161 | do { | 187 | do { |
162 | ret = read(recorder->trace_fd, buf, recorder->page_size); | 188 | ret = read(recorder->trace_fd, buf, recorder->page_size); |