tools lib traceevent: Remove unneeded qsort and uses memmove instead
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Wed, 28 Aug 2019 19:05:29 +0000 (15:05 -0400)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 29 Aug 2019 11:36:12 +0000 (08:36 -0300)
commit301011ba622513cb41ced59973972204e0da2f71
tree0e9cee872cef88d9e31dc0923adf8e1297106fe2
parentb0215e2d6a18d8331b2d4a8b38ccf3eff783edb1
tools lib traceevent: Remove unneeded qsort and uses memmove instead

While reading a trace data file that had 100,000s of tasks, the process
took an extremely long time. I profiled it down to add_new_comm(), which
was doing a qsort() call on an array that was pretty much already sorted
(all but the last element. qsort() isn't very efficient when dealing
with mostly sorted arrays, and this definitely showed its issues.

When adding a new task to the task list, instead of using qsort(), do
another bsearch() with a function that will find the element before
where the new task will be inserted in. Then simply shift the rest of
the array, and insert the task where it belongs.

Fixes: f7d82350e597d ("tools/events: Add files to create libtraceevent.a")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20190828191820.127233764@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/traceevent/event-parse.c