How do I measure separate CPU core usage for a process?

前端 未结 8 1487
故里飘歌
故里飘歌 2021-01-29 18:45

Is there any way to measure a specific process CPU usage by cores?

I know top is good for measuring the whole system\'s CPU usage by cores and taskset can provide inform

8条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 19:08

    I had just this problem and I found a similar answer here.

    The method is to set top the way you want it and then press W (capital W). This saves top's current layout to a configuration file in $HOME/.toprc

    Although this might not work if you want to run multiple top's with different configurations.

    So via what I consider a work around you can write to different config files / use different config files by doing one of the following...

    1) Rename the binary

      ln -s /usr/bin/top top2
      ./top2
    

    Now .top2rc is going to be written to your $HOME

    2) Set $HOME to some alternative path, since it will write its config file to the $HOME/.binary-name.rc file

    HOME=./
    top
    

    Now .toprc is going to be written to the current folder.

    Via use of other peoples comments to add the various usage accounting in top you can create a batch output for that information and latter coalesces the information via a script. Maybe not quite as simple as you script but I found top to provide me ALL processes so that later I can recap and capture a state during a long run that I might have missed otherwise (unexplained sudden CPU usage due to stray processes)

提交回复
热议问题