aboutsummaryrefslogtreecommitdiffstats
path: root/trace-input.c
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 /trace-input.c
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>
Diffstat (limited to 'trace-input.c')
-rw-r--r--trace-input.c48
1 files changed, 48 insertions, 0 deletions
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];