Skip to content

Commit

Permalink
trace-cmd library: Have tracecmd_iterate_events() start where it left…
Browse files Browse the repository at this point in the history
… off

When a callback to tracecmd_iterate_events() returns non-zero, it exits
the iteration. Allow a sequential call to tracecmd_iterate_events() to
start were it left off.

The iterator peeks at the data which needs to be cleared. But the peek
itself set the next read to be the next record. On a sequential iterator
call, it will not include the cached records that were left over from the
previous iterator call.

Make sure at the end of the iterator to reset the indexes so that the next
reads will be the recorders that were not processed by the iterator.

Also do the same for tracecmd_iterate_events_multi() and remove the stale
comment about not needing to free the records.

Link: https://lore.kernel.org/linux-trace-devel/[email protected]

Fixes: 2cb6cc2 ("tracecmd library: Add tracecmd_iterate_events()")
Fixes: b37903a ("tracecmd library: Add tracecmd_iterate_events_multi()")
Signed-off-by: Steven Rostedt (Google) <[email protected]>
  • Loading branch information
rostedt committed Jul 6, 2023
1 parent ac643de commit 7f0a59a
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/trace-cmd/trace-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -2820,10 +2820,15 @@ int tracecmd_iterate_events(struct tracecmd_input *handle,

/* Need to unlock and free the records */
for (cpu = 0; cpu < handle->max_cpu; cpu++) {
int offset;

if (!records[cpu])
continue;
record = tracecmd_read_data(handle, cpu);
tracecmd_free_record(record);

offset = (int)(records[cpu]->offset & (handle->page_size - 1));
free_next(handle, cpu);
/* Reset the buffer to read the cached record again */
kbuffer_read_at_offset(handle->cpu_data[cpu].kbuf, offset, NULL);
}

free(records);
Expand Down Expand Up @@ -2917,20 +2922,20 @@ int tracecmd_iterate_events_multi(struct tracecmd_input **handles,
/* Unlock and free the records */
for (cpu = 0; cpu < all_cpus; cpu++) {
int local_cpu;
int offset;

if (!records[cpu].record)
continue;

handle = records[cpu].handle;
local_cpu = cpu - handle->start_cpu;
record = tracecmd_read_data(handle, local_cpu);
tracecmd_free_record(record);

offset = (int)(records[cpu].record->offset & (handle->page_size - 1));
free_next(handle, local_cpu);
/* Reset the buffer to read the cached record again */
kbuffer_read_at_offset(handle->cpu_data[cpu].kbuf, offset, NULL);
}

/*
* The records array contains only records that were taken via
* tracecmd_peek_data(), and do not need to be freed.
*/
free(records);

return ret;
Expand Down

0 comments on commit 7f0a59a

Please sign in to comment.