From emaste@FreeBSD.org  Fri Nov 21 16:12:32 2008
Return-Path: <emaste@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id BA5CF1065673
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 21 Nov 2008 16:12:32 +0000 (UTC)
	(envelope-from emaste@FreeBSD.org)
Received: from ref8-amd64.freebsd.org (ref8-amd64.freebsd.org [IPv6:2001:4f8:fff6::5f])
	by mx1.freebsd.org (Postfix) with ESMTP id ABDB48FC0C
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 21 Nov 2008 16:12:32 +0000 (UTC)
	(envelope-from emaste@FreeBSD.org)
Received: from ref8-amd64.freebsd.org (localhost [127.0.0.1])
	by ref8-amd64.freebsd.org (8.14.3/8.14.3) with ESMTP id mALGCWmt027320
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 21 Nov 2008 16:12:32 GMT
	(envelope-from emaste@ref8-amd64.freebsd.org)
Received: (from emaste@localhost)
	by ref8-amd64.freebsd.org (8.14.3/8.14.3/Submit) id mALGCWSa027319;
	Fri, 21 Nov 2008 16:12:32 GMT
	(envelope-from emaste)
Message-Id: <200811211612.mALGCWSa027319@ref8-amd64.freebsd.org>
Date: Fri, 21 Nov 2008 16:12:32 GMT
From: Ed Maste <emaste@FreeBSD.org>
Reply-To: Ed Maste <emaste@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: ps(1) %cpu column reports misleading data for threaded programs
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         129052
>Category:       bin
>Synopsis:       ps(1) %cpu column reports misleading data for threaded programs
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 21 16:20:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Ed Maste
>Release:        FreeBSD 8.0-CURRENT amd64
>Organization:
FreeBSD
>Environment:
System: FreeBSD ref8-amd64.freebsd.org 8.0-CURRENT FreeBSD 8.0-CURRENT #0 r184542: Sun Nov 2 00:26:55 UTC 2008 peter@ref8-amd64.freebsd.org:/scratch/src/sys/amd64/compile/REF8-AMD64 amd64


>Description:

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.

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
