Commit Graph

4040 Commits

Author SHA1 Message Date
Jim Warner
9dc281fe4b library: include the 'docker' containers in <pids> api
This commit makes a task's 'docker' container id (both
full and abbreviated) available within the <pids> API.

It is patterned after that 'lxc' container logic which
tracks ids already seen so as to avoid repeated malloc
plus free calls. It should be noted, however, that the
'docker' ids do not proliferate like those others may.

In implementing the addition, the 'readproc/task' code
had to be tweaked a little. The code for PROC_FILL_LXC
and PROC_FILL_DOCKER now share a buffer containing the
cgroup contents so as to avoid a second file2str call.

[ yes, each container extraction routine may corrupt ]
[ that buffer. and yes, a caller may request both of ]
[ those enums (LXNAME and DOCKER_ID) simultaneously. ]
[ but, a task can be in only one container at a time ]
[ so the buffer would get whacked at most just once. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
0ffd98f652 NEWS: acknowledged separate 'disk sleep' in <pids> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
a0572ef4e3 top: accommodate a separate 'disk sleep' in <pids> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
cf9a63f2c4 library: enabled a separate 'disk sleep' in <pids> api
This patch was prompted by the issue referenced below.

Previously the library silently combined the 'D' state
(disk sleep/uninterruptible sleep) with the 'S' state.

That approach meant the reap or select counts were not
at all self documenting. Even worse, since the 'R' and
'D' states were involved in load average calculations,
accurately assessing high load average was impossible.

Now, instead of an arbitrary library decision, callers
can choose to combine or report the counts separately.

[ this change could be made in a way which preserves ]
[ the ABI, requiring bumping this library 'revision' ]
[ only, by placing that new 'disk_sleep' count last. ]

[ that, however, wouldn't be fair to potential users ]
[ of the old 'sleep' value which included 'D' tasks. ]
[ thus, the API is implicitly broken by this change. ]

[ so for clarity, we'll locate 'disk_sleep' adjacent ]
[ to 'sleep' which will then necessitate raising the ]
[ 'current' value then zeroing 'revision' and 'age'. ]

Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/265

Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
c9b3a2ddbc NEWS: mention change to 'SCHED_CLASSSTR' in <pids> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
ac47f8aece top: exploited that new 'SCHED_CLASSSTR' in <pids> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
e75709f278 ps: switch to using the 'SCHED_CLASSSTR' in <pids> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
a9324139d9 library: introduced new 'SCHED_CLASSSTR' in <pids> api
Many years ago a truly awful patch was submitted which
purported to add a 'CLS' field to top. That patch, and
a subsequent offering, were rejected. This commit will
allow adding such a field to top and also simplify ps.

We've added this newest field in a way that will break
both our library's API and ABI. As an alternative, the
change could have been implemented as shown in a patch
referenced below. However, a subsequent commit dealing
with <pids> disk_sleep will break both of them anyway.

Reference(s):
https://www.freelists.org/post/procps/PATCH-topadded-scheduling-class-in-top-output,1
Aug, 2016 - expand fields yet maintain API/ABI
commit 09e1886c9e

Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
d5f74ee3bc NEWS: updated with new 'ZSWAP' fields in <meminfo> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
be4e6d50e5 library: added two new 'ZSWAP' fields in <meminfo> api
With the 5.19 kernel two new fields dealing with zswap
were introduced. They are present when CONFIG_ZSWAP is
defined. That configuration seems to be the usual one.

We're adding these new fields in a way that will break
both our library's API and ABI. As an alternative, the
change could have been implemented as shown in a patch
referenced below. However, a subsequent commit dealing
with <pids> disk_sleep will break both of them anyway.

Reference(s):
Aug, 2016 - expand fields yet maintain API/ABI
commit 09e1886c9e

Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
f88e0172ab top: tweak some Fieldstab widths related to processors
This commit just corrects some inconsistencies between
the EU_CPN (cpu number) and EU_NMA (numa node) fields.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
7caff8c96b top: a few minor miscellaneous code/comment/man tweaks
. clarify that CGNAME is not available with cgroup v2.

. error_exit() might be called from one signal handler
  and it, in turn, calls that bye_bye() function so we
  must adjust slightly that latter's prologue comment.

. using 'static' will avoid repeatedly executing the 2
  instructions (for initialization) otherwise present.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-12-26 20:55:24 +11:00
Jim Warner
d4ecd5cb35 build-sys: add 'units.h' to the local/Makefile.am file
An addition that's needed for the 'make dist' tarball.

Reference(s):
. Oct, 2023 - units.c was intrduced
commit 460df8aeb5

Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-10-16 07:13:36 +11:00
Craig Small
f9927c6650 docs: Add manpage and NEWS for human slabtop
Update slabtop.1 to describe --human flag
Added NEWS entry

References:
 https://www.freelists.org/post/procps/Add-human-flag-to-slabtop
 commit c4f33bc302
2023-10-11 18:01:22 +11:00
Krzysztof Piecuch
c4f33bc302 Slabtop - add --human flag for human-readable units
Strongly inspired from free.c codebase

I had to split PRINT_line into two calls because scale_size reuses the
buffer and that's the easiest workaround for that.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-11 17:55:09 +11:00
Krzysztof Piecuch
d5364379cd Whitespace fix - tabs to spaces
no functional change

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-11 17:55:04 +11:00
Krzysztof Piecuch
460df8aeb5 Move scale_size away from free to use in other programs
no functional change

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-11 17:54:17 +11:00
Roman Žilka
b22540117a watch: Indicate (with blank lowheader) when is cmd running
* Because 's' is synchronous, it's become necessary to indicate when is cmd
  running. Without it the user may not be sure whether a 's' will save the
  output currently on-screen or the next iteration output. The blank lowheader
  is relatively unobtrusive, but might suggest that the timestamp in header is
  the time of cmd completion. Also, it puts potentially time-consuming I/O
  between cmd iterations. Still, the best option I could think of. Header
  semantics is given in manpage.
2023-10-06 16:59:02 +11:00
Roman Žilka
1f3bbde55f watch: Typing corrections, more concise check for screen resizing in sleep loop 2023-10-06 16:59:02 +11:00
Roman Žilka
88b1e6b03d watch: React to 'q' only after processing all available input (deterministic) 2023-10-06 16:59:02 +11:00
Roman Žilka
d9cc0438a6 watch: Added -s to usage() 2023-10-06 16:59:02 +11:00
Roman Žilka
80be969f6a watch: Implemented -s/--shotsdir 2023-10-06 16:59:02 +11:00
Roman Žilka
bf66c76f6e watch: Implemented sync. key control: restart [#240], quit [#270], screenshot
* Implemented key control. Keys don't interrupt running cmd.
* Implemented ' ' (issue immediate cmd run, partial #240), 'q' (quit, #270), 's'
  (take screenshot).
* -n limited to 31 days (limitation of select()).
* Prepended all xerr()s with endwin() to have the msg displayed.
2023-10-06 16:59:02 +11:00
Roman Žilka
ba70e47c33 watch: Display lowheader when exiting on -e
* Display lowheader when exiting on -e.
* Only refresh() screen when cmd was run this pass through the main loop in
  main(). Till now the first line of header was refreshed on-screen each time
  the main loop restarted. That was confusing when resizing with -r: current
  time in header would update after a resize, suggesting that the cmd was
  executed at that time, while it actually wasn't and the cmd output shown
  would be invalid: either it'd be old or presented as empty (when clear() used
  to be part of the main loop prologue).

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:53:26 +11:00
Roman Žilka
bfa1553129 watch: Removed dead code reg. STOPped children, bugfix in child status proc. (branch regr.)
* Removed code that handled STOPped command process. waitpid() doesn't report
  those by default.
* Fixed a minor bug in child status processing when WIFEXITED and WEXITSTATUS=0
  (topic branch regression).
* Moved two TODOs to gitlab issues.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:53:24 +11:00
Roman Žilka
1cf2018ac4 watch: Make sure to consume all output of cmd to avoid SIGPIPE
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:53:20 +11:00
Roman Žilka
f25cead24a watch: Included cmd exitcode in 2nd line of header
* Included cmd exitcode in 2nd line of header.
* Reverted back to "in" from "ran" in running time display. Looks better.
* Manpage: moved info on header from -t description to intro.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:53:15 +11:00
Roman Žilka
54c59b15d8 watch: -e passes command's exit code on to environment
* -e exits with cmd's last exit code. Possibly a regression fix, similar
  function used to be mentioned in manpage.
* Without -e, exit codes partitioned into success (0), cmd-related errors (2),
  other errors (1).
* Child returns sh-like codes on signal and failure to exec/wait.
* Replaced xerr()s following ncurses init with a ncurses-aware exit.
* Removed unnecessary clear() when screen resizes.
* Replaced the ambiguous "in" with "ran" in lowheader.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:53:13 +11:00
Roman Žilka
3813326f2f watch: Implemented displaying of cmd running time in header
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:53:07 +11:00
Roman Žilka
ac89d63c5a signals: Updated signal list and defines, introduced RTMAX, fixed strtosig()
* Removed the intro comment: it's >20 years old, some things clearly no longer
  hold (UNUSED, the bug in glibc, Linux ports, ...). Replaced it with some
  boilerplate intro.
* Updated manual defines of missing macros (explained in comments). Removed the
  EMT/STKFLT situation (ancient).
* All functions now account for SIGRTMAX.
* Placed all known non-RT signals into sigtable[]. There's no need anymore to
  try hard to only keep uniquely-numbered signals in it and to make them a
  complete sequence. Most kinds of updates to the signals can be accomplished
  just by editing the table. All functions accomodate, there's no longer a need
  for them to maintain exceptions (most of them).
* No function returns a freeable pointer.
* strtosig(): Re-write (old one didn't handle synonyms, interpreted malloc()
  failure as signal not found).
* On the auxiliary, implemented a stable sort. The stability of qsort() is
  unspecified.

References:
 !207
2023-10-06 16:45:43 +11:00
Roman Žilka
77aecd3e9f watch: Removed TODO that'd been impl., listed name in credits
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:35:12 +11:00
Roman Žilka
21adce9fc4 watch: Corrected header on first_screen, build error when !8BIT (branch regr.)
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:34:48 +11:00
Roman Žilka
4760f3d6b3 watch: Calculate cur usec timestamp in a large enough type (branch regression)
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:34:38 +11:00
Roman Žilka
0a5b342927 watch: Orderly recovery from cmd taking longer than -n [BUG]; code cleanup
* When cmd took longer than -n to complete, -p is no longer skipping sleeps to
  make up for the time lost waiting for the completion(s) [BUG].
* Code cleanup, minor optimization. Moved universal routines to
  strutils/fileutils.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:34:11 +11:00
Roman Žilka
771f8dc559 watch: -d considers full width of new character
* -d considers all columns the new char will occupy, not just the first one.
  When 日a -> a日a, 日 is now highlighted (because of the change in its 2nd
  column).

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:33:52 +11:00
Roman Žilka
4e3d520f09 watch: Fixed -d ignoring combining characters [BUG]
* Worked around a ncurses bug of applying combining characters to the base
  character preceding the target one. -d now operates on all components of
  complex characters. Removes a BUG.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:33:25 +11:00
Roman Žilka
1b8626ec54 watch: Consume outstanding input before allowing termination due to -e
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:32:20 +11:00
Roman Žilka
54c531de6a watch: Header printing locale-aware, optimized and bug-fixed; corr. BUGS and EXIT STATUS in man
* Manpage:
  * Reduced EXIT STATUS to 0 and other. The others were uninteresting in a
    manpage and passing cmd exitcode doesn't work.
  * Removed BUG about combining characters in last column. AFAICS it's gone.
  * Removed BUG about -p not killing cmd when it takes too long. That can be a
    new feature, but the current behavior is what a lot of people might well
    expect by default.
  * Re-phrased the BUG with "rapid-fire" in it. Makes it look like a fork bomb.
* Impl. mbswidth(), the strlen()/wcswidth() for multi-byte strings.
* In header printing:
  * Fixed a few bugs in positioning and truncation (it's ctime()).
  * For 8BIT, column widths are considered instead of mbstring lengths (not just
    for the cmd).
  * ENOMEM handled after asprintf().
  * ctime() -> strftime() for a localized string. Left out date. Ok?
  * Most of header is pre-composed for speed.
* -qN, N < 1, becomes -q1.
* When screen resizes, -q now only pauses for a turn, doesn't restart. This is
  probably as much as can be done without a modification to the change-detecting
  routine.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:31:14 +11:00
Roman Žilka
552308031d watch: Removed use of hijacked streams after fork(), ensured fds/processes do not leak
* Manpage:
  * Rewrote the description of -p. It wasn't saying what -p did.
  * Added COLUMNS and LINES to ENVIRONMENT.
  * Refreshed EXAMPLES, moved it up to be before BUGS.
* Regression in topic branch: tabs now print properly.
* Removed output into the hijacked stdout/err following fork().
* EINTR-protected watpid()s and the release of fds to prevent leaks.
* Removed the measure taken in Debian#240989 to circumvent faulty is(w)print().
  Glibc has been fixed (verified) and as it was, watch was letting all non-ASCII
  non-printables into output. I'm not terribly certain about this one, but I
  figure people with old glibc also have old procps.
* Ensured reading cmd output is buffered. We do a lot of getc() from it.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:30:38 +11:00
Roman Žilka
607a0625a4 watch: Multiple bugs fixed (mostly about -g/-q/-d/-c), run_command() simplified greatly
* Moved character printing out of run_command() and into a new function to clean
  run_command() up and isolate self-contained functionality.
* Main loops in run_command() simplified greatly.
* Bugs fixed:
  * -g and -q now coexist well (both apply). Formerly, "watch -g -q X" with cmd
    output changing would act as "watch -q X" with cmd output not changing.
  * -d highlight no longer removes color.
  * -c together with -d no longer mark the entire screen as ever-changing.
  * malloc() of "wcommand" in main() corrrected (sizeof(item_ptr) ->
    sizeof(*item_ptr)). Also present in a commit in another merge request, but
    I could no longer keep scrolling over it.
  * -q counter now restarts when terminal size changes. That puts it in sync
    with the lifecycle of first_screen and prevents the counter from progressing
    extra fast due to the frequent restarts of the command during the resizing.
* Regression within topic branch: -g is no longer ignored.
* Larger blank areas are now drawn using dedicated ncurses routines, resulting,
  I presume, in faster & cheaper operation. Not confirmed.
* Manpage:
  * Changed the -x option description. The old one made it seem like it's the
    same thing, only better and everyone wants it, disregarding the fact that
    it behaves differently and that this difference is probably more important
    than the convenience regarding quoting.
  * fgrep is obsolete, in GNU grep at least.
  * Made the BUG "Non-printing characters..." into a NOTE. Some common
    non-printables are actually accounted for and the others would probably ruin
    the day of half the people.
  * Reduced the BUG "Upon terminal resize..." The screen does get repainted when
    its dimensions change. The -r is intended to prevent the screen from
    repainting.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:29:04 +11:00
Roman Žilka
22e729be9f watch: Avoid re-computing strlen(command) when displaying header
* Avoid re-computing strlen(command) every time header is printed.
* Regression within topic branch: diff once again accounts for blank space.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:27:17 +11:00
Roman Žilka
e4315b9ab8 watch: Blank lines after very long lines now display properly (one of BUGS)
* Fixed bug from watch(1): "Blank lines directly after a line which ends in the
  last column do not display."
* Cursor is now hidden.
* Bug from watch(1) involving missing compound characters may have been fixed as
  well. I can see no issues with canonically decomposed characters in UTF-8, if
  that's what it's regarding. The BUGS stays, however, until this is confirmed.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:25:56 +11:00
Roman Žilka
49932b9dc3 watch: Code cleanup, minor optim.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:24:22 +11:00
Roman Žilka
eb24b63440 watch: Fixed output errors when --no-wrap and blank lines or wide wchars [#285]
Errors fixed when --no-wrap:
* empty line following a truncated line omitted from output
* overlong line isn't truncated when the truncation should happen "in the
  middle" of a wide (wcwidth) wchar

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:22:49 +11:00
Roman Žilka
0e472f791c watch: minor optimisations and fixes
Minor optimisations (narrower types)
Fixed indentation
minor fixes (wcwidth() only if not WEOF, wint_t accessed as *(wchar_t *)&var)

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:21:33 +11:00
Roman Žilka
67284cb719 watch: my_getwc(): errors when char signed/unsigned, off-by-one in ungetc(), ...
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:19:02 +11:00
Roman Žilka
03aa5d371c watch: Inserted a missing !8bit segment in run_command(); reduced 8bit ifdefs with finer macros
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:12:37 +11:00
Roman Žilka
6884420264 str*dup()->xstr*dup() where needed; library: openproc(): avoid closedir(NULL) 2023-10-06 05:03:30 +00:00
Roman Žilka
b5db042e54 library/stat: Avoid smaller_int=huge_ULL in delta calc. due to newval<oldval 2023-10-05 15:22:21 +02:00
Roman Žilka
30cd16af3a vmstat: Type correction in stat output, in update counter 2023-10-05 15:22:21 +02:00