Bug 129052 - ps(1) %cpu column reports misleading data for threaded programs
Summary: ps(1) %cpu column reports misleading data for threaded programs
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 8.0-CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-21 16:20 UTC by Ed Maste
Modified: 2014-06-05 18:37 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2008-11-21 16:20:01 UTC
When running ps without -H (show all threads), only one thread's %CPU
is shown.  This can be very misleading: if a process has one idle
thread and other busy threads and ps(1) can report 0% cpu.

How-To-Repeat: 
Run ps with and without -H, and compare the %CPU data

[emaste@ref8-amd64 ~]$ ps -a -x -p 11 -opid,lwp,comm,tdnam,%cpu
  PID    LWP COMMAND             TDNAM               %CPU
   11 100010 idle                                    100.0

[emaste@ref8-amd64 ~]$ ps -a -x -H -p 11 -opid,lwp,comm,tdnam,%cpu
  PID    LWP COMMAND             TDNAM               %CPU
   11 100003 idle                idle: cpu7          99.9
   11 100004 idle                idle: cpu6          100.0
   11 100005 idle                idle: cpu5          74.9
   11 100006 idle                idle: cpu4          91.7
   11 100007 idle                idle: cpu3          96.1
   11 100008 idle                idle: cpu2          100.0
   11 100009 idle                idle: cpu1          100.0
   11 100010 idle                idle: cpu0          100.0

Note %CPU comes from just the last thread in this case.

Other per-thread data probably has the same problem.
Comment 1 Ed Maste freebsd_committer freebsd_triage 2014-06-05 14:13:11 UTC
Not reproducible on stable/9:

feynman% ps -a -x -p 11 -opid,lwp,comm,tdnam,%cpu
PID    LWP COMMAND TDNAM   %CPU
 11 100010 idle           725.7
feynman% ps -a -x -H -p 11 -opid,lwp,comm,tdnam,%cpu
PID    LWP COMMAND         TDNAM      %CPU
 11 100003 idle/idle: cpu0 idle: cpu0 86.4
 11 100004 idle/idle: cpu1 idle: cpu1 93.2
 11 100005 idle/idle: cpu2 idle: cpu2 89.8
 11 100006 idle/idle: cpu3 idle: cpu3 91.7
 11 100007 idle/idle: cpu4 idle: cpu4 93.3
 11 100008 idle/idle: cpu5 idle: cpu5 88.6
 11 100009 idle/idle: cpu6 idle: cpu6 88.2
 11 100010 idle/idle: cpu7 idle: cpu7 91.1
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2014-06-05 18:17:04 UTC
fixing resolution.
Comment 3 Ed Maste freebsd_committer freebsd_triage 2014-06-05 18:18:59 UTC
This should be "FIXED", I just didn't find out when the fix landed.
Comment 4 Eitan Adler freebsd_committer freebsd_triage 2014-06-05 18:37:28 UTC
sorry, was testing something, needed a real bug :-\