Search code examples
perf

How do I sample all threads and record their thread id with perf?


I want to get information about what each thread is doing at regular intervals. Unfortunately I can see in the perf script output that no thread id is recorded, because the output looks the same with -F +tid as with -F -tid.

I tried using the --per-thread option but it doesn't do what I want. Instead, it seems to drop the timestamp field from the data.

Is this possible? If not, what does the data reported by perf for a multithreaded program mean – does it just sample the main thread, or random threads?


Solution

  • As it turns out, perf record already records threads and their ID. What got me confused is that the thread ID of the main thread is equal to the process ID. I also must have been doing something wrong when doing the -F -tid test, because indeed the column with the thread ID disappears.