1

I need to find out how many CPU cores a given process has executed on during a certain time e.g 1 second or so? This has to be done from a C program (or possibly C++). I know that perf presents the number of cpu-migrations.

I need to know the number of CPU core swaps and also which cores the process has used. I assume that I first have to get which threads the process executes in and then to see what cores the threads run on.

The information I get is to be used to calculate the CPU load for a process. When running in only one CPU core I know how to do and have a working solution. However, handling several CPU cores that a process consisting of several threads that run in one or several CPU cores at different times makes it harder. Is there any solution or hint to solution anyone here could point at?

2
  • Maybe some points it that post can help: stackoverflow.com/q/26362261/3194340 even it is about forcing a number of CPU for a process Commented Nov 4, 2014 at 9:33
  • @Coconop Thanks for your comment. However, I can not (and prefer not to) change the affinity of the process I observe. Commented Nov 4, 2014 at 9:38

2 Answers 2

1

I don't have a definitive answer, but here is what I found. I use stress -c 1 -t 1 (runs a sqrt+loop process during one second).

I think this answers your very first question (find out how many migrations happen during the execution of your process).

$ perf stat -e migrations stress -c 1 -t 1
stress: info: [4159] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd
stress: info: [4159] successful run completed in 1s
 Performance counter stats for 'stress -c 1 -t 1':
                 2      migrations

Next I found an interesting tracepoint:

perf stat -e sched:sched_migrate_task stress -c 1 -t 1

and it happens that sched_migrate_task has a dest_cpu argument which I don't know how to trace.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Emilien. Is there a way to call perf from a C program besides through system call?
0

Try out the tool kernelshark . It provides better visual representation of multi-core system, affinity and many more features that can help in information gathering.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.