aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-01-13 12:13:30 -0500
committerSteven Rostedt <rostedt@goodmis.org>2010-01-13 12:13:30 -0500
commitc25df862b0a904d01bde0604c8165ba48b8172cd (patch)
tree31c6d7338c3615cd1a47a8e6e1a129ee224b41d1
parentaf80aa3150ae72497c8ed3c3bb9211667d82f57b (diff)
trace-cmd: Move merge sort of reading records into library
The merge sort of reading the record timestamps and ording the records by time, regardless of CPU, has been moved from the trace-cmd.c file into the libtracecmd library code trace-input.c. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-cmd.h3
-rw-r--r--trace-input.c48
-rw-r--r--trace-read.c30
3 files changed, 61 insertions, 20 deletions
diff --git a/trace-cmd.h b/trace-cmd.h
index 3639fdd..13d913a 100644
--- a/trace-cmd.h
+++ b/trace-cmd.h
@@ -61,6 +61,9 @@ struct record *
61tracecmd_read_data(struct tracecmd_input *handle, int cpu); 61tracecmd_read_data(struct tracecmd_input *handle, int cpu);
62 62
63struct record * 63struct record *
64tracecmd_read_next_data(struct tracecmd_input *handle, int *rec_cpu);
65
66struct record *
64tracecmd_read_at(struct tracecmd_input *handle, unsigned long long offset, 67tracecmd_read_at(struct tracecmd_input *handle, unsigned long long offset,
65 int *cpu); 68 int *cpu);
66struct record * 69struct record *
diff --git a/trace-input.c b/trace-input.c
index dc1167a..ece0aab 100644
--- a/trace-input.c
+++ b/trace-input.c
@@ -1339,6 +1339,54 @@ tracecmd_read_data(struct tracecmd_input *handle, int cpu)
1339 return record; 1339 return record;
1340} 1340}
1341 1341
1342/**
1343 * tracecmd_read_next_data - read the next record
1344 * @handle: input handle to the trace.dat file
1345 * @rec_cpu: return pointer to the CPU that the record belongs to
1346 *
1347 * This returns the next record by time. This is different than
1348 * tracecmd_read_data in that it looks at all CPUs. It does a peek
1349 * at each CPU and the record with the earliest time stame is
1350 * returned. If @rec_cpu is not NULL it gets the CPU id the record was
1351 * on. The CPU cursor of the returned record is moved to the
1352 * next record.
1353 *
1354 * Multiple reads of this function will return a serialized list
1355 * of all records for all CPUs in order of time stamp.
1356 *
1357 * The record returned must be freed.
1358 */
1359struct record *
1360tracecmd_read_next_data(struct tracecmd_input *handle, int *rec_cpu)
1361{
1362 unsigned long long ts;
1363 struct record *record;
1364 int next;
1365 int cpu;
1366
1367 if (rec_cpu)
1368 *rec_cpu = -1;
1369
1370 next = -1;
1371 ts = 0;
1372
1373 for (cpu = 0; cpu < handle->cpus; cpu++) {
1374 record = tracecmd_peek_data(handle, cpu);
1375 if (record && (!ts || record->ts < ts)) {
1376 ts = record->ts;
1377 next = cpu;
1378 }
1379 }
1380
1381 if (next >= 0) {
1382 if (rec_cpu)
1383 *rec_cpu = next;
1384 return tracecmd_read_data(handle, next);
1385 }
1386
1387 return NULL;
1388}
1389
1342static int init_cpu(struct tracecmd_input *handle, int cpu) 1390static int init_cpu(struct tracecmd_input *handle, int cpu)
1343{ 1391{
1344 struct cpu_data *cpu_data = &handle->cpu_data[cpu]; 1392 struct cpu_data *cpu_data = &handle->cpu_data[cpu];
diff --git a/trace-read.c b/trace-read.c
index 306fa3a..a04c85b 100644
--- a/trace-read.c
+++ b/trace-read.c
@@ -189,16 +189,14 @@ static void test_save(struct record *record, int cpu)
189} 189}
190#endif 190#endif
191 191
192static void show_data(struct tracecmd_input *handle, int cpu) 192static void show_data(struct tracecmd_input *handle,
193 struct record *record, int cpu)
193{ 194{
194 struct pevent *pevent; 195 struct pevent *pevent;
195 struct record *record;
196 struct trace_seq s; 196 struct trace_seq s;
197 197
198 pevent = tracecmd_get_pevent(handle); 198 pevent = tracecmd_get_pevent(handle);
199 199
200 record = tracecmd_read_data(handle, cpu);
201
202 test_save(record, cpu); 200 test_save(record, cpu);
203 201
204 trace_seq_init(&s); 202 trace_seq_init(&s);
@@ -226,7 +224,7 @@ static void read_rest(void)
226static void read_data_info(struct tracecmd_input *handle) 224static void read_data_info(struct tracecmd_input *handle)
227{ 225{
228 unsigned long long ts; 226 unsigned long long ts;
229 struct record *data; 227 struct record *record;
230 int cpus; 228 int cpus;
231 int next; 229 int next;
232 int cpu; 230 int cpu;
@@ -250,22 +248,14 @@ static void read_data_info(struct tracecmd_input *handle)
250 ts = 0; 248 ts = 0;
251 if (filter_cpu >= 0) { 249 if (filter_cpu >= 0) {
252 cpu = filter_cpu; 250 cpu = filter_cpu;
253 data = tracecmd_peek_data(handle, cpu); 251 record = tracecmd_peek_data(handle, cpu);
254 if (data) 252 } else
255 next = cpu; 253 record = tracecmd_read_next_data(handle, &cpu);
256 } else { 254
257 for (cpu = 0; cpu < cpus; cpu++) { 255 if (record)
258 data = tracecmd_peek_data(handle, cpu); 256 show_data(handle, record, next);
259 if (data && (!ts || data->ts < ts)) {
260 ts = data->ts;
261 next = cpu;
262 }
263 }
264 }
265 if (next >= 0)
266 show_data(handle, next);
267 257
268 } while (next >= 0); 258 } while (record);
269 259
270 show_test(handle); 260 show_test(handle);
271} 261}