On Thu, Aug 17, 2023 at 06:24:14PM -0400, Steven Rostedt wrote: > From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx> > > When an iterator is created, it creates an array of pointers to point to > all the elements in the traceeval. This is used to index through the > entities in an nice order. But if an event is added or removed from the > traceeval, the size and count of this array will be off in the iterator. > > Add an "update_counter" that gets incremented every time an item is added > or removed (doesn't need to keep track of updates to existing entries). If > the counter is different from the last time the iterator created the sort > array, it will need to delete and recreate the list again before it can do > a sort. > > Note: It is safe to use the iterator to remove times, so a removal (or items > even insert) should not affect the traceeval_iterator_next(). But it > should be explained in the man pages (soon to be written) that doing so > must be done with care. And maybe a helper function should be used > instead! > > Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx> > --- > src/eval-local.h | 2 ++ > src/histograms.c | 91 ++++++++++++++++++++++++++++++++++++++---------- > 2 files changed, 74 insertions(+), 19 deletions(-) <> > @@ -1168,6 +1190,31 @@ static int iter_cmp(const void *A, const void *B, void *data) > return 0; > } > > +static int check_update(struct traceeval_iterator *iter) > +{ > + struct entry **entries; > + size_t nr_entries; > + int ret; > + > + /* Was something added or removed from the teval? */ > + if (iter->teval->update_counter == iter->update_counter) > + return 0; > + > + entries = iter->entries; > + nr_entries = iter->nr_entries; > + > + /* Something changed, need to recreate the array */ > + ret = create_iter_array(iter); > + if (ret < 0) { > + iter->entries = entries; > + iter->nr_entries = nr_entries; > + return -1; ^^ extra tab Aside from these 2 nits: Reviewed-by: Ross Zwisler <zwisler@xxxxxxxxxx>