Commit Graph

335 Commits

Author SHA1 Message Date
Eitan Adler
01a55f006a top(1): partial revert of r334517
In fixing issues with uid > INT_MAX, I broke the uid without username
case. The latter is more important so return the old state.

Discussed with:	allanjude
2018-06-03 05:20:11 +00:00
Eitan Adler
b7128a09ce top(1): remove chdir to /
While this came out of a conversation in IRC, it turn out that some
people don't like it. Since this was a courtesy feature, just remove it.
2018-06-03 05:07:46 +00:00
Eitan Adler
1d5b01e66e top(1): use greater warnings
One of the downsides of using numeric WARNS is that if we only have a
single type of issue we get no protection from other changes.  For
example, we got no warning for missing variable declaration, due to
the issues with "const".

For this utility, explicitly list out the warnings which are failing.
They should still be fixed, so only reduce them to warning instead of
error.

Tested with: clang base (amd64, i386), gcc6, gcc7, gcc9, gcc base (mips)
2018-06-03 05:07:39 +00:00
Eitan Adler
d0bb69dc07 top(1): misc minor improvements
- use bool instead of int [0]
- use calloc correctly [0]
	(this also caught an incorrect sizeof argument) [1]
- use size_t over int [2]
- correct style

Reported by:	pfg [0], scan-build [1], gcc [2]
2018-06-03 02:58:53 +00:00
Eitan Adler
c51e28f46f top(1): Fix two speeling errors I introduced 2018-06-02 22:12:57 +00:00
Eitan Adler
f32efe0205 top(1): chdir to / as init; remove unneeded comment
- chdir to / to allow unmounting of wd
- remove warning about running top(1) as setuid. If this is a concern we
should just drop privs instead.
2018-06-02 22:06:27 +00:00
Eitan Adler
4fedcd4983 top(1): cleanup memory allocation and warnings
- Prefer calloc over malloc. This is more predicable and we're not in a
performance sensitive context. [1]
- Remove bogus comment (obsolete from prior commit). [2]
- Remove void casts and type casts of NULL
- Remove redundant declaration of 'quit'
- Add additional const

Reported by:	kib [1], vangyzen [2]
2018-06-02 21:40:45 +00:00
Roman Bogorodskiy
51b29cb7b3 top: add -p option and p command to only show a single process
Allow to show only a single process specified by PID. This could
be done either by running top like 'top -p PID' or using the 'p' command
inside top.

Reviewed by:	eadler
Approved by:	eadler
Obtained from:	OpenBSD
Differential Revision:	https://reviews.freebsd.org/D15501
2018-06-02 15:52:18 +00:00
Eitan Adler
b274c68a20 Use stpcpy instead of home grown solution 2018-06-02 08:46:09 +00:00
Eitan Adler
2c1fdbac13 top(1): remove wrapper around putchar
This appears to have been written for portability which we no longer
need.
2018-06-02 07:44:53 +00:00
Eitan Adler
960a7f3960 top(1): const poison part 2
Further reduce the number of warnings emitted by gcc.
2018-06-02 07:44:50 +00:00
Eitan Adler
66b3f031f0 top(1): const poison
top(1) has a number of issues with writing to const strings. Begin
helping this along by marking easy cases as const.
2018-06-02 04:37:37 +00:00
Eitan Adler
0059e7102f top(1): clean up a bit
- remove unused defines
- use standard defines for STDOUT
- don't cast for memset
- avoid using (void) cast
2018-06-02 04:20:42 +00:00
Eitan Adler
cffee2bc5b top(1): help scan-build along a bit
Teach scan-build that some arrays are larger than zero, and thus not to
warn.
2018-06-02 04:08:52 +00:00
Eitan Adler
1978939544 top(1): Use uid_t for uid rather than 'int'
Remove unneeded define while here.
2018-06-02 03:54:50 +00:00
Eitan Adler
f4d9a8de00 top(1): Remove now-invalid NOTE 2018-06-02 03:33:02 +00:00
Eitan Adler
3798694c01 top(1): avoid casting malloc 2018-06-02 03:31:14 +00:00
Eitan Adler
0b2f6ed144 top(1): Use standard boolean rather than homegrown alternative 2018-06-02 03:25:15 +00:00
Eitan Adler
220e4623aa top(1): remove two unneeded headers 2018-06-02 00:02:27 +00:00
Eitan Adler
f6234b51bf top(1): ansify, style(9). and nits
- Prefer using ansi prototypes rather than C prototypes
- Keep type on separate line from name of function
- Try to keep things const where possible. This will help get to WARNS=6
- switch to "bool" where it makes sense
2018-06-02 00:02:15 +00:00
Eitan Adler
937499dcb1 top(1): Display of TID when using 'H' flag
Some users prefer seeing the TID when viewing individual threads. This
makes sense as the PID will be the same for multiple entries. An attempt
was made to include both, but there is insufficient room. As such, using
the TID.

While here, rename the header variables to be more understandable.

Discussed with:	mmacy
Reported on:	2009-10-07
2018-06-01 05:51:40 +00:00
Eitan Adler
dbcdf411a1 top(1): increase size of 'status' buffer
This corrects a warning issues by gcc9:
/srv/src/freebsd/head/usr.bin/top/machine.c:988:22: warning: '%5zu'
directive writing between 5 and 20 bytes into a
 region of size 15 [-Wformat-overflow=]
     sprintf(status, "?%5zu", state);
2018-05-22 07:56:58 +00:00
Eitan Adler
bc875b45c5 top(1): unbreak build with gcc7; fix varargs
- use correct function for varargs argument
- allow build to complete with gcc7 at current WARNS

Reported by:	jhibbits, ian
2018-05-22 02:13:04 +00:00
Eitan Adler
6ffc72df9d top(1): fix build
Remove 'top.local.hs'. This was not noticed since
/srv/obj/fbsd/srv/src/freebsd/svn/head/amd64.amd64/usr.bin/top/top.local.h
existed locally on my machine despite "make clean". Only fully removing
the objdir allowed me to observe the error directly.

Pointyhat to:	me
2018-05-21 09:43:50 +00:00
Eitan Adler
3c9ec0a580 top(1): clean up some "const" related warnings
This leaves at WARNS=6:
35 warnings in top.c
88 warnings in machine.c

all of which are either "incompatible-pointer-types-discards-qualifiers"
or "cast-qual"
2018-05-21 09:32:52 +00:00
Eitan Adler
1b7645c629 top(1): modernize a bit; reduce warnings
- Replace caddr_t with "void *". This reduces
the number of warnings at WARNS=6
- use "static" where possible
- sprinkle const where possible

This leaves at WARNS=6:
35 warnings in top.c
88 warnings in machine.c
7 warnings in commands.c

all of which are either "incompatible-pointer-types-discards-qualifiers"
or "cast-qual"
2018-05-21 09:25:21 +00:00
Eitan Adler
dfa5eb70ae Add missing va_end
Reported by:	andrew
2018-05-21 09:21:42 +00:00
Eitan Adler
00157b4c04 Revert r333969 which contained one too many changes 2018-05-21 09:20:26 +00:00
Eitan Adler
bfb79c2ccc top(1): modernize a bit; reduce warnings
- Replace caddr_t with "void *". This reduces
the number of warnings at WARNS=6
- use "static" where possible
- sprinkle const where possible

This leaves at WARNS=6:
35 warnings in top.c
72 warnings in machine.c
5 warnings in commands.c

all of which are either "incompatible-pointer-types-discards-qualifiers"
or "cast-qual"
2018-05-21 09:18:01 +00:00
Eitan Adler
9aeb8f9999 top(1): add myself as a MAINTAIENR
also fix some nits
2018-05-21 05:00:19 +00:00
Eitan Adler
b3b6732412 top(1): remove prime.c
This file was not connected to the build, and is better served by
primes(6) anyways.
2018-05-21 04:51:43 +00:00
Eitan Adler
ad8ffc3fc2 top(1): fix MIPS
I missed where the parentheses were.

Reported by:	imp
2018-05-21 04:47:13 +00:00
Eitan Adler
5ef89dbfa7 top(1): further unconditionally assume we're on FreeBSD 2018-05-21 04:40:20 +00:00
Eitan Adler
419fab3b14 top(1): clean up in prep for const poisoning
- sprinkle "const" in a few obvious places
- remove "(void)" in front of lack-of-error-checked functions
2018-05-21 04:32:14 +00:00
Eitan Adler
47ffa267d7 top(1): further unconditionally assume we're on FreeBSD 2018-05-21 04:02:45 +00:00
Eitan Adler
1d6a4ba350 top(1): build with WARNS=3
This fixes everything but
-Wincompatible-pointer-types-discards-qualifiers
2018-05-21 03:58:15 +00:00
Eitan Adler
a5ca08ed94 top(1): fix several more warnings 2018-05-21 03:36:16 +00:00
Eitan Adler
986a5bafb1 top(1): fix build on arches where size_t != ull 2018-05-21 01:39:26 +00:00
Eitan Adler
fcfaa4734c top(1): pull function declarations and externs into headers 2018-05-21 01:16:26 +00:00
Eitan Adler
4e33a6b507 top(1): fix "variable without declaration" warning
This is only shown at WARNS=6, but since we don't yet build at WARNS=2
its hidden.
2018-05-21 01:05:32 +00:00
Eitan Adler
666cf87393 top(1): clean much of WARNS=3 issues
There is still one glaring issue: new_message is not a protoype, but
can't be trivially converted since it uses K&R style var-args.
2018-05-21 00:53:42 +00:00
Eitan Adler
4901ca088d top(1): build with WARN=2 2018-05-21 00:32:48 +00:00
Eitan Adler
2877df8d84 top(1): add getrusage to SEE also
This documents the various columns that top might support.

PR:		199637
Submitted by:	vermaden@interia.pl
2018-05-21 00:20:32 +00:00
Eitan Adler
878441444b top(1): Remove now-unused variable 2018-05-20 23:39:08 +00:00
Eitan Adler
668af25d2e top(1): pull configuration directly into header files
This sets configuration variables directly in the various header files,
avoiding the need to have special logic in our Makefile to build the
header.
2018-05-20 23:37:30 +00:00
Eitan Adler
4b9ca404c5 top(1): set max username length based on system constant
This changes previous behavior of calculating it at startup based on
the current max username length.

This is done because:
- it is in theory possible for the max length to change at run-time
  (e.g., a new user is added after top starts running)
- on machines with many users this delays startup significantly

PR:		20799
PR:		89762
Reported by:	ob@e-Gitt.NET
Reported by:	wkwu@Kavalan.csie.NCTU.edu.tw
Reported on:	2000-08-23 and 2005-11-30
2018-05-20 23:19:09 +00:00
Eitan Adler
f11066efb1 top(1): unconditionally assume we are on FreeBSD (more unifdef)
Now that we're our own upstream, remove useless ifdefs.
2018-05-20 18:11:58 +00:00
Eitan Adler
cebbed43bb Retry revert
I had a local modification before my revert. Try reverting one more time.
2018-05-20 18:03:40 +00:00
Eitan Adler
500cd2d6a1 revert r333928
I had missed a file when testing this, and it does not build. Will try again.
2018-05-20 18:02:40 +00:00
Eitan Adler
d408525046 top(1): Make lack of "percent" information explicit
When count is 1, no delta information can be produced. Make this
explicit.

PR:		195717
Submitted by:	fernape
2018-05-20 17:59:59 +00:00
Eitan Adler
808862b298 top(1): remove 'xs' and 'xh' source files
Now that we're our own upstream these files buy us nothing.
2018-05-20 17:58:22 +00:00
Eitan Adler
b3c88c289c top(1): Quiesce several warnings
This is all warnings at level six (6) that are not
char-subscripts, incompatible-pointer-types,
sign-compare, switch, int-conversion,
missing-variable-declarations, cast-qual, cast-align

Some warnings that are fixed by this commit are:
shadow, strict-prototypes, missing-prototypes, pointer-arith,
unused-parameter, unused-const-variable, and several others
2018-05-20 02:14:27 +00:00
Eitan Adler
98c299e062 top(1): remove use of 'register' keyword
This keyword is meaningless is obscures future diffs that help clear up
warnings in top.
2018-05-20 01:32:27 +00:00
Eitan Adler
b8b7822214 top(1): be constant in a structure
This silences some warnings that are still hidden since the remainder of
top(1) does not build with higher WARNS yet.
2018-05-20 01:30:19 +00:00
Eitan Adler
caee48830b top(1): unconditionally assume we are running on FreeBSD
This allows us to remove a special header and more specifically just the
system headers we want.
2018-05-19 23:19:24 +00:00
Eitan Adler
8a133278b7 top(1): unconditionally provide 'FreeBSD' as a version 2018-05-19 23:04:42 +00:00
Eitan Adler
946e91ab0c top(1): assume that we're building on FreeBSD
This allows us to avoid the ifdefs that we set unconditionally.
2018-05-19 22:59:58 +00:00
Eitan Adler
a4af6c0592 top(1): bump WARNS to 1
Nothing else builds without errors yet, but 1 is better than 0
2018-05-19 22:45:43 +00:00
Eitan Adler
3be6ef0659 top(1): Migrate top to usr.bin
We've been maintaining top(1) for a long time, and the upstream
hasn't existed/been used in similarly as long. Make it clear that we own
top(1)

Tested with 'make universe'. Everything passed except MIPS which failed
for unrelated reasons. Install also tested for amd64.

Reviewed by:		sbruno
No objections:		imp, mmacy
Differential Revision:	https://reviews.freebsd.org/D15387
2018-05-19 22:40:23 +00:00
Bryan Drewery
ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Konstantin Belousov
24e470ef9c Limit top display of total swap size by the max swap size system can
handle.

Keep both pagesize and the new swap_maxpages in the static variables
to save sysctl calls.

Submitted by:	ota@j.email.ne.jp
PR:	223149
MFC after:	2 weeks
2017-10-25 11:44:46 +00:00
Pietro Cerutti
f9995000bc Enhance top(1) to filter on multiple usernames
Reviewed by:	cognet, bapt
Approved by:	cognet
MFC after:	1 week
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D11840
2017-08-07 08:45:08 +00:00
Mark Johnston
8781788d2b Fix top(1) output when zfs.ko is loaded but ZFS is not in use.
Reviewed by:	allanjude
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D11693
2017-07-21 23:53:48 +00:00
Allan Jude
2fcfba285e top: Missing man page update for r319866
MFC after:	3 days
2017-06-12 19:54:42 +00:00
Allan Jude
d9a7232865 top: Change the way the ZFS ARC compression ratio is calculated
Based on feedback from OpenZFS developers Matt Ahrens and George Wilson,
the calculation of the ratio no longer takes in to account overhead.

The old formula could result in reporting a negative compression ratio

This could confuse the user or give a false impression that there would be
an advantage to disabling the compressed ARC feature.

The new formula will more closely match an average of the on-disk
compression ratio, as reported by the ZFS property 'compressratio'

MFC after:	3 days
Sponsored by:	ScaleEngine Inc.
2017-06-12 19:51:57 +00:00
Allan Jude
49dd63a9bd Explain the new fields in top(1) related to ZFS compressed ARC
Reviewed by:	bcr
X-MFC-with:	316314
Differential Revision:	https://reviews.freebsd.org/D10781
2017-05-18 12:55:07 +00:00
Gleb Smirnoff
83c9dea1ba - Remove 'struct vmmeter' from 'struct pcpu', leaving only global vmmeter
in place.  To do per-cpu stats, convert all fields that previously were
  maintained in the vmmeters that sit in pcpus to counter(9).
- Since some vmmeter stats may be touched at very early stages of boot,
  before we have set up UMA and we can do counter_u64_alloc(), provide an
  early counter mechanism:
  o Leave one spare uint64_t in struct pcpu, named pc_early_dummy_counter.
  o Point counter(9) fields of vmmeter to pcpu[0].pc_early_dummy_counter,
    so that at early stages of boot, before counters are allocated we already
    point to a counter that can be safely written to.
  o For sparc64 that required a whole dummy pcpu[MAXCPU] array.

Further related changes:
- Don't include vmmeter.h into pcpu.h.
- vm.stats.vm.v_swappgsout and vm.stats.vm.v_swappgsin changed to 64-bit,
  to match kernel representation.
- struct vmmeter hidden under _KERNEL, and only vmstat(1) is an exclusion.

This is based on benno@'s 4-year old patch:
https://lists.freebsd.org/pipermail/freebsd-arch/2013-July/014471.html

Reviewed by:	kib, gallatin, marius, lidl
Differential Revision:	https://reviews.freebsd.org/D10156
2017-04-17 17:34:47 +00:00
Allan Jude
8554754c7b fix top(1) ZFS compressed ARC support
top(1) read the wrong amount of data from sysctl, uint64_t instead of
boolean_t, resulting in the stats not showing in many cases.

X-MFC-With:	r315435
Sponsored by:	ScaleEngine Inc.
2017-03-31 03:08:07 +00:00
Robert Watson
abc58cc4d9 Provide proper contemporary function prototypes for many of the functions
implemented in top(1), rather than relying on K&R prototypes, which can
cause problems on targets where there are multiple incompatible calling
conventions and the compiler requires argument information to select the
correct one.

(There's a bit more to do here, since it looks like top(1) also sometimes
provides prototypes for various curses functions rather than relying on
the header file...)

Sponsored by:	DARPA, AFRL
MFC after:	1 week
2017-03-26 17:22:44 +00:00
Allan Jude
1dbfa4b530 Add ZFS compressed ARC stats to top(1)
Provides:
amount of compressed data
logical size of compressed data (how much it would have taken uncompressed)
compression ratio (logical size : total ARC size)
Overhead (space consumed for compression headers)

Example output:
ARC: 31G Total, 18G MFU, 9067M MRU, 2236K Anon, 615M Header, 2947M Other
     25G Compressed, 54G Uncompressed, 1.76:1 Ratio, 2265M Overhead

Reviewed by:	jpaetzel, smh, imp, jhb (previous version)
MFC after:	2 week
Relnotes:	yes
Sponsored by:	ScaleEngine Inc.
Differential Revision:	https://reviews.freebsd.org/D9829
2017-03-17 00:46:50 +00:00
Warner Losh
a35f04fba2 Adopt SRCTOP in usr.bin
Prefer ${SRCTOP}/foo over ${.CURDIR}/../../foo and ${SRCTOP}/usr.bin/foo
over ${.CURDIR}/../foo for paths in Makefiles.

Differential Revision:	https://reviews.freebsd.org/D9932
Sponsored by:		Netflix
Silence on:		arch@ (twice)
2017-03-12 18:58:44 +00:00
Enji Cooper
a22656f0b2 Style fixes
- Delete trailing whitespace
- Use nitems(mib) instead of hardcoding the mib length

MFC after:	3 days
2017-01-09 00:29:23 +00:00
Eric van Gyzen
3d32d4a7c9 Export the whole thread name in kinfo_proc
kinfo_proc::ki_tdname is three characters shorter than
thread::td_name.  Add a ki_moretdname field for these three
extra characters.  Add the new field to kinfo_proc32, as well.
Update all in-tree consumers to read the new field and assemble
the full name, except for lldb's HostThreadFreeBSD.cpp, which
I will handle separately.  Bump __FreeBSD_version.

Reviewed by:	kib
MFC after:	1 week
Relnotes:	yes
Sponsored by:	Dell EMC
Differential Revision:	https://reviews.freebsd.org/D8722
2016-12-07 15:04:22 +00:00
Mark Johnston
cc59e3a79b Add the laundry page count to the displays of systat, top, and vmstat.
Reviewed by:	alc, kib
Differential Revision:	https://reviews.freebsd.org/D8467
2016-11-10 19:55:45 +00:00
Dag-Erling Smørgrav
b6924c9309 Add a toggle to display the approximate amount of swap used by each
process.  We don't *quite* pull that number out of our backside, as
the actual number is difficult to determine without modifying the VM
system to report it, but it's still useful to get an idea of what's
going on when a machine unexpectedly starts swapping.

MFC after:	1 week
2016-09-05 08:27:04 +00:00
Marcelo Araujo
cd59e2f343 Use MIN() macro from sys/param.h.
MFC after:	2 weeks.
2016-04-27 02:44:10 +00:00
Bryan Drewery
bd18fd57db DIRDEPS_BUILD: Regenerate without local dependencies.
These are no longer needed after the recent 'beforebuild: depend' changes
and hooking DIRDEPS_BUILD into a subset of FAST_DEPEND which supports
skipping 'make depend'.

Sponsored by:	EMC / Isilon Storage Division
2016-02-24 17:20:11 +00:00
Konstantin Belousov
78b7ef01a8 Rename variable to reflect the condition.
Suggested by:	jhb
Sponsored by:	The FreeBSD Foundation
2016-02-09 18:35:37 +00:00
Konstantin Belousov
db57c70a5b Rename P_KTHREAD struct proc p_flag to P_KPROC.
I left as is an apparent bug in ntoskrnl_var.h:AT_PASSIVE_LEVEL()
definition.

Suggested by:	jhb
Sponsored by:	The FreeBSD Foundation
2016-02-09 16:30:16 +00:00
Bryan Drewery
cf990407e1 Update dependencies after r291406 added libelf to libkvm.
Unfortunately filemon/meta mode tracks all indirect dependencies here
since ld(1) is reading libelf when linking in libkvm.  Churn would be
reduced if this was able to be limited to direct dependencies.

Sponsored by:	EMC / Isilon Storage Division
2015-12-01 05:18:48 +00:00
Simon J. Gerraty
2ef6d5a7b9 new depends 2015-06-16 23:37:19 +00:00
Simon J. Gerraty
ccfb965433 Add META_MODE support.
Off by default, build behaves normally.
WITH_META_MODE we get auto objdir creation, the ability to
start build from anywhere in the tree.

Still need to add real targets under targets/ to build packages.

Differential Revision:       D2796
Reviewed by: brooks imp
2015-06-13 19:20:56 +00:00
Simon J. Gerraty
44d314f704 dirdeps.mk now sets DEP_RELDIR 2015-06-08 23:35:17 +00:00
Marcel Moolenaar
529b5c137e Move contrib/top/top.X to contrib/top/top.xs and move
contrib/top/top.local.H to contrib/top/top.local.hs.
This fixes a build breakage when src is on a case-
insensitive file system -- we never properly create
top.x nor top.local.h. Change the makefile accordingly.

MFC after:	3 days
2015-06-08 19:45:24 +00:00
Simon J. Gerraty
98e0ffaefb Merge sync of head 2015-05-27 01:19:58 +00:00
Kevin Lo
cf7f8a9de8 Print size_t's with %zu rather than "%zd.
Reviewed by:	bde
2015-03-26 09:13:16 +00:00
Baptiste Daroussin
3e11bd9e2a Convert to usr.bin/ to LIBADD
Reduce overlinking
2014-11-25 14:29:10 +00:00
Simon J. Gerraty
9268022b74 Merge from head@274682 2014-11-19 01:07:58 +00:00
Jung-uk Kim
b666b03241 Replace a magic number with the proper definition. This change actually
fixes broken state field after r273266, i.e., "CPU-1" was displayed in place
of "RUN".
2014-10-29 19:21:19 +00:00
Simon J. Gerraty
ee7b0571c2 Merge head from 7/28 2014-08-19 06:50:54 +00:00
John Baldwin
e876f6d052 Cap the percent CPU of individual threads at 100% to fix some of the
more obvious imprecision in the previous top changes.

Specifically, top uses a delta of clock_gettime() calls right after
invoking the kern.proc sysctl to fetch the process/thread list to
compute the time delta between the fetches.  However, the kern.proc
sysctl handler does not run in constant time.  It can spin on locks,
be preempted by an interrupt handler, etc.  As a result, the time
between the gathering of stats for individual processes or threads
between subsequent kern.proc handlers can vary.  If a "slow" kern.proc
run is followed by a "fast" kern.proc run, then the threads/processes
at the start of the "slow" run will have a longer time delta than the
threads/processes at the end.  If the clock_gettime() time delta is
not itself skewed by preemption, then the delta may be too short for
a given thread/process resulting in a higher percent CPU than actual.
However, there is no good way to calculate the exact amount of overage,
nor to know which threads to subtract the overage from.  Instead, just
punt and fix the definitely-wrong case of an individual thread having
more than 100% CPU.

Discussed with:	zonk
2014-06-20 19:54:23 +00:00
John Baldwin
a90539544c Rework the notion of CPU used in top. In particular, for subsequent
displays after a pause, use the difference in runtime divided by the
length of the pause as the percentage of CPU used instead of the value
calculated by the kernel.  In addition, when determing if a process or
thread is idle or not, treat any process or thread that has used any
runtime or performed any context switches during the interval as busy.

Note that the percent CPU is calculated as a double and stored in an
array to avoid recalculating the value multiple times in the comparison
method used to sort processes in the CPU display.

Tested by:	Jamie Landeg-Jones <jamie@dyslexicfish.net>
Reviewed by:	emaste (earlier version)
MFC after:	1 week
2014-05-30 21:18:53 +00:00
John Baldwin
5648de3b31 Fix a couple of size_t != int warnings. 2014-05-27 20:22:36 +00:00
Simon J. Gerraty
fae50821ae Updated dependencies 2014-05-16 14:09:51 +00:00
Simon J. Gerraty
76b28ad6ab Updated dependencies 2014-05-10 05:16:28 +00:00
Simon J. Gerraty
cc3f4b9965 Merge from head 2014-05-08 23:54:15 +00:00
Bryan Drewery
069f49cfe8 Fix width/alignment of JID column. Make it support up to the maximum
7-wide JIDs. On a system using jails for common tasks the JID can
quickly increase.

MFC after:	2 weeks
2014-05-03 15:03:47 +00:00
Bryan Drewery
1b60f97272 Add -J command/flag to filter by jail name/jid. This will automatically
display the JID as well (the -j command/flag).

  0 displays host.
  + displays all.

MFC after:	2 weeks
Relnotes:	yes
2014-05-02 23:30:39 +00:00
Simon J. Gerraty
d1d0158641 Merge from head 2013-09-05 20:18:59 +00:00
John Baldwin
49e3bde165 Bump the CPU/WCPU column width by one so that it fits values from 100% up
to 999.99% CPU.  It still won't be aligned if you have a multithreaded
process using more than 1000% CPU (e.g. idle process on an idle 12-way
system), but 100% is a common case.

Submitted by:	Jeremy Chadwick (partial)
MFC after:	1 week
2013-06-11 19:05:29 +00:00
Simon J. Gerraty
69e6d7b75e sync from head 2013-04-12 20:48:55 +00:00
Simon J. Gerraty
7cf3a1c6b2 Updated dependencies 2013-03-11 17:21:52 +00:00
John Baldwin
ee66c8b94e Fix the 'C' field for a running thread to match the behavior described
in the manpage by having it display the current CPU (ki_oncpu) rather
than the previously used CPU (ki_lastcpu).  ki_lastcpu is still used for
all other thread states.

Reported by:	Chris Ross <cross+freebsd@distal.com>
MFC after:	1 week
2013-03-11 16:33:05 +00:00
Simon J. Gerraty
34ce9cc44f Do no assume ${DESTDIR}/usr/include is always valid 2013-02-20 00:13:26 +00:00
Simon J. Gerraty
f5f7c05209 Updated dependencies 2013-02-16 01:23:54 +00:00
David E. O'Brien
d9a447559b Sync with HEAD. 2013-02-08 16:10:16 +00:00
Rui Paulo
78210af90c Use the correct size when allocating the cmdbuf string.
cmdlengthdelta is the size of the header and we were using it to
allocate a buffer to store the command line. This would mean that
the cmdbuf could be too short. In practice this was never noticed unless
you usually run top -a. On a stock FreeBSD system you can see the
problem by running sendmail and then running top -a on a big terminal
window. In practice this doubles to size available to cmdbuf since the
header is around 65-68 bytes.

Reviewed by:	adrian
2012-11-19 08:03:40 +00:00
Rui Paulo
8b800d3af2 Add the PID column to the list of sort keys. 2012-11-11 08:16:33 +00:00
Simon J. Gerraty
23090366f7 Sync from head 2012-11-04 02:52:03 +00:00
John Baldwin
b49af68ca0 Correct the order of the MFU and MRU labels. I had reversed them.
Submitted by:	Nikolay Denev  ndenev gmail
Pointy hat to:	jhb
MFC after:	3 days
2012-10-19 12:28:26 +00:00
Marcel Moolenaar
7750ad47a9 Sync FreeBSD's bmake branch with Juniper's internal bmake branch.
Requested by: Simon Gerraty <sjg@juniper.net>
2012-08-22 19:25:57 +00:00
John Baldwin
54900c9b1f Fix two layout bugs in the previous change:
- Properly increase y_mem when per-CPU stats are enabled.
- Update y_arc for per-CPU stats being enabled/disabled.

MFC after:	3 days
2012-07-02 20:08:11 +00:00
John Baldwin
2e52fb92ff Add a new line to top that provides a brief summary of the ZFS ARC memory
usage on hosts using ZFS.  The new line displays the total amount of RAM
used by the ARC along with the size of MFU, MRU, anonymous (in flight),
headers, and other (miscellaneous) sub-categories.  The line is not
displayed on systems that are not using ZFS.

Reviewed by:	avg, fs@
MFC after:	3 days
2012-06-27 18:08:48 +00:00
John Baldwin
17cf6fc527 Clarify that the cached file data pages included in the "Wired" count
in top are the BIO-level cached data (i.e. "Buf"), since the previous
phrase was a bit ambiguous with the "Cache" count.

MFC after:	3 days
2012-06-27 12:30:56 +00:00
Konstantin Belousov
bf313207fc Fix string buffer overflow when preparing the line of output.
PR:	bin/161739
Submitted by:	Jeremy Chadwick <freebsd jdc parodius com>
MFC after:	1 week
2012-04-18 10:23:42 +00:00
Eitan Adler
50d675f7a9 Remove trailing whitespace per mdoc lint warning
Disussed with:	gavin
No objection from:	doc
Approved by:	joel
MFC after:	3 days
2012-03-29 05:02:12 +00:00
Ulrich Spörlein
487ac9ac21 Spelling fixes for usr.bin/ 2011-12-30 11:02:40 +00:00
John Baldwin
fcc3d62fa5 Rework the dynamic per-CPU stats code a bit. Always set 'statics->ncpus'
to the maximum number of CPUs to ensure that lcpustates[] array is always
allocated to the maximum size.  Previously, if top was started without
per-CPU stats it would allocate a smaller lcpustates[] array.  When
per-CPU stats were then enabled, it would overflow the array and trash
the cpustates_columns[] array causing the CPU stats to be printed in the
wrong locations.

Approved by:	re (kib)
MFC after:	1 week
2011-07-18 21:15:47 +00:00
Bjoern A. Zeeb
c618a5222e Constantly print the command name and if set include the thread
name in per-thread mode.

Discussed with:	jhb
Obtained from:	Ed Maste at Sandvine Incorporated
Sponsored by:	Sandvine Incorporated
MFC after:	1 week
Approved by:	re (kib)
2011-07-18 20:57:43 +00:00
Bjoern A. Zeeb
925af54487 Rename ki_ocomm to ki_tdname and OCOMMLEN to TDNAMLEN.
Provide backward compatibility defines under BURN_BRIDGES.

Suggested by:	jhb
Reviewed by:	emaste
Sponsored by:	Sandvine Incorporated
Approved by:	re (kib)
2011-07-18 20:06:15 +00:00
John Baldwin
2417d97ebb - Export each thread's individual resource usage in in struct kinfo_proc's
ki_rusage member when KERN_PROC_INC_THREAD is passed to one of the
  process sysctls.
- Correctly account for the current thread's cputime in the thread when
  doing the runtime fixup in calcru().
- Use TIDs as the key to lookup the previous thread to compute IO stat
  deltas in IO mode in top when thread display is enabled.

Reviewed by:	kib
Approved by:	re (kib)
2011-07-18 17:33:08 +00:00
John Baldwin
b225f36e26 Revert 130163 and let top use KERN_PROC_PROC when individual threads are
not displayed.  The KERN_PROC_PROC sysctl was fixed in 188764.
2011-07-15 17:23:45 +00:00
Bjoern A. Zeeb
f4dad666e3 Fix indentation.
Obtained from:	Ed Maste at Sandvine Incorporated
Sponsored by:	Sandvine Incorporated
MFC after:	3 days
2011-07-14 13:47:42 +00:00
John Baldwin
51f202e9ed Allow per-CPU statistics to be toggled at runtime via the 'P' key.
While here, make -P a toggle similar to other options such as -I.

Reviewed by:	arundel
MFC after:	1 week
2011-07-11 16:48:52 +00:00
John Baldwin
034b7b80b2 Always skip the kernel idle process if requested, it is not specific to
the 'CPU' mode.

PR:		bin/158677
Reported by:	arundel
MFC after:	3 days
2011-07-07 13:37:46 +00:00
John Baldwin
35b23f5d86 - Document the -H option and 'H' key alongside other options and keys
rather than at the bottom of the manpage.
- Remove an obsolete comment about SWAIT being a stale state.  It was
  resurrected for a different purpose in FreeBSD 5 to mark idle ithreads.
- Add a comment documenting that the SLEEP and LOCK states typically
  display the name of the event being waited on with lock names being
  prefixed with an asterisk and sleep event names not having a prefix.

MFC after:	1 week
2011-05-31 15:41:10 +00:00
John Baldwin
c9385548e7 Add a new option to toggle the display of the system idle process (per-CPU
idle threads).  The process is displayed by default (subject to whether or
not system processes are displayed) to preserve existing behavior.  The
system idle process can be hidden via the '-z' command line argument or the
'z' key while top is running.  When it is hidden, top more closely matches
the behavior of FreeBSD <= 4.x where idle time was not accounted to any
process.

MFC after:	2 weeks
2011-05-31 15:11:23 +00:00
Sergey Kandaurov
d9b2153b4e Add missing header file.
MFC after:	1 week
2011-05-20 17:03:23 +00:00
Giorgos Keramidas
001dcb9133 Touch up the sample memory usage numbers a bit, to avoid wrapping
on terminal boundary.  While here add definition for 'G' and fix
the indentation of 'K' units.

Submitted by:	plunket
PR:		docs/153614
MFC after:	3 days
2011-01-23 11:08:39 +00:00
Rebecca Cran
4784a27247 Memory stats are reported in bytes, not pages.
PR:	docs/151283
Submitted by:	Bas Smeelen <b.smeelen at ose.nl>
MFC after: 3 days
2010-11-13 11:43:20 +00:00
Ed Schouten
b7946da96b Build usr.bin/ with WARNS=6 by default.
Also add some missing $FreeBSD$ to keep svn happy.
2010-01-02 10:27:05 +00:00
John Baldwin
a0b9e7e332 Update top and systat for vfs.bufcache now being a long rather than an int. 2009-03-10 15:25:19 +00:00
Rui Paulo
491c34ec7e Right align the CPU column header. 2008-12-26 11:11:30 +00:00
John Baldwin
b2ce972537 Make the CPU column in top always be 2 characters and print in decimal
rather than hex.

Requested by:	rwatson
2008-10-01 22:01:07 +00:00
Stephane E. Potvin
c975a48dee Display the sum of the runtime of all the threads in a process when it's
multithreaded instead of picking the time of the first thread found.

Reviewed by:	jhb
Approved by:	kan (mentor)
MFC after:	1 month
2008-09-12 17:54:50 +00:00
Ruslan Ermilov
d3bf3b9a7a system_info.cpustates isn't sparse, so a bitmask of available CPU states
is redundant (I think it's a leftover from an older implementation).
2008-04-11 11:39:26 +00:00
Ruslan Ermilov
3aaa083285 Allocate enough memory for pcpu_cp_time[] to stop sysctl() from
writing outside of array bounds.  This fully fixes -P display on
i386, where kern.cp_times prints zeroes for non-existing CPUs.
2008-04-11 11:34:09 +00:00
Ruslan Ermilov
f89db4357e Fix "top -P" (&' mistyped as &&' and a botched logic).
The bug was unnoticed on non-i386 because mp_maxid is
initialized differently, kern.cp_times doesn't print
zeroes for non-existing CPUs, so no "writing outside of
array bounds" happens.

MFC after:	3 days
2008-04-10 16:17:54 +00:00
Xin LI
2f487fe4e4 Use calloc() when requesting zero'ed memory allocation rather than rolling
our own.
2008-01-29 00:06:44 +00:00
Peter Wemm
031175705e Add a -P flag to display per-cpu cpu usage stats. 2008-01-18 01:43:14 +00:00
David E. O'Brien
dbb2956620 Improve -u (limit uid lookups) behavior.
Submitted by:	David Frascone <dave@frascone.com>
PR:		119490
2008-01-09 18:06:24 +00:00
Julian Elischer
7ab24ea3b9 Introduce a way to make pure kernal threads.
kthread_add() takes the same parameters as the old kthread_create()
plus a pointer to a process structure, and adds a kernel thread
to that process.

kproc_kthread_add() takes the parameters for kthread_add,
plus a process name and a pointer to a pointer to a process instead of just
a pointer, and if the proc * is NULL, it creates the process to the
specifications required, before adding the thread to it.

All other old kthread_xxx() calls return, but act on (struct thread *)
instead of (struct proc *). One reason to change the name is so that
any old kernel modules that are lying around and expect kthread_create()
to make a process will not just accidentally link.

fix top to show  kernel threads by their thread name in -SH mode
add a tdnam formatting option to ps to show thread names.

make all idle threads actual kthreads and put them into their own idled process.
make all interrupt threads kthreads and put them in an interd process
(mainly for aesthetic and accounting reasons)
rename proc 0 to be 'kernel' and it's swapper thread is now 'swapper'

man page fixes to follow.
2007-10-26 08:00:41 +00:00
Jeff Roberson
b61ce5b0e6 - Move all of the PS_ flags into either p_flag or td_flags.
- p_sflag was mostly protected by PROC_LOCK rather than the PROC_SLOCK or
   previously the sched_lock.  These bugs have existed for some time.
 - Allow swapout to try each thread in a process individually and then
   swapin the whole process if any of these fail.  This allows us to move
   most scheduler related swap flags into td_flags.
 - Keep ki_sflag for backwards compat but change all in source tools to
   use the new and more correct location of P_INMEM.

Reported by:	pho
Reviewed by:	attilio, kib
Approved by:	re (kensmith)
2007-09-17 05:31:39 +00:00
Ruslan Ermilov
06351b59c6 Inactive pages don't have to be dirty plus improve description of
the cache queue.

Submitted by:	alc
Approved by:	re (kensmith)
2007-09-02 10:29:16 +00:00
Ruslan Ermilov
d71e591b49 Fix the description of the "Cache" memory and clarify the
description of the "Inact" memory.  (They count pages in
the cache/inactive page queues, respectively.)

Approved by:	re (kensmith)
2007-09-01 05:52:39 +00:00
Bruce Evans
e19249f7a7 Third stage of unbreaking printing of pseudo-nice values (realtime
priorities, etc.) in the NICE field:

Use a combination of pri_native and pri_user instead of pri_level to
guess the original realtime priority.  Using pri_level here has been
wrong since 2001/02/12.  Using only pri_native here would be correct
if the kernel actually initialized it reasonably.  (The kernel exports
its raw td_base_priority as pri_native, but userland mostly wants a
refined base priority).  Give up on waiting pri_native to work correctly
and only use it when there is nothing better (for kthreads).

This should reduce printing of bizarre pseudo-nice values.  Bizarre
values are still printed if we observe a transient borrowed priority
for a kthread (transient borrowing is the main thing that makes the
raw td_base_priority almost useless in userland), or if there is a
kernel bug.  One current kernel bug involves the kernel idprio thread
pagezero permanently changing its priority from PRI_MAX_IDLE (255) to
PUSER (160).  Then the bizarre value "ki-6" is printed instead of
"ki31".  Here "-6" is PRI_MIN_IDLE - PUSER = -64 truncated to 2
characters.  We are observing a transient borrowed priority that has
become permanent due to a bug.

ps/print.c:priorityr() needs similar changes (including ones in stage 2
here).
2007-06-15 12:03:07 +00:00
Rong-En Fan
6000ced11b - Add a new 'j' switch and runtime option to toggle display jail id for
each process.
- While I'm here, keep help message sorted by keys

PR:		98489, 98975
Submitted by:	clsung
Approved by:	delphij (mentor)
MFC after:	2 weeks
2007-04-17 03:12:39 +00:00
Stanislav Sedov
faac60c8fc - Add new 'a' switch and runtime option that allows 'top' to display process
titles extracted from argv vector instead of the real executable names.
  This is useful when you want to watch applications that set their status
  information via setproctitle(3).

Approved by:	alfred
MFC after:	2 weeks
2007-04-14 10:16:52 +00:00
Giorgos Keramidas
d2d6d8d537 The sigconv.awk script generates a sigdesc.h header file, which
contains a sigdec[] vector of structures, but the generated output is
missing braces around the initializer of each struct, which
triggers warnings in WARNS=3:

src/usr.bin/top/sigdesc.h:10: warning: missing braces around initializer
src/usr.bin/top/sigdesc.h:10: warning: (near initialization for `sigdesc[0]')

  * Fix the sigconv.awk script to generate a header with initializers
    which look better.

  * Add rules to usr.bin/top/Makefile that rebuilds a new sigconv.h
    header which matches the correct signal set from the build-time
    version of `${DESTDIR}/usr/include/signal.h' (so sigconv.h doesn't
    get stale once changes are made to the header).

  * Remove the old sigconv.h header, now that it is autoupdated at
    build time.

  * Various Makefile style fixes (the committed Makefile was kindly
    submitted by Ruslan):

    - Reorder .PATH, PROG, SRCS and CFLAGS to match style.Makefile(5)
    - Split off the generated sources (sigdesc.h top.local.h) in an
      SRCS+= line of their own.
    - Add entries to CLEANFILES near the rules that generate the
      respective files.
    - Move the explicit rule which builds top.1 after the implicit
      rules which generate its dependencies.

Reviewed by:	ru, bde
Submitted by:	ru (Makefile)
MFC after:	2 weeks
2006-12-01 07:01:19 +00:00
Bruce Evans
8dbbff5b81 Second stage of unbreaking thr formatting of the NICE field: decode the
priority class and use this to:

- print "-" instead of a garbage value for ithreads.  Print "-" instead
  of the unused nice value for kthreads which are (mis)classified as
  PRI_TIMESHARE.  For such threads, the nice value can be set to nonzero
  by root, but it is never used (at least by the 4bsd scheduler).  For
  ithreads, we didn't even print the unused value.

- print "i<priority>" and "r<priority>" instead of a biased "<priority>"
  for idletime and realtime threads,  Here <priority> is the priority
  parameter to idprio/rtprio(1).  Just add the prefix and remove the
  bias for now.  <priority> has been stored indirectly in the kernel
  since 2001/02/12, and even the kernel cannot recover the original
  value in all cases.  Here we need to handle more cases than pri_to_rtp(),
  but actually handle fewer cases, and end up printing garbage after
  a thread changes its current priority while in the kernel.

- for idletime and realtime threads, if they are kthreads then add a prefix
  of "k" to the previous string.

- for idletime and realtime threads, if they in the FIFO scheduling class
  then add a suffix of "F" to the previous string (if it fits; the other
  parts of the string are sure to fit unless <priority> is garbage).
2006-11-07 10:03:10 +00:00