Commit Graph

358 Commits

Author SHA1 Message Date
Eitan Adler
da446b10ed top(1): permit sending signal with any case 2018-06-10 06:21:45 +00:00
Eitan Adler
468910cd7a top(1): permit sub-second delay times
This removes the getuid check for delay==0. It didn't prevent users from
writing similar programs in the general case. In theory, if top(1) is
among one of the few restricted programs you're allowed to run, it may
have helped a little, but there are better ways of handling that case.
2018-06-10 00:02:56 +00:00
Eitan Adler
6e0632db3d top(1): correctly reset per-cpu counters
I had changed this from a for loop to a memset during an earlier
cleanup. This change was incorrect so revert it.

While here, clean up

Reported by:	flo
2018-06-09 23:24:08 +00:00
Eitan Adler
ef436ca6a6 top(1): handle specific pids better
When told to watch a specific pid, don't filter idle, system, or self
processes. The summary at the top will still flip correctly though.
2018-06-09 23:08:02 +00:00
Eitan Adler
d73bfd43b2 top(1): implement additional missing long options 2018-06-09 22:30:10 +00:00
Eitan Adler
9d6cce02a7 top(1): initial pass to freebsdize the man page
The previous man page used many conventions not typical in FreeBSD.
Since we've forked top completely, convert the man page too.
2018-06-09 21:40:33 +00:00
Eitan Adler
c388909b8d top(1): Implement long options
This also documents some reserved or differing options from top's
original upstream.
2018-06-09 21:40:24 +00:00
Eitan Adler
dd0bdd6b45 top(1): allow starting with -T flag 2018-06-09 20:06:06 +00:00
Eitan Adler
e3225dcf12 top(1): correct header, align it.
THR is always 6 digits or longer. Now that the PID/THR change is
separated, use correct headers.

PR:		228823
Reported by:	Trond.Endrestol@ximalas.info
2018-06-09 02:47:02 +00:00
Eitan Adler
4e08f2f53c top(1): actually make change for tid vs pid 2018-06-09 02:18:15 +00:00
Eitan Adler
fc36f5a7cb top(1): use a different command to toggle tid vs pid
- By popular demand, implement a different switch ("T") for toggling
between thread id and process id.
- Add an assert that the size of command chars is as expected.
- Also clean up some messiness I found when implementing this.
- Further document the new flag.

Requested by:	flo, ronald-lists@klop.ws, bapt
PR:		139389 (for the record)
X-MFC-With:	r334474
2018-06-09 02:14:33 +00:00
Eitan Adler
4fb80c7008 top(1): remove some unneeded indirection 2018-06-08 02:03:51 +00:00
Eitan Adler
d408c8f742 top(1): fix several style & const related issues
- use parens for return
- put function names on newline
- sprinkle const where possible
2018-06-08 01:55:47 +00:00
Eitan Adler
59c8d5dc27 top(1): fix err again
I am amazed at my ability to get a one-line error reporting line wrong
thrice.
2018-06-06 07:13:27 +00:00
Eitan Adler
bca1b45bb1 top(1): make error message happy
We don't use a "size" variable, so just don't report it.

Reported by:	bapt
2018-06-06 06:42:12 +00:00
Eitan Adler
cda7a5d5ed top(1): some nitpicks
- prefer fully spelled names to "u_long"
- fix speeling
2018-06-04 05:27:00 +00:00
Eitan Adler
8d0d26767b top(1): include what you use
- Change headers to more closely match what we use
- use more standard functions instead of bzero, bcmp, bcopy
- Add myself to authors.

Tested with: base clang (amd64), gcc 9 (amd64), base clang (i386), base
gcc (mips)
2018-06-04 04:59:32 +00:00
Eitan Adler
5dc98aeeaa top(1): Prefer memcpy over bcopy 2018-06-04 04:59:24 +00:00
Eitan Adler
a9a99372d9 top(1): Use strsep instead of homegrown alternative
This replaces some complex, and not quite correct logic, with a more
common strsep pattern.

Reviewed by:	mmacy (older version)
2018-06-04 03:16:24 +00:00
Eitan Adler
eae589f1ce top(1): another pass of cleanup
- avoid the need to call a function to get size of known array. I'll
likely re-arrange some of the indirect in a later to avoid the magic
constants.
- use correct type
- add const
- replace caddr_t with void*. This corrects an alignment warning.
- remove duplicated include from immediately prior commit

Under base clang we're now down to:
- 3 warning in top.c, 1 warning in mahcine.c,  4 warning in display.c,
- 1 warning in utils.c

Tested with base clang, gcc7, gcc9, base gcc (mips)
2018-06-03 23:40:54 +00:00
Eitan Adler
9f8096e339 top(1): top warnings and cleanup
- Add const where helpful
- add missing 'static' for file-local functions
- use nitems where possible
- convert manual abort() to assert
- use strndup instead of homegrown version

Tested with clang, gcc7, and gcc9
2018-06-03 22:42:54 +00:00
Eitan Adler
a2cda47ac3 top(1): restore size for kern.cp_times
Restore last minute change that broke top(1).
2018-06-03 13:41:23 +00:00
Eitan Adler
c5484668f1 top(1): Only use NO_WERROR for base gcc
This is what was intended. If statements are hard.
2018-06-03 06:02:31 +00:00
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