Commit Graph

136 Commits

Author SHA1 Message Date
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
Stefan Eßer
d1b76f3f6e Fix display of idle processes, which had been broken since rev. 1.56 of
machine.c. The traditional condition was (pctcpu > 0 || SRUN), but the
negation of the condition logic (from select to skip) made this come
out as (pctcpu > 0 && SRUN), leading to a very erratic display, except
for purely CPU bound processes.

This has been discussed in the mail lists some time ago and I have used
top with this patch on my systems for more than a year without problems
(just forgot to commit it earlier, since my systems were all fixed ...).
2006-06-11 19:18:39 +00:00
Bruce Evans
de916c8b74 Move the formatting of the NICE column to a new function format_nice()
so that it can be more easily unbroken and extended.

Try to use `static', `const' (as appropriate), prototypes declared together,
and parameter names in prototypes for all private functions, not just the
new one.
2006-05-04 03:56:31 +00:00
Bruce Evans
789e38771b Fixed some style bugs (mainly missing and wrong splitting of long lines). 2006-05-04 03:00:13 +00:00
Giorgos Keramidas
58ea49c98e (1) Revert unnecessary indentation changes I committed as part of the
last version and (2) remove a disabled debugging fprintf() that I
accidentally committed here.

Noticed by:	simon (2)
2005-05-18 13:42:51 +00:00
Giorgos Keramidas
bbf750fbff Merge the CPU and WCPU columns in a single %6.2f column, add a new 'C'
command that toggles between the two and update the ORDER_PCTCPU()
macro to sort correctly by the visible "cpu" value.

This saves 6 more columns in 80-column terminals, making things a lot
better for the COMMAND column.

Tested on:	i386, sparc64 (panther), amd64 (sledge)
Approved by:	davidxu (in principle)
2005-05-18 13:30:08 +00:00
David E. O'Brien
c413702af3 Hardcode username to 8 characters. This makes top(1) output sane when
there are users on the system (even if not running a single process)
with a login > 8 chars.
I'm not all that happy limiting the username width like this, but it
restores sanity to top(1) output.

Discussed with:	keramida
2005-05-16 18:17:38 +00:00
Giorgos Keramidas
5970af4cd4 Reduce the width of the THR column to 4 characters, to avoid wrap-around
of lines in SMP machines (which are wider), until we have a better way
of handling window sizes & columns in top.

Caught by:	ache, Andre Guibert de Bruet <andy@siliconlandmark.com>
Point hat:	keramida
2005-04-16 15:43:38 +00:00
Giorgos Keramidas
32efd26355 - Add a THR column to the process listing, that shows the number of
threads a process has.  The THR column is disabled and disappears
  when 'H' is hit, because then every thread gets its own output line.
- Allow sorting processes by "threads".

Approved by:	davidxu
Inspired by:	Jiawei Ye <leafy7382@gmail.com>
2005-04-14 15:02:03 +00:00
Stefan Farfeleder
426494536e Include <string.h> and <strings.h> for various functions. 2005-04-04 21:19:48 +00:00
Alfred Perlstein
5d320d4b95 This patch merges the sort fields for both pages, so you can (for
example) view io stats while sorting by process size.  Also adds
voluntary and involuntary context-switch stats to the io page because
there was lots of room.

Submitted by: Dan Nelson dnelson at allantgroup.com
2004-08-16 07:51:22 +00:00
Alfred Perlstein
dcd6f4bd48 Comment some of the 'io' functions. 2004-08-01 09:19:41 +00:00
Dag-Erling Smørgrav
9b30d69710 Adjust the show_self code (the test got inadvertantly reversed a couple of
revisions ago)

Submitted by:	Alex Vasylenko <lxv@omut.org>
2004-07-12 08:22:32 +00:00
Alfred Perlstein
98c151d6d9 Cache a pointer to the old proc (as well as negative cache) to make
computing the io statistics over and over not as expensive.
This is a bit of a cop out, as I should just allocate a struct with
the computed values, but this will do for now.
2004-07-12 04:55:07 +00:00
Giorgos Keramidas
26b2243ae7 Build upon the nice work of Alfred and add sorting capabilities to
the -m "io" mode of top.

Approved by:	alfred
2004-07-08 16:45:55 +00:00
Dag-Erling Smørgrav
e38035a512 Additional preemptive unsigned -> signed casts. 2004-07-05 14:55:58 +00:00
Dag-Erling Smørgrav
f92a11552e ki_pctcpu is unsigned, so we cast to long before subtracting. 2004-07-05 14:52:06 +00:00
Dag-Erling Smørgrav
4946a00b0b Unhealthy amount of manual code cleanup. Some long lines still remain. 2004-07-05 14:45:57 +00:00
Dag-Erling Smørgrav
ea9e70bf68 Apply consistent indentation. Long lines will be fixed in a separate
commit.
2004-07-05 13:12:16 +00:00
Dag-Erling Smørgrav
f6a10fea63 Protoize. 2004-07-05 13:03:35 +00:00
Dag-Erling Smørgrav
cd23263cdd Sort out the #include mess. In particular, do not #include "os.h", since
all it does is provide broken prototypes for standard library functions.
2004-07-05 12:58:47 +00:00
Dag-Erling Smørgrav
1ce57ca079 Mechanical whitespace cleanup. 2004-07-05 12:51:35 +00:00
Dag-Erling Smørgrav
d62a717dae My previous commit fixed uid filtering, but broke io mode. Unravel the
process filtering logic to prevent this from happening again.
2004-07-05 12:48:17 +00:00
Dag-Erling Smørgrav
a578eed9af Fix selecting processes by uid, which was broken in the previous commit. 2004-07-05 12:22:50 +00:00
Alfred Perlstein
7fe9a86a5a Tell what percentage of the total IO a process is doing.
TODO: Show system totals.
2004-07-01 15:49:28 +00:00
Alfred Perlstein
db6bb7fc01 New feature, provide a display that shows the amount of IO processes
are doing.  Toggle this mode by hitting "m" or passing the command line
option "-m io" to top(1).  This allows one to identify disk bandwidth
hogs much easier.
2004-07-01 09:12:38 +00:00
Alfred Perlstein
970636e94f style, remove register. 2004-06-30 04:19:23 +00:00
Brian Feldman
cac4b14c12 Do not use KERN_PROC_PROC with kvm_getproc(3); instead, if only process
(and not thread) scope is to be displayed, use KERN_PROC_ALL and
accrue CPU% ourselves, as the kernel makes no attempt to do so.

Of course, this doesn't make most stats any less bogus when displaying
threaded processes, but at least the CPU time is added up and not just
always 0.00%.  There are still issues with SCHED_ULE in top(1) that
cause other processes to display 0.00% CPU when they in fact have used
more.
2004-06-06 19:59:06 +00:00
Julian Elischer
e27d79bb28 Changes to allow top to decide whether or not to show multiple threads per
process. Option -H enables it and it is toggled at the interactive
screen by 'H'.

Submitted by:	Jung-uk Kim <jkim@niksun.com>
2003-07-17 23:56:40 +00:00
Poul-Henning Kamp
f341ca9891 Remove #include <sys/dkstat.h> 2003-02-16 14:13:23 +00:00
John Baldwin
0d6326492b Catch up to SMTX -> SLOCK changes. 2002-10-02 20:33:52 +00:00
Philippe Charnier
93b0017f88 Replace various spelling with FALLTHROUGH which is lint()able 2002-08-25 13:23:09 +00:00
Warner Losh
3f330d7d1a remove __P 2002-03-22 01:42:45 +00:00
Mark Murray
e35f9517d6 Remove NO_WERRORs and WARNS=n's. To be revisited after GCC3. 2002-02-08 23:07:37 +00:00
David Malone
24bd57cbbd Add new option HAVE_STRERROR to CFLAGS. 2002-01-24 17:59:39 +00:00
Mark Murray
19964b3233 Protect this against the coming WARNS=2 default. 2001-12-12 00:05:16 +00:00
Bruce Evans
6eabd84580 Compensate for "Compensate for header dethreading" by backing it out. 2001-10-10 17:48:44 +00:00
Ruslan Ermilov
7d20bafcad Generate top.local.h and manpage dynamically, with sed(1) script.
The generated manpage will now describe the actual behavior of
top(1) WRT how many processes it displays.  This also eliminates
all troff(1) warnings.
2001-07-12 15:07:30 +00:00
Thomas Moestl
e0038fe587 Cast size_t variables before printing them to cope with the case of
sizeof(size_t) != sizeof(int).
2001-05-31 22:36:51 +00:00
Poul-Henning Kamp
719bfad4aa We don't need to include <sys/conf.h> 2001-05-23 23:01:37 +00:00
Mark Murray
6e547eabb8 Compensate for header dethreading. 2001-05-01 08:46:02 +00:00
John Baldwin
2522796e9d Check the new kern.smp.active sysctl rather than the non-existent
smp.smp_active sysctl to determine if we are running on an SMP machine.
2001-04-27 19:33:50 +00:00
Thomas Moestl
6243f7aca4 Correct the top memory stats display: convert page counts to kB.
Submitted by:	Andrea Campi <andrea@webcom.it>
Approved by:	rwatson
Pointy hat to:	myself
2001-03-20 16:02:16 +00:00
Will Andrews
9e13809564 Fix top(1) display for SMP systems where the username is longer than 14
characters.  This should avoid unattractive wrapping for people who are
stuck in an 80x24 screen.  :-)

PR:		22270
Submitted by:	William Carrel <williamc@go2net.com>
2001-03-12 05:53:54 +00:00
Andrew Gallatin
98e53e5bfb - An array of 4 32-bit ints for avenrun doesn't work on the alpha because
fscale is a (64-bit) long.  So just use a struct loadavg.
This fixes the recent failure of top on alphas:
	top: sysctl(vm.loadavg...) failed: Cannot allocate memory

- use size_t for sizeof() so as to fix a few int/long warnings on alpha

Reviewed by: Thomas Moestl <tmoestl@gmx.net>
2001-02-27 17:11:19 +00:00
Robert Watson
0ce14ceb84 Remove directive to install top as group kmem. Remove directive to
install top with setgid bit.
2001-02-23 18:55:43 +00:00
Robert Watson
39d513ecdd Adapt the top utility to not use kmem_read to retrieve variables now
available via sysctl().  As a result, top should now be able to run without
setgid kmem.

Submitted by:	Thomas Moestl <tmoestl@gmx.net>
Reviewed by:	freebsd-audit
2001-02-23 18:52:37 +00:00
Mark Murray
a28d666c49 Adjust columns for wide nicenesses in 'top -S'. 2001-02-18 11:08:47 +00:00
Jake Burkholder
4c85452ba9 Catch up to new priority interface. 2001-02-12 00:21:38 +00:00
John Baldwin
0821b7ca3a Catch up to proc flag change. 2001-01-24 14:17:23 +00:00
Kirk McKusick
1f7d250182 Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
John Baldwin
7f18d5d343 Make use of the full screen width to display p_comm rather than assuming a
hardcoded screen width of 80 chars.
2000-11-29 23:03:02 +00:00
John Baldwin
089f9b7e2f Display the name of the mutex we are blocked on in the state field. To
differentiate mutex names from wait channel names, prefix mutex names with
an asterisk.

Submitted by:	Dan Nelson <dnelson@emsphone.com>
2000-11-29 20:22:34 +00:00
Jason Evans
0384fff8c5 Major update to the way synchronization is done in the kernel. Highlights
include:

* Mutual exclusion is used instead of spl*().  See mutex(9).  (Note: The
  alpha port is still in transition and currently uses both.)

* Per-CPU idle processes.

* Interrupts are run in their own separate kernel threads and can be
  preempted (i386 only).

Partially contributed by:	BSDi (BSD/OS)
Submissions by (at least):	cp, dfr, dillon, grog, jake, jhb, sheldonh
2000-09-07 01:33:02 +00:00
David Nugent
dc7c1750c2 Reduce max length of user names to 15 characters to reflect reality.
This also prevents the line-wrap and messed up display that occurs
when there happens to be one or more names with 15 chars.
1999-11-17 16:31:51 +00:00
Bruce Evans
a8224b82fd Fixed sorting on time. On i386's, time differences of more than 2147
seconds caused overflow.  Use a type-safe but slightly slower comparison.
Comparisons for other fields are still fragile.

Fixed rounding of cputime (don't do extra work to get it slightly wrong
by first converting without rounding to milliseconds).

Removed dead code for setting cputime.

Fixed comments about cputime.
1999-11-17 03:25:54 +00:00
Peter Wemm
c3aac50f28 $Id$ -> $FreeBSD$ 1999-08-28 01:08:13 +00:00
Nick Hibma
33d56839e3 Man pages for top refer to only 2.x, but not to 3.x and later 1999-06-14 12:06:11 +00:00
Peter Wemm
bf0e1ee370 Tidy up references to <sys/rlist.h> and support for the old swap management
that went away in January.
1999-05-11 14:32:18 +00:00
John Hay
e7f807a217 Fix the display of the "nice" value of processes like ntpd that use the
posix sched_setscheduler() to set their priority.

Noticed by:	Mark Allwright <mallwri@orion.didata.co.za>
1999-04-22 14:34:53 +00:00
Bruce Evans
6bc6d9631d Oops, the test for "no-cpu" was inverted.
Submitted by:	Seigo TANIMURA <tanimura@naklab.dnj.ynu.ac.jp>
1999-03-07 06:55:47 +00:00
Bruce Evans
efc96764e0 The magic "no-cpu" cpu number is 0xff. Don't misrepresent cpu
numbers as chars or use bogus casts in an attempt to unmisrepresnt
them.  In top, don't assume that 0xff is the only negative cpu
number when cpu numbers are (mis)represented.
1999-03-05 16:38:13 +00:00
Bill Fenner
1005b43609 Don't dump core when p_stat is not in the expected range. This is
only likely to happen when you have a kernel<>userland mismatch,
but it's really annoying when top dumps core and leaves the terminal
in a mangled state; it's much nicer to print nicely formatted gibberish.
1999-02-06 16:58:50 +00:00
Matthew Dillon
47b370f5c6 Make 'top' handle case w/ new swapper where no swap is configured 1999-02-06 06:33:55 +00:00
Matthew Dillon
7bb42db9e7 Make top use new kvm_getswapinfo() call. 1999-01-22 11:09:41 +00:00
David E. O'Brien
a2641311ff uptime display more in style with original code 1999-01-09 20:25:02 +00:00
Bruce Evans
c13e5fb799 Removed unused nlist'ed variables stathz and hz. These used to be used
to half compensate for broken scaling of p_pctcpu in the kernel, but the
previous commit removed this compensation.  %cpu values will be wrong by
a factor of stathz/hz until the kernel is fixed.  (The kernel gets it
wrong by a factor of stathz/hz, and top got the compensation wrong by
a factor of 100/stathz.)
1998-11-26 12:59:21 +00:00
Doug Rabson
d24b518319 Port top to the alpha.
Submitted by: Hidetoshi Shimokawa <simokawa@sat.t.u-tokyo.ac.jp>
1998-11-25 09:45:28 +00:00
Dmitrij Tejblum
00e500a2e5 Some fixes for swap space accounting.
Obtained from:  pstat.c
1998-09-11 14:38:12 +00:00
Wolfram Schneider
f3b2c2d1d3 Merge from stable: support for the o, order, command 1998-08-12 09:58:15 +00:00
Dag-Erling Smørgrav
e7cdb97253 Add -t option ('t' in interactive mode) to make top(1) ignore itself.
Attempts to contact the author of top(1) (William LeFebvre) have so
far been unsuccessful.

PR:		7253
Submitted by:	Yours Truly
1998-08-04 14:10:48 +00:00
Wolfram Schneider
4dc0ec1db1 Round - not cut - the real cpu time. 1998-07-27 12:21:58 +00:00
Dmitrij Tejblum
8fbaa58a29 Make value of SIZE accurate.
Obtained from:	ps(1)
1998-06-21 18:00:34 +00:00
Poul-Henning Kamp
e796e00de3 Some cleanups related to timecounters and weird ifdefs in <sys/time.h>.
Clean up (or if antipodic: down) some of the msgbuf stuff.

Use an inline function rather than a macro for timecounter delta.

Maintain process "on-cpu" time as 64 bits of microseconds to avoid
needless second rollover overhead.

Avoid calling microuptime the second time in mi_switch() if we do
not pass through _idle in cpu_switch()

This should reduce our context-switch overhead a bit, in particular
on pre-P5 and SMP systems.

WARNING:  Programs which muck about with struct proc in userland
will have to be fixed.

Reviewed, but found imperfect by:       bde
1998-05-28 09:30:28 +00:00
Peter Wemm
373e363e34 Fix top sorting of idle processes. top used p_cpticks as a tie-breaker
but that isn't suitable (it gets zeroed each second apparently).

PR: bin/4957
Submitted-by: Dan Nelson <dnelson@emsphone.com>
1998-02-14 13:34:59 +00:00
Steve Passe
cb52d9ccc5 For SMP, add a space between the state name and the CPU#.
Everything following bumps right 1 character.
1997-10-05 21:20:56 +00:00
Peter Wemm
e5aff02f68 YAMF22: (rev 1.3.2.2) Display realtime and idle priorities appropriately. 1997-09-28 00:59:04 +00:00
Peter Wemm
ed550569a2 Adapt to recent smp tree changes.. 1997-08-27 03:48:25 +00:00
Bruce Evans
745ec60f07 Added top.1 to CLEANFILES. 1997-07-21 16:06:00 +00:00
Peter Wemm
a2aff8b2bd Hack to work around the large username field... scan for the largest
username present on the system at startup and use that for the field width.
It's not ideal but (I think) better than it was before.  The width is
limited to within 8..16.
1997-07-14 09:06:46 +00:00
Peter Wemm
94154ff82b Dynamically adapt to smp mode at runtime. This stops the cpu column
appearing on uniprocessor systems since the smp->current merge.
1997-07-12 10:51:54 +00:00
Andrey A. Chernov
595c8b2ff9 Long usernames fixes 1997-04-21 13:53:47 +00:00
Peter Wemm
524a8761b1 Tweak column headers a tad for when running in SMP mode. 1997-04-19 20:28:50 +00:00
Peter Wemm
aa9278ffa9 move top.1 -> top.local.1, and generate top.1 so that the man page
is remotely useful
1997-04-05 22:05:46 +00:00
Andrey A. Chernov
d9c406718c Remove libcurses, it is pure termcap application 1997-03-24 14:29:46 +00:00
Joerg Wunsch
511d9c6565 This is the FreeBSD-specific files for top, plus the Makefile
that pulls all the files from contrib.

Obtained from:	The ports collection (mostly).
1997-03-23 18:55:20 +00:00