Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How pidstat calculates CPU usage on each core and in total? #335

Open
wuzengshun opened this issue Sep 8, 2022 · 2 comments
Open

How pidstat calculates CPU usage on each core and in total? #335

wuzengshun opened this issue Sep 8, 2022 · 2 comments

Comments

@wuzengshun
Copy link

Hi everyone,
I've been using pidstat recently, but I'm having some problems with the interpretation of the data, I'd like to get some answers, thanks!

1. What is the method about calculating the total CPU usage? I added up the usage on each core and found that it is not equal to the total usage shown by pidstat?

The table below:
The total %usr of pidstat is 43.14, but the %usr of each core adds up to 45.09
pidstat total %system is 15.69, but %system per core adds up to 15.68
pidstat total %CPU is 58.82, but %CPU per core adds up to 60.77

adb shell '/data/local/tmp/sysstat/pidstat 1 -p pidof -s %perf_proc_name% -r -d -t -u' > pidstat.txt

Linux 5.10.81-gki-g5cc049ba3e0a (localhost) 09/07/22 aarch64 (8 CPU)

UID TGID TID %usr %system %guest %wait %CPU CPU Command
16:09:23 10250 26897 - 43.14 15.69 0.00 2.94 58.82 6 droid.ugc.aweme
16:09:23 10250 - 26897 8.82 0.98 0 2.94 9.8 6 |__droid.ugc.aweme
16:09:23 10250 - 26912 0.98 0.98 0 0.98 1.96 3 |__Binder:26897_2
16:09:23 10250 - 26980 3.92 1.96 0 0 5.88 4 |__pool-3-thread-1
16:09:23 10250 - 27067 0.98 0 0 0 0.98 2 |__looper_monitor
16:09:23 10250 - 27068 0 0.98 0 0 0.98 1 |__looper_monitor
16:09:23 10250 - 27074 12.75 2.94 0 2.94 15.69 4 |__RenderThread
16:09:23 10250 - 27163 0.98 0.98 0 0 1.96 3 |__GPU completion
16:09:23 10250 - 27184 0.98 0 0 0 0.98 2 |__Binder:26897_5
16:09:23 10250 - 27289 0.98 0.98 0 0 96 2 |__motion_familiar
16:09:23 10250 - 27297 0 0.98 0 0 98 0 |__Reader-V1
16:09:23 10250 - 27304 2.94 0.98 0 1.96 3.92 4 |__MediaCodec_loop
16:09:23 10250 - 27305 0.98 0 0 0 0.98 3 |__CodecLooper
16:09:23 10250 - 27309 0.98 1.96 0 1.96 2.94 4 |_HwBinder:26897
16:09:23 10250 - 27330 0.98 0.98 0 0.98 1.96 3 |__VDecode-V1
16:09:23 10250 - 27331 2.94 0 0 0 2.94 2 |__ADecode-V1
16:09:23 10250 - 27332 0.98 0 0 0 0.98 3 |__AGraph-V1
16:09:23 10250 - 27333 1.96 0.98 0 0.98 2.94 3 |__VOutlet-V1
16:09:23 10250 - 27334 2.94 0 0 0.98 2.94 0 |__AOutlet-V1
16:09:23 10250 - 27984 0 0.98 0 0 0.98 1 |__Reader-V2
45.09 15.68 60.77

2. What does the CPU id represent in the line of data about total usage (CPU 6 as shown below)? I'm guessing it doesn't mean the process is executing on this core.

UID TGID TID %usr %system %guest %wait %CPU CPU Command
16:09:23 10250 26897 - 43.14 15.69 0.00 2.94 58.82 6 droid.ugc.aweme
@wuzengshun
Copy link
Author

3. In combination with mpstat, there is another rather strange phenomenon.
I see from mpstat that the CPU usage of core 4 at 16:09:23, %usr is 11.22.
But I use pidstat to count the CPU usage of process 'droid.ugc.aweme' in different threads on core 4 and add up 20.59. This figure is much higher than 11.2. Is this a bug?

adb shell "/data/local/tmp/sysstat/mpstat 1 -P ALL" > mpstat.txt
Linux 5.10.81-gki-g5cc049ba3e0a (localhost) 09/07/22 aarch64 (8 CPU)

16:09:22 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
16:09:23 all 9.53 2.16 8.01 0.00 1.78 0.13 0.00 0.00 0.00 78.40
16:09:23 0 14.74 0.00 12.63 0.00 4.21 0.00 0.00 0.00 0.00 68.42
16:09:23 1 10.00 0.00 16.00 0.00 3.00 1.00 0.00 0.00 0.00 70.00
16:09:23 2 15.62 0.00 11.46 0.00 2.08 0.00 0.00 0.00 0.00 70.83
16:09:23 3 11.96 0.00 8.70 0.00 3.26 0.00 0.00 0.00 0.00 76.09
16:09:23 4 11.22 0.00 6.12 0.00 0.00 0.00 0.00 0.00 0.00 82.65
16:09:23 5 4.85 4.85 0.97 0.00 0.97 0.00 0.00 0.00 0.00 88.35
16:09:23 6 8.65 6.73 7.69 0.00 0.96 0.00 0.00 0.00 0.00 75.96
16:09:23 7 0.00 5.05 1.01 0.00 0.00 0.00 0.00 0.00 0.00 93.94

@brofu
Copy link

brofu commented Nov 17, 2022

This maybe helpful, for the 1st question. #344 (comment)
@wuzengshun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants