887 Commits

Author SHA1 Message Date
Jeff Squyres
b8fb0df377 fix: avoid macOS swap disk crash [AI generated]
Skip the synthetic swap disk entry when collecting filesystem stats on macOS. The swap row is not a real mountpoint, so calling statvfs() on it fails and leaves the async disk-stat future in an error path.

Also release IOKit properties only when IORegistryEntryCreateCFProperties() succeeds and returns a valid object, avoiding an unsafe CFRelease() after failed property creation.
2026-06-01 11:11:05 -04:00
Jakob P. Liljenberg
568320f674 Merge pull request #1667 from zzallirog/feat/proc-tree-auto-collapse
proc: add proc_tree_auto_collapse option
2026-05-31 00:05:08 +02:00
zzalli
e79c7fbbe5 proc: add proc_tree_auto_collapse option
Auto-collapse processes with N or more direct children when entering
tree mode. Root-level processes (depth 0 and 1) are never collapsed.

Useful for multi-process apps like Chromium, Firefox, or Electron apps
that spawn dozens of subprocesses and clutter the tree view.

Default is 0 (disabled). Example: proc_tree_auto_collapse = 4
2026-05-31 00:37:02 +03:00
Jakob P. Liljenberg
41cd493b6b Merge pull request #1561 from Saphereye/unit-fix
Switch unit string literals to be SI compliant
2026-05-30 22:43:53 +02:00
Jakob P. Liljenberg
3d1d3493f6 Merge pull request #1661 from mgajda/feat/amd-igpu-sysfs-v2
[AI generated] AMD APU/iGPU sysfs backend for GPU monitoring
2026-05-30 22:30:06 +02:00
Jakob P. Liljenberg
88df2ca515 Merge pull request #1663 from jsquyres/fix/log-iso8601-timestamps
fix: use ISO 8601 format for log timestamps [AI generated]
2026-05-30 10:22:21 +02:00
Jakob P. Liljenberg
1cbaf92144 Merge pull request #1674 from jsquyres/fix/sigwinch-resize-reentry
fix: defer SIGWINCH resize handling [AI generated]
2026-05-30 10:20:42 +02:00
Jakob P. Liljenberg
2fb9796e6f Merge pull request #1658 from DerPlayer2001/main
Fix: Macos SIGABRT Crash during SMB TimeMachine Backups [AI generated]
2026-05-30 10:17:22 +02:00
Jakob P. Liljenberg
fd57e9c841 Merge pull request #1648 from NLagwal/fix-macos-regression
fix: gate Apple Silicon GPU support to unbreak intel Mac builds (#1641)
2026-05-30 10:12:39 +02:00
Jakob P. Liljenberg
2bc18e826e Merge pull request #1662 from jsquyres/fix/collector-futures
Fix possible thread deadlocks and power-event-based false stall detections
2026-05-30 10:11:22 +02:00
DerPlayer
2e7d8d395e Fix: Macos SIGABRT Crash during SMB TimeMachine Backups 2026-05-29 14:02:10 +02:00
Jakob P. Liljenberg
42267b32b6 Merge pull request #1652 from chiluk/chiluk/1651-fix-amd-gpu-graph
Fix btop with amd gpu on rocm 7 as in Ubuntu 26.04
2026-05-28 13:09:12 +02:00
Jeff Squyres
43bfed7202 fix: defer SIGWINCH resize handling [AI generated]
Avoid running the full terminal resize path from the signal handler so resize notifications cannot reenter term_resize() while it already holds its guard.
2026-05-24 09:26:21 -04:00
Jeff Squyres
08d722aa89 fix: make wait_for timeout suspend-aware [AI generated]
Change atomic_waiting_lock::wait_for() so its timeout is measured with
an uptime clock that pauses during system suspend, while still using the
condition variable for wakeups.

Previously, std::condition_variable::wait_for() owned the timeout. If
the system suspended while the main thread was waiting for the runner
to finish, the condition-variable timeout clock could include the
suspend duration (this definitely happens on macOS). On resume, the
wait could immediately time out even though the runner had only had
milliseconds of awake time to make progress.

The new uptime_micros() helper uses the best available clock on each
platform:

- macOS: CLOCK_UPTIME_RAW (pauses during Sleep/Deep Idle)
- FreeBSD: CLOCK_UPTIME (explicitly excludes suspend time)
- Linux/OpenBSD/NetBSD: CLOCK_MONOTONIC (excludes suspend on Linux;
  best available on other platforms)

This preserves the condition-variable locking model, but makes the
stall timeout count *awake* time rather than *wall clock* or *suspend*
time.

Co-authored-by: ItsMeSamey <sameychain5041@gmail.com>
2026-05-23 09:39:12 -04:00
Jeff Squyres
3c6cfda26a fix(osx): use futures for sensor collection, remove pthread_cancel [AI generated]
Replace synchronous IOKit HID sensor reads with std::async futures
and remove all pthread_cancel() calls from the runner stall-recovery
path. This addresses the macOS/NetBSD deadlocks reported in #1349.

The root cause of the deadlocks is that pthread_cancel() does not
reliably invoke C++ destructors on macOS (libc++) or NetBSD
(libstdc++), leaving mutexes and semaphore internals wedged when the
runner thread is cancelled mid-collection.

Sensor collection via futures:

  Wrap the IOKit HID thermal sensor reads (getSensors) and SMC
  temperature reads in a std::async future, following the same pattern
  already used for statvfs in the Linux disk collector. Each collection
  cycle checks if the previous cycle's future is ready (non-blocking),
  grabs the result if so, and launches a new async. Temperature
  readings are delayed by at most one collection cycle (~2s), which is
  imperceptible to users.

  This moves the dominant cost (~130ms mean, ~700ms worst case from
  77 Mach IPC roundtrips to IOKit HID sensors) off the runner's
  critical path, reducing the runner cycle from ~180ms to ~50ms.

Remove pthread_cancel from stall recovery:

  Replace the 5-second timeout + pthread_cancel + thread recreation
  logic with a 10-second warning + 30-second clean exit. If the runner
  is still stalled after 30 seconds (which should be nearly impossible
  with sensor reads off the critical path), btop exits cleanly rather
  than risking undefined behavior from pthread_cancel.

  This follows the maintainer's recommendation: remove pthread_cancel
  for BSD-derived platforms and exit with an error if the thread
  stalls, with an extended timeout to allow recovery from transient
  OS-level delays (sleep/wake transitions, IOKit contention).

  All three timeout sites are updated:
  - Runner::run(): 10s warning, 30s exit (was 5s + pthread_cancel)
  - Runner::stop(): 30s exit (was 5s)
  - Runner thread loop: 30s (was 5s)
  - clean_quit(): remove pthread_cancel fallback from thread join

Fixes #1349
2026-05-23 09:32:14 -04:00
ItsMeSamey
3b2149ed27 Merge remote-tracking branch 'origin/main' into locking_fix
# Conflicts:
#	src/btop_menu.cpp
2026-05-23 03:36:26 +10:00
Jordan Lambert
86ed12037a feat: map = to + to avoid having to press shift when increasing refresh rate (#1665) 2026-05-18 19:13:54 +00:00
Jeff Squyres
31d4c9c84f fix: use ISO 8601 format for log timestamps [AI generated]
Change log timestamps from the custom format to ISO 8601 with UTC
indicator:

  Before: 2026-05-14 (10:31:47) | DEBUG: ...
  After:  2026-05-14T10:31:47Z | DEBUG: ...

The previous format used parentheses around the time and omitted any
timezone indicator, making timestamps ambiguous. The logger uses
std::chrono::system_clock which measures time since Unix epoch (UTC
on all platforms), but the old format did not communicate this.

ISO 8601 with the Z suffix is an unambiguous, universally-recognized
format parseable by standard functions across languages:
- C++ (C++20): std::chrono::from_stream(ss, "%FT%TZ", tp)
- C: strptime(s, "%Y-%m-%dT%H:%M:%SZ", &tm)
- Python: datetime.fromisoformat("2026-05-14T10:31:47Z")

This matters for correlating btop log events with system logs (e.g.,
macOS pmset power events) that use local time with explicit timezone
offsets.
2026-05-17 16:46:24 -04:00
Michal J. Gajda
e2479bba01 [AI generated] feat(linux): AMD APU/iGPU sysfs backend for GPU monitoring
This PR is AI-assisted (per CONTRIBUTING.md disclosure requirement).
Reviewed and tested by the author; independently confirmed by @rnk.

Adds Gpu::Asysfs, a pure-sysfs fallback that activates only when
rocm-smi enumerates 0 AMD devices. Covers consumer hardware where
ROCm libraries are absent or /dev/kfd isn't loaded — typical for
APUs (Phoenix/Strix-class iGPUs) and older discrete cards no longer
supported by ROCm.

Closes #1643. Related: #1169, #1045, #956.

Scope is deliberately additive:
  * No change of behavior on hardware where rocm-smi already works.
  * Not a migration to amd-smi (#1196 remains open and warranted
    for the discrete-GPU case the sysfs path may not fully cover).
  * @rnk's parallel dlopen(libamd_smi.so) draft lives at
    https://github.com/rnk/btop/compare/main...amd-smi-sysfs as a
    complementary direction for discrete GPUs.

Reads only standard amdgpu DRM sysfs nodes — no library dependency,
no dlopen, pure file I/O:
  device/gpu_busy_percent     -> utilization
  device/mem_info_vram_*      -> VRAM total / used
  hwmon*/temp1_input          -> temperature (millidegrees -> degrees)
  hwmon*/freq1_input          -> core clock (Hz -> MHz)
  hwmon*/power1_average       -> power (microwatts -> milliwatts),
                                 falls back to power1_input

Filters by PCI vendor 0x1002 and driver=amdgpu, so does not collide
with nvidia/intel backends. Skips connector children (card1-DP-1)
and render nodes via filename pattern. Cards exposing no readable
signals (virtual GPUs, freshly-bound devices) are dropped at
enumeration rather than rendered as empty entries every tick.

Code follows CONTRIBUTING.md style: tabs of 4, alternative operators
(and/or/not), opening brace at line end, RAII (no raw resources;
std::filesystem::path / std::string / std::vector throughout),
std::ranges algorithms (all_of), fmt::format for the device-id
label, descriptive names, comments on non-obvious logic only.

Macros/files touched:
  src/btop.cpp               +1   (Asysfs::shutdown in clean_quit)
  src/btop_shared.hpp        +3   (forward declare Asysfs::shutdown)
  src/linux/btop_collect.cpp +218 (the backend)
  src/osx/btop_collect.cpp   +1   (no-op shutdown stub for the
                                   GPU_SUPPORT path used by Apple
                                   Silicon, so the macOS link works)

Tested on Strix-class iGPU (PCI 1002:150e, Radeon 780M variant):
  - btop displays "AMD GPU (1002:150e)" as gpu0
  - utilization, temperature, power, clock, VRAM used/total live-update
  - matches sysfs values within sampling jitter

Independently confirmed by @rnk on AMD APU Framework laptop.

Warning sweep clean under -Wall -Wextra -pedantic -Wconversion
-Wshadow -Wfloat-conversion (zero new warnings introduced).
2026-05-17 11:49:47 +00:00
Paul Meyer
30b3868787 themes: load/save by name if possible
This fixes #443 and a downstream issue in nixpkgs:
https://github.com/NixOS/nixpkgs/issues/460344

Short description of the latter issue: I nixpkgs, different versions
of btop are installed under different paths. If a user selects a
theme and it is saved to the config by its absolute path, that path
will be broken after an update.

To solve this, we allow writing the theme name only into the config,
and we save the theme by name if possible.

When selecting a theme, we check if it is the first (with respect to
the load oder priority: custom > user > system) match for this
filename in the list of available themes. If it is, we save it by
filename instead of using the full path. If there is another theme
with the same name and higher priority, we save using the full path.

This should also be compatible with the previous behavior of being
able to load themes by name from $XDG_CONFIG_PATH/btop/themes.

Signed-off-by: Paul Meyer <katexochen0@gmail.com>
2026-05-13 10:27:39 +02:00
ItsMeSamey
2c631e4c8f introduced seperate class for waiting with timeout 2026-05-09 19:15:44 +10:00
ItsMeSamey
312592f01e remove useless not_true flag and use single wakes 2026-05-09 17:24:52 +10:00
Dave Chiluk
07fff6c6cd Fix btop with amd gpu on rocm 7 as in Ubuntu 26.04
Fixes #1651

Signed-off-by: Dave Chiluk <chiluk@ubuntu.com>
2026-05-09 00:23:58 -05:00
ItsMeSamey
5aaca91b3b made fail ordering for atom.compare_exchange_strong to be relaxed 2026-05-08 15:17:43 +10:00
ItsMeSamey
327f69517d fix gpu devide name leak 2026-05-08 14:35:36 +10:00
ItsMeSamey
3843042b4f Donot call async-signal-unsafe function clean_quit inside of the signal handler 2026-05-08 03:41:03 +10:00
ItsMeSamey
88b0ed67e6 Fixed atomic primitives [well hopefully]
The original code used relaxed ordering which does not fence reordering.
Relaxed atomics infact are identical to volatile variables [on x86
atleast]
compare&swap was wrong too and not resetting the variable to false
correctly.
Stores were using strict ordering which is not actually required.
2026-05-08 03:22:34 +10:00
ItsMeSamey
677336f8ba found and fixed 2 more potential races 2026-05-08 02:15:50 +10:00
ItsMeSamey
557fbe519b fixed ui race 2026-05-08 01:52:33 +10:00
Nakul Lagwal
018afadd2b fix: fixed typo 2026-05-07 07:15:07 +00:00
Nakul Lagwal
1e7bb4205f fix: restore macOS headers and local includes for ARM builds 2026-05-07 07:12:41 +00:00
NLagwal
542f3d7f1f fix: gate Apple Silicon GPU support conditionally to unbreak intel Mac builds (#1641) 2026-05-07 12:31:15 +05:30
aristocratos
6e39144aaf v1.4.7 New features & Bug fixes 2026-05-01 18:05:43 +02:00
William Stoneham
3f91a9e736 fix: improve Apple Silicon temperature detection on macOS 2026-05-01 16:53:42 +02:00
aristocratos
ce408dd8ef Created function toggle_tree_collapse() in shared.cpp to reduce code duplication 2026-05-01 16:34:22 +02:00
jam
742fc854d8 fix(proc): force full collect on sort change in tree mode
When proc_tree is active and left/right changes the sort column,
no_update was left as true. _tree_gen is called with no_update=true,
which skips the p.filtered=true assignment for children of collapsed
nodes while the unconditional else-if on line 211 of btop_shared.cpp
clears their stale filtered flag from the previous cycle. This leaves
collapsed children in an inconsistent state for one frame, causing a
brief visual glitch before the next full update corrects it.

Setting no_update=false only in tree mode keeps the fast path for
flat list mode unchanged.
2026-05-01 16:00:01 +02:00
jam
e6d1b54a55 fix(proc): exclude root processes from E collapse/expand all
Root processes (those whose parent is not in the tracked process list,
e.g. launchd on macOS or a top-level colima) are now left untouched by
the E hotkey. Only their descendants are collapsed or expanded.

The toggle direction is also determined solely from non-root parents,
so a tree full of root-only visible rows correctly expands on the
next E press.
2026-05-01 16:00:01 +02:00
jam
f0cfe0980c feat(proc): add E hotkey to collapse/expand all tree nodes
Pressing E in tree mode collapses all processes if any parent is
currently expanded, or expands all if everything is already collapsed.
This gives a quick per-application resource summary without having
to manually toggle each node.

Implemented across all platforms (Linux, macOS, FreeBSD, OpenBSD, NetBSD).
2026-05-01 16:00:01 +02:00
Jakob P. Liljenberg
295fe59cb8 Merge pull request #1628 from seanniu93/fix-cpu-temp 2026-05-01 13:57:16 +02:00
aristocratos
ae278edd3b Remove code duplication 2026-05-01 13:26:51 +02:00
Jakob P. Liljenberg
c9b401b735 Merge pull request #1583 from sola-contrib/amd-temp-fix 2026-05-01 12:23:40 +02:00
aristocratos
b36357b0f1 Fixed missing CPU package temperature color (numeric value) 2026-05-01 12:20:22 +02:00
Jakob P. Liljenberg
5e93a50497 Merge pull request #1619 from busterb/fix-openbsd-smt-online-cpus 2026-05-01 12:06:54 +02:00
Patrick Wieschollek
169737fb86 Update src/btop_draw.cpp
Co-authored-by: dieter-apptronik <dieterbuys@apptronik.com>
2026-05-01 11:54:15 +02:00
Patrick Wieschollek
0bafa6fa71 Update src/btop_draw.cpp
Co-authored-by: dieter-apptronik <dieterbuys@apptronik.com>
2026-05-01 11:54:15 +02:00
patwie
ce0d5fffb4 [AI generated] fix: Clamp GPU graph widths to prevent crash on small terminals
When many GPUs are present and the terminal is small, the GPU graph
width calculations in Cpu::draw init_graphs and draw_graphs can
produce negative values. This causes std::out_of_range from the
Draw::Graph constructor, surfacing as "Exception in runner thread ->
Cpu:: -> deque".

The root cause is the remainder-distribution formula for the last GPU
graph: graph_width + graph_default_width%graph_width - gpus.size() + 1
which underflows when gpus.size() exceeds the available remainder plus
graph_width. The per-GPU graph_width itself can also go below 1 when
graph_default_width is small relative to gpu_draw_count.

Clamp both graph_width and the last-GPU width to a minimum of 1, and
clamp the cursor movement arguments in draw_graphs to prevent negative
Mv::l and Mv::r values.
2026-05-01 11:54:15 +02:00
aristocratos
7657384ed4 Fix cpu watt overflow in cpu box + division by zero fix for cpu.temp_max 2026-05-01 11:37:26 +02:00
Jakob P. Liljenberg
8f78fe1c4d Merge pull request #1598 from deniskhud/fix-non-ascii-proc 2026-05-01 10:16:19 +02:00
one
92cf853cdb fix: use static_cast 2026-05-01 10:00:59 +02:00
one
2899c58118 fix: correct shared gpu vram and power percentage calculations 2026-05-01 10:00:59 +02:00