Commit Graph

203 Commits

Author SHA1 Message Date
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
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
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
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
5ef89dbfa7 top(1): further unconditionally assume we're on FreeBSD 2018-05-21 04:40:20 +00:00
Eitan Adler
47ffa267d7 top(1): further unconditionally assume we're on FreeBSD 2018-05-21 04:02:45 +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
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
878441444b top(1): Remove now-unused variable 2018-05-20 23:39:08 +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
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
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
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
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
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
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
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
Kevin Lo
cf7f8a9de8 Print size_t's with %zu rather than "%zd.
Reviewed by:	bde
2015-03-26 09:13:16 +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
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
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
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
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
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
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
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
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
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
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
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
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
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