Commit Graph

276 Commits

Author SHA1 Message Date
Hisham Muhammad 72ba20fa5f Introduce screen tabs
This is a forward port (by nathans) of Hisham's original code.
2021-12-07 17:04:49 +11:00
Benny Baumann 550100327b Extract string writing/buffer handling into some callback 2021-11-28 20:19:10 +01:00
Benny Baumann 9dc964bb42 Compress cgroup names based on some heuristics 2021-11-28 20:19:10 +01:00
Benny Baumann ea4282784d Filter leading colons in CGROUP name 2021-11-28 20:19:10 +01:00
Rin Cat (鈴猫) 07496eafb0 Linux: use proper way to detect kernel threads
Use PF_KTHREAD flag in /proc/[pid]/stat to detect kernel threads.
This fixed an issue when a process's cmdline is empty, htop think
it is a kernel thread.
2021-11-09 19:04:25 +01:00
marcluque d8dfbbd37c Tidy up process state handling 2021-11-02 20:02:54 +01:00
Christian Hesse 3f9f52fd29 Linux: ignore mapped /dev/zero
Virtualbox maps /dev/zero for memory allocation. That results in
false positive, so ignore.
2021-10-25 21:05:28 +02:00
Christian Göttsche 970885edc3 Linux: improve tryRead macro safety
Add an explicit else clause so a following else branch for a prior if
condition does not get mixed up.

Also force a trailing semicolon and thereby silence current
-Wextra-semi-stmt warnings.

Improve readability of the hwloc_bitmap_foreach_begin loop macro.
2021-10-01 18:36:35 +02:00
Nathan Scott 6f751d5929 Merge branch 'o_path' of https://github.com/cgzones/htop into cgzones-o_path 2021-09-27 13:13:13 +10:00
Christian Göttsche 754c0d6bb9 Linux: always compute procExeDeleted if already set
A process, whose executable has been replaced and thus marked by htop,
can be re-executed with the replaced executable, with the same PID, in
two ways: the Linux feature checkpoint/restore or re-execution of PID 1.
The actual check is just a string comparison, like the dropped
condition, leading to (almost) no computation overhead.
2021-09-24 22:03:16 +02:00
Christian Göttsche a710deeaa7 Linux: define O_PATH if not defined
Defining O_PATH if not defined by <fcntl.h> does not really add any
maintenance cost and might improve some portability.

Related: #804
2021-09-24 20:31:48 +02:00
Daniel Lange 94ad111391 Update license headers to explicitly say GPLv2+ 2021-09-22 14:28:19 +02:00
Christian Göttsche 3c8d586a1c Linux: recalculate LRS value
The LRS value is only zero in the first cycle; drop the check to
recalculate while running.
2021-09-12 18:20:40 +02:00
Christian Göttsche 43ffdb0eda Linux: zero CPU data after allocation
Zero all the CPU data, like totalPeriod, after its memory allocation via
realloc(3).

    Conditional jump or move depends on uninitialised value(s)
       at 0x132A9B: LinuxProcessList_scanCPUTime (LinuxProcessList.c:1928)
       by 0x1358C3: ProcessList_goThroughEntries (LinuxProcessList.c:2079)
        by 0x12A79A: ProcessList_scan (ProcessList.c:627)
        by 0x11CA67: CommandLine_run (CommandLine.c:357)
        by 0x4A81E49: (below main) (libc-start.c:314)
      Uninitialised value was created by a heap allocation
        at 0x48396C5: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
        by 0x12F633: xRealloc (XUtils.c:64)
        by 0x12F633: xReallocArray (XUtils.c:78)
        by 0x1325A8: LinuxProcessList_updateCPUcount (LinuxProcessList.c:207)
        by 0x134E0A: ProcessList_new (LinuxProcessList.c:284)
        by 0x11C8D0: CommandLine_run (CommandLine.c:301)
        by 0x4A81E49: (below main) (libc-start.c:314)
2021-09-11 00:04:00 +02:00
Christian Göttsche 74f99e3693 linux: simplify recheck condition
`recheck` is calculated modulo 2048, so its maximum value is 2047.
Drop the quite similar (up to 27 milliseconds) explicit check against
2000.
2021-09-02 08:03:21 +02:00
Christian Göttsche 58a59c11f4 linux: drop dead process field column DIRTY
The field for dirty pages in /proc/[pid]/statm is always 0 since Linux
2.6 (see man:proc(5)).
2021-09-02 08:03:21 +02:00
Christian Göttsche 2bf626c4e4 IWYU update 2021-08-25 09:54:30 +02:00
Christian Göttsche 9df0f62859 Linux: do not scan frequency for inactive CPUs 2021-08-22 14:50:38 +02:00
Christian Göttsche ce27f8379d Respect "Show custom thread names" setting update
Update merged command-line when started with "Show custom thread names"
disabled and enabling at runtime.

Also only consider showThreadNames when working on userland threads.
2021-08-14 17:05:00 +02:00
Nathan Scott f839095e3b Merge branch 'dynamic-columns' of https://github.com/smalinux/htop into smalinux-dynamic-columns 2021-08-13 15:56:01 +10:00
Sohaib Mohamed 6f2021f3d9 PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns.  The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.

We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.

Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location.  Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop.  This
final location becomes the preferred place for our own
shipped meter and column files.

The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start.  Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-08-13 07:32:57 +02:00
Nathan Scott 02cfd38671 The average CPU utilization value must never be marked 'offline'
Fixes https://github.com/htop-dev/htop/issues/729
2021-08-10 08:00:35 +02:00
Nathan Scott 1bd95983b2 Add columns for process autogroup identifier and nice value
Adds AGRP (autogroup) and ANI (autogroup nice) columns that
report the information from /proc/PID/autogroup, as well as
handlers for '{' and '}' to change the autogroup nice value.

This is guarded by /proc/sys/kernel/sched_autogroup_enabled
such that sampling and/or changing values wont be attempted
unless the kernel feature is enabled.

Fixes: #720
2021-08-09 07:56:13 +02:00
Christian Göttsche 10e9ffd8e5 Fix misc typos
[ci skip]
2021-08-08 15:10:58 +02:00
Christian Göttsche 11d2206f40 Add ProcessList_isCPUonline 2021-07-18 07:47:09 +02:00
Christian Göttsche 41af31be7f Rework CPU counting
Currently htop does not support offline CPUs and hot-swapping, e.g. via
    echo 0 > /sys/devices/system/cpu/cpu2/online

Split the current single cpuCount variable into activeCPUs and
existingCPUs.

Supersedes: #650
Related: #580
2021-07-18 07:44:02 +02:00
Benny Baumann 976c6123f4 Pointer indication aligned to typename 2021-07-15 06:57:24 +02:00
Benny Baumann 458749df45 Code indentation 2021-07-15 06:57:24 +02:00
Nathan Scott f0ed0fdafb Add a new DynamicMeter class for runtime Meter extension
This commit is based on exploratory work by Sohaib Mohamed.
The end goal is two-fold - to support addition of Meters we
build via configuration files for both the PCP platform and
for scripts ( https://github.com/htop-dev/htop/issues/526 )

Here, we focus on generic code and the PCP support.  A new
class DynamicMeter is introduced - it uses the special case
'param' field handling that previously was used only by the
CPUMeter, such that every runtime-configured Meter is given
a unique identifier.  Unlike with the CPUMeter this is used
internally only.  When reading/writing to htoprc instead of
CPU(N) - where N is an integer param (CPU number) - we use
the string name for each meter.  For example, if we have a
configuration for a DynamicMeter for some Redis metrics, we
might read and write "Dynamic(redis)".  This identifier is
subsequently matched (back) up to the configuration file so
we're able to re-create arbitrary user configurations.

The PCP platform configuration file format is fairly simple.
We expand configs from several directories, including the
users homedir alongside htoprc (below htop/meters/) and also
/etc/pcp/htop/meters.  The format will be described via a
new pcp-htop(5) man page, but its basically ini-style and
each Meter has one or more metric expressions associated, as
well as specifications for labels, color and so on via a dot
separated notation for individual metrics within the Meter.

A few initial sample configuration files are provided below
./pcp/meters that give the general idea.  The PCP "derived"
metric specification - see pmRegisterDerived(3) - is used
as the syntax for specifying metrics in PCP DynamicMeters.
2021-07-07 10:59:36 +10:00
fraggerfox 3770769ed1 Replaces WRAP_SUBTRACT with saturatingSub inline function to reduce code duplication. 2021-06-26 12:18:37 +02:00
Christian Göttsche df752dd189 Do not override Linux process library size
The library size in statm is unused and always 0 since Linux 2.6.

Fixes: 8154125d4b
2021-06-12 20:44:33 +02:00
Christian Göttsche 45ab05c56a Limit deleted library check
Reading and parsing /proc/<pid>/maps is quite expensive.

Do not check for deleted libraries if the main binary has been deleted;
in this case the deleted binary takes precedence.

Do not check in threads.  The check is void for kernel threads and user-
land threads can just inherit the state from the main process structure.
2021-06-12 16:02:23 +02:00
Christian Göttsche 9114cf6ea3 Linux: update process uid on change
Always check if the user of a process changed, e.g. by using setuid(2).
2021-06-09 22:52:18 +02:00
Christian Göttsche faabbaa71e Linux: drop O_PATH usage
O_PATH is available since Linux 2.6.39, but we are using fstat(2) on the
returned file descriptor in LinuxProcessList_statProcessDir(), which
is only supported since Linux 3.6.

Fixes #534
2021-06-09 22:52:18 +02:00
Christian Göttsche 8154125d4b Check processes for using deleted shared libraries
Shared libraries can be replaced by an upgrade, highlight processes
using deleted shared libraries.

Link with highlightDeletedExe setting, enabled by default.

Currently only checked on Linux.
2021-06-09 14:40:04 +02:00
Benny Baumann b6ff5c8a2e Move CWD field handling to platform-neutral code 2021-05-25 21:55:04 +02:00
Christian Göttsche c408add108 Linux: add reset to heuristic
On hard to parse command lines tokenStart might be computed to be bigger
than tokenEnd.
Reset both values in such cases.
2021-05-25 18:20:09 +02:00
Christian Göttsche 3d5b6d9282 Fix assert failure on short running thread
The following assert failure might happen on short running threads with
an empty comm value in /proc/${pid}/stat:

htop: Process.c:1159: void Process_updateCmdline(Process *, const char *, int, int): Assertion `(cmdline && basenameStart < (int)strlen(cmdline)) || (!cmdline && basenameStart == 0)' failed.

The specific task is:
    comm=''
    exe='(null)'
    cmdline='/usr/bin/ruby /usr/bin/how-can-i-help --apt'

So basenameStart is 0, while strlen(cmdline) is also 0.
2021-05-23 15:25:23 +02:00
Benny Baumann 51ecc62d92 Force update when executable was recently deleted/replaced 2021-05-23 09:30:36 +02:00
Christian Göttsche 7892ac68fb Linux: use merge command line helpers 2021-05-23 09:22:21 +02:00
Benny Baumann 7ef58f2dcf Drop mc->maxLen field 2021-05-23 09:22:21 +02:00
Benny Baumann a61a2e6d47 Call makeCommandStr on all platforms 2021-05-23 09:22:21 +02:00
Benny Baumann bcb18ef822 Move Process_makeCommandStr to global Process implementation 2021-05-23 09:22:21 +02:00
Benny Baumann 7224d0e083 Move kernel/userland thread handling to platform-independent implementation 2021-05-23 09:22:21 +02:00
Benny Baumann 1a1fddae85 Pre-calculate isUserlandThread flag 2021-05-23 09:22:21 +02:00
Benny Baumann cdb660adab Move mergeCommand to global process struct 2021-05-23 09:22:21 +02:00
Benny Baumann 94a52cb5c9 Rename cmdlineBasenameOffset to cmdlineBasenameEnd to properly indicate the fields purpose 2021-05-23 09:22:21 +02:00
Benny Baumann 666f70c58c Move procCmdlineBasenameOffset as cmdlineBasenameStart to global Process structure 2021-05-23 09:22:21 +02:00
Benny Baumann 6dc485dd20 Remove duplicate field LinuxProcess->procCmdlineBasenameEnd
This field held practically the same value as cmdlineBasenameEnd
2021-05-23 09:22:21 +02:00
Benny Baumann a685661866 Move procExeBasenameOffset to main Process structure
This drops procExeLen, as that field is implicit by strlen(Process->procExe)
2021-05-23 09:22:21 +02:00