0

I am about to find out how a specific process, in C, loads the CPU over a certain time frame. The process may switch processor core during runtime, therefore I need to handle that too. The CPU is an ARM processor.

I have looked at different ways to get the load, from standard top, perf and also to calculate the load through the statistics given in the /proc/[pid]/stat-file.

My thoughts is to have a program that read the /proc/[pid]/stat-file as suggested in the thread: "How to calculate the CPU usage of a process by PID in Linux from C?" and calculate the load accordingly. But how would I treat core switching? I need to notice it and adjust the load calculation.

How would you recommend me to achieve this?

Update: How can I see which core the process runs in and by that examine if it has switched core since the last chack assuming I poll the process figures/statistics at least twice?

Community
  • 1
  • 1
Curious
  • 13
  • 3
  • possible duplicate of [total cpu usage of an application from /proc/pid/stat](http://stackoverflow.com/questions/16726779/total-cpu-usage-of-an-application-from-proc-pid-stat) – Jahaja Oct 30 '14 at 15:49
  • @Jahaja That post was good but it lacks the handling of when the process is executed first on core A and after a while on core B? – Curious Oct 30 '14 at 22:23
  • 1
    Which cpu core the process scheduler happens to put the process shouldn't affect the accounting of the amount of cpu time the process has received. – Jahaja Oct 30 '14 at 23:02
  • Alright, you are right about that @Jahaja. – Curious Oct 31 '14 at 06:33

1 Answers1

0

The perf tool can tell you the amount of cpu-migrations your process has made. That is, how many times the process has switched cpu. It won't tell you which cpu cores though.

Jahaja
  • 3,222
  • 1
  • 20
  • 11