The commands above will identify the sys_write which takes time but only
provide the stacktrace at the entry and exit of the syscall, but this do
not show why the process blocked or what it did inside the system call.
So a way to get what is required for the use case would be to make the
following changes to the above sequence:
(1) include the sched:* events when perf trace record is run
(2) around the time of interest, look at the kernel stack st the sched:switch
events between the entry and the exit. This will show what the process was
waiting for when it when it blocked. The stacktraces at the
stat_runtime events in the process may also be useful to understand what
was going on.