Search code examples
clinuxperformancelinux-kernel

Find out which thread/process is consuming CPU


While examining a software performance issue in embedded linux system, I need to check which thread blocks the CPU for example for 100ms straight. Since the requirement to figure out is at ms level, normal commands that sample at a given interval wont work and being an embedded system those commands come with very limited options.

Instead, I am thinking to add some code inside the scheduler that can record this information about which thread has blocked/consumed the CPU for a given time frame.

I want to know what is the place in kernel where I can make changes to record this information first in some variable in memory then I can probably flush/log to file at a later time.


Solution

  • You can add the code in core.c or fair.c file under the kernel/sched directory which contains the scheduler code