Bug 218357

Summary: trace-cmd split doesn't handle multiple instances
Product: Tools Reporter: pierre.gondois
Component: Trace-cmd/KernelsharkAssignee: Default virtual assignee for Trace-cmd and kernelshark (tools_tracecmd_kernelshark)
Status: RESOLVED CODE_FIX    
Severity: normal CC: rostedt
Priority: P3    
Hardware: All   
OS: Linux   
Kernel Version: Subsystem:
Regression: No Bisected commit-id:
Attachments: trace.dat recorded with the record command given as example
Handle leaf node case in rbtree deletion

Description pierre.gondois 2024-01-09 10:29:07 UTC
Created attachment 305690 [details]
trace.dat recorded with the record command given as example

trace-cmd can record events in multiple instances:
  $ trace-cmd record -e sched_wakeup -B test_instance -e sched_switch

When trying to split a trace.dat file recorded with the above command, only the events located in the main buffer seems to be split. The events recorded in the test_instance buffer seem to be discarded:
  $ trace-cmd split -i trace.dat -o trace_2.dat 284443 284444
  $ trace-cmd report trace_2.dat
    cpus=8
           <...>-525991 [004] 284443.173879: sched_wakeup:         wdavdaemon:525987 [120] CPU:007
           <...>-525991 [004] 284443.173879: sched_wakeup:         wdavdaemon:525987 [120] CPU:007
           <...>-525990 [007] 284443.173885: sched_wakeup:         wdavdaemon:525986 [120] CPU:007
           <...>-525990 [007] 284443.173885: sched_wakeup:         wdavdaemon:525986 [120] CPU:007
(no sign of sched_switch events)

As a side issue, it also seems that some timestamps make the trace-cmd split command fail:
  $ trace-cmd split -i trace.dat -o trace_2.dat 284443.2003 284444
  Segmentation fault
Comment 1 pierre.gondois 2024-01-09 10:35:22 UTC
I forgot to mention, trace-cmd is built from the latest:
08435acd37326c7030747dc5c3a10daca185e6fe (HEAD, origin/master, origin/HEAD) trace-cmd stat: Use tracefs_instance_file_read()
Comment 2 Steven Rostedt 2024-01-10 04:03:35 UTC
Moving to Tools: trace-cmd/KernelShark

As "Tracing/Profiling" is for the kernel component not the tooling.
Comment 3 pierre.gondois 2024-01-10 08:44:01 UTC
I have started to work on it, just to avoid a duplicated effort.
Comment 4 Steven Rostedt 2024-01-10 13:44:21 UTC
Created attachment 305691 [details]
Handle leaf node case in rbtree deletion

Can you see if this patch fixes it for you. The rbtree did't handle a deletion of a leaf node. I have no idea how this didn't trigger in my tests.
Comment 5 pierre.gondois 2024-01-10 14:00:07 UTC
Yes it solves the Segmentation fault issue,

Thanks
Comment 6 Steven Rostedt 2024-01-10 15:44:47 UTC
Unfortunately that patch is incorrect. Although it fixes the segfault, it corrupts the rbtree. I have the real fix here:

  https://lore.kernel.org/all/20240110103941.2e26da60@gandalf.local.home/