macpm 3.4.0__tar.gz → 3.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. {macpm-3.4.0 → macpm-3.4.1}/CHANGELOG.md +19 -0
  2. {macpm-3.4.0/macpm.egg-info → macpm-3.4.1}/PKG-INFO +3 -3
  3. {macpm-3.4.0 → macpm-3.4.1}/README.md +2 -2
  4. {macpm-3.4.0 → macpm-3.4.1}/RELEASE.md +14 -14
  5. {macpm-3.4.0 → macpm-3.4.1}/macpm/__init__.py +1 -1
  6. {macpm-3.4.0 → macpm-3.4.1}/macpm/modelview.py +4 -1
  7. {macpm-3.4.0 → macpm-3.4.1}/macpm/serviceregistry.py +77 -13
  8. {macpm-3.4.0 → macpm-3.4.1/macpm.egg-info}/PKG-INFO +3 -3
  9. {macpm-3.4.0 → macpm-3.4.1}/setup.py +1 -1
  10. {macpm-3.4.0 → macpm-3.4.1}/tests/test_discovery_real.py +4 -7
  11. {macpm-3.4.0 → macpm-3.4.1}/tests/test_modelview.py +37 -1
  12. {macpm-3.4.0 → macpm-3.4.1}/tests/test_netns.py +9 -15
  13. {macpm-3.4.0 → macpm-3.4.1}/tests/test_serviceregistry.py +95 -0
  14. {macpm-3.4.0 → macpm-3.4.1}/LICENSE +0 -0
  15. {macpm-3.4.0 → macpm-3.4.1}/MANIFEST.in +0 -0
  16. {macpm-3.4.0 → macpm-3.4.1}/docs/linux-port.md +0 -0
  17. {macpm-3.4.0 → macpm-3.4.1}/docs/model-view-eval.md +0 -0
  18. {macpm-3.4.0 → macpm-3.4.1}/macpm/__main__.py +0 -0
  19. {macpm-3.4.0 → macpm-3.4.1}/macpm/backend.py +0 -0
  20. {macpm-3.4.0 → macpm-3.4.1}/macpm/blessed_engine.py +0 -0
  21. {macpm-3.4.0 → macpm-3.4.1}/macpm/capabilities.py +0 -0
  22. {macpm-3.4.0 → macpm-3.4.1}/macpm/dump.py +0 -0
  23. {macpm-3.4.0 → macpm-3.4.1}/macpm/footprint.py +0 -0
  24. {macpm-3.4.0 → macpm-3.4.1}/macpm/gpuview.py +0 -0
  25. {macpm-3.4.0 → macpm-3.4.1}/macpm/ioreport.py +0 -0
  26. {macpm-3.4.0 → macpm-3.4.1}/macpm/linux_backend/__init__.py +0 -0
  27. {macpm-3.4.0 → macpm-3.4.1}/macpm/linux_backend/cpu.py +0 -0
  28. {macpm-3.4.0 → macpm-3.4.1}/macpm/linux_backend/gpu.py +0 -0
  29. {macpm-3.4.0 → macpm-3.4.1}/macpm/linux_backend/modelname.py +0 -0
  30. {macpm-3.4.0 → macpm-3.4.1}/macpm/linux_backend/net.py +0 -0
  31. {macpm-3.4.0 → macpm-3.4.1}/macpm/linux_backend/power.py +0 -0
  32. {macpm-3.4.0 → macpm-3.4.1}/macpm/linux_backend/proc.py +0 -0
  33. {macpm-3.4.0 → macpm-3.4.1}/macpm/linux_backend/sampler.py +0 -0
  34. {macpm-3.4.0 → macpm-3.4.1}/macpm/linux_backend/soc.py +0 -0
  35. {macpm-3.4.0 → macpm-3.4.1}/macpm/linux_backend/sysfs.py +0 -0
  36. {macpm-3.4.0 → macpm-3.4.1}/macpm/linux_backend/thermal.py +0 -0
  37. {macpm-3.4.0 → macpm-3.4.1}/macpm/macos_gpu.py +0 -0
  38. {macpm-3.4.0 → macpm-3.4.1}/macpm/macpm.py +0 -0
  39. {macpm-3.4.0 → macpm-3.4.1}/macpm/metrics.py +0 -0
  40. {macpm-3.4.0 → macpm-3.4.1}/macpm/modelfeed.py +0 -0
  41. {macpm-3.4.0 → macpm-3.4.1}/macpm/modellog.py +0 -0
  42. {macpm-3.4.0 → macpm-3.4.1}/macpm/netinfo.py +0 -0
  43. {macpm-3.4.0 → macpm-3.4.1}/macpm/netmodel.py +0 -0
  44. {macpm-3.4.0 → macpm-3.4.1}/macpm/network.py +0 -0
  45. {macpm-3.4.0 → macpm-3.4.1}/macpm/probe.py +0 -0
  46. {macpm-3.4.0 → macpm-3.4.1}/macpm/processes.py +0 -0
  47. {macpm-3.4.0 → macpm-3.4.1}/macpm/sampler.py +0 -0
  48. {macpm-3.4.0 → macpm-3.4.1}/macpm/sensors.py +0 -0
  49. {macpm-3.4.0 → macpm-3.4.1}/macpm/smc.py +0 -0
  50. {macpm-3.4.0 → macpm-3.4.1}/macpm/soc.py +0 -0
  51. {macpm-3.4.0 → macpm-3.4.1}/macpm/theme.py +0 -0
  52. {macpm-3.4.0 → macpm-3.4.1}/macpm/tui.py +0 -0
  53. {macpm-3.4.0 → macpm-3.4.1}/macpm/widgets.py +0 -0
  54. {macpm-3.4.0 → macpm-3.4.1}/macpm.egg-info/SOURCES.txt +0 -0
  55. {macpm-3.4.0 → macpm-3.4.1}/macpm.egg-info/dependency_links.txt +0 -0
  56. {macpm-3.4.0 → macpm-3.4.1}/macpm.egg-info/entry_points.txt +0 -0
  57. {macpm-3.4.0 → macpm-3.4.1}/macpm.egg-info/not-zip-safe +0 -0
  58. {macpm-3.4.0 → macpm-3.4.1}/macpm.egg-info/requires.txt +0 -0
  59. {macpm-3.4.0 → macpm-3.4.1}/macpm.egg-info/top_level.txt +0 -0
  60. {macpm-3.4.0 → macpm-3.4.1}/packaging/README-linux.txt +0 -0
  61. {macpm-3.4.0 → macpm-3.4.1}/packaging/README.txt +0 -0
  62. {macpm-3.4.0 → macpm-3.4.1}/packaging/build-linux.sh +0 -0
  63. {macpm-3.4.0 → macpm-3.4.1}/packaging/build.sh +0 -0
  64. {macpm-3.4.0 → macpm-3.4.1}/packaging/entry_tui.py +0 -0
  65. {macpm-3.4.0 → macpm-3.4.1}/packaging/install.sh +0 -0
  66. {macpm-3.4.0 → macpm-3.4.1}/packaging/linux/Dockerfile +0 -0
  67. {macpm-3.4.0 → macpm-3.4.1}/packaging/linux/README.txt +0 -0
  68. {macpm-3.4.0 → macpm-3.4.1}/packaging/macpm-linux.spec +0 -0
  69. {macpm-3.4.0 → macpm-3.4.1}/packaging/macpm.command +0 -0
  70. {macpm-3.4.0 → macpm-3.4.1}/pyproject.toml +0 -0
  71. {macpm-3.4.0 → macpm-3.4.1}/setup.cfg +0 -0
  72. {macpm-3.4.0 → macpm-3.4.1}/tests/__init__.py +0 -0
  73. {macpm-3.4.0 → macpm-3.4.1}/tests/linux_fixtures.py +0 -0
  74. {macpm-3.4.0 → macpm-3.4.1}/tests/test_ane.py +0 -0
  75. {macpm-3.4.0 → macpm-3.4.1}/tests/test_blessed_engine.py +0 -0
  76. {macpm-3.4.0 → macpm-3.4.1}/tests/test_calc_freq.py +0 -0
  77. {macpm-3.4.0 → macpm-3.4.1}/tests/test_cli.py +0 -0
  78. {macpm-3.4.0 → macpm-3.4.1}/tests/test_containerlog.py +0 -0
  79. {macpm-3.4.0 → macpm-3.4.1}/tests/test_footprint.py +0 -0
  80. {macpm-3.4.0 → macpm-3.4.1}/tests/test_gpudiscovery.py +0 -0
  81. {macpm-3.4.0 → macpm-3.4.1}/tests/test_gpuview.py +0 -0
  82. {macpm-3.4.0 → macpm-3.4.1}/tests/test_kubelog.py +0 -0
  83. {macpm-3.4.0 → macpm-3.4.1}/tests/test_layout.py +0 -0
  84. {macpm-3.4.0 → macpm-3.4.1}/tests/test_linux_cpu.py +0 -0
  85. {macpm-3.4.0 → macpm-3.4.1}/tests/test_linux_gpu.py +0 -0
  86. {macpm-3.4.0 → macpm-3.4.1}/tests/test_linux_ixsmi.py +0 -0
  87. {macpm-3.4.0 → macpm-3.4.1}/tests/test_linux_modelname.py +0 -0
  88. {macpm-3.4.0 → macpm-3.4.1}/tests/test_linux_net.py +0 -0
  89. {macpm-3.4.0 → macpm-3.4.1}/tests/test_linux_nvidia.py +0 -0
  90. {macpm-3.4.0 → macpm-3.4.1}/tests/test_linux_power.py +0 -0
  91. {macpm-3.4.0 → macpm-3.4.1}/tests/test_linux_sampler.py +0 -0
  92. {macpm-3.4.0 → macpm-3.4.1}/tests/test_linux_thermal.py +0 -0
  93. {macpm-3.4.0 → macpm-3.4.1}/tests/test_linux_view.py +0 -0
  94. {macpm-3.4.0 → macpm-3.4.1}/tests/test_linux_wiring.py +0 -0
  95. {macpm-3.4.0 → macpm-3.4.1}/tests/test_macos_gpu.py +0 -0
  96. {macpm-3.4.0 → macpm-3.4.1}/tests/test_modelfeed.py +0 -0
  97. {macpm-3.4.0 → macpm-3.4.1}/tests/test_modellog.py +0 -0
  98. {macpm-3.4.0 → macpm-3.4.1}/tests/test_modellog_vllm.py +0 -0
  99. {macpm-3.4.0 → macpm-3.4.1}/tests/test_netinfo.py +0 -0
  100. {macpm-3.4.0 → macpm-3.4.1}/tests/test_network.py +0 -0
  101. {macpm-3.4.0 → macpm-3.4.1}/tests/test_power_panel.py +0 -0
  102. {macpm-3.4.0 → macpm-3.4.1}/tests/test_probe.py +0 -0
  103. {macpm-3.4.0 → macpm-3.4.1}/tests/test_process_linux.py +0 -0
  104. {macpm-3.4.0 → macpm-3.4.1}/tests/test_processes.py +0 -0
  105. {macpm-3.4.0 → macpm-3.4.1}/tests/test_sampler.py +0 -0
  106. {macpm-3.4.0 → macpm-3.4.1}/tests/test_sampler_macos.py +0 -0
  107. {macpm-3.4.0 → macpm-3.4.1}/tests/test_sensors.py +0 -0
  108. {macpm-3.4.0 → macpm-3.4.1}/tests/test_theme.py +0 -0
  109. {macpm-3.4.0 → macpm-3.4.1}/tests/test_widgets.py +0 -0
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.4.1 — 2026-12-06
4
+
5
+ ### Fixed
6
+
7
+ - Model view: a service that only shows up on a later rescan — a server started
8
+ after the view was opened, or one that is being restarted or upgraded — is
9
+ polled as soon as it is listed. The feed used to be bound only on `6`,
10
+ `↑/↓`, `s` or `r`, so the detail card stayed `unverified · polling starts with
11
+ the selection` with `model -` and empty Decode/Context cards until a key was
12
+ pressed, even though the server was answering.
13
+ - Model view on macOS: the `MODEL` column keeps the name instead of showing
14
+ `-`. Discovery groups processes by network namespace through
15
+ `/proc/<pid>/ns/net` and names a service through `/proc/<pid>/net/tcp`, and
16
+ neither exists on macOS, so the app-bundle launcher's `-` placeholder won
17
+ over the name its server process carried. Endpoints are now read from
18
+ psutil's socket table where `/proc` is absent, and a placeholder never beats a
19
+ real model name when one pod's rows are merged — so a Splash or oMLX server
20
+ started from the desktop app is named without a `--model` flag.
21
+
3
22
  ## 3.4.0 — 2026-11-28
4
23
 
5
24
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: macpm
3
- Version: 3.4.0
3
+ Version: 3.4.1
4
4
  Summary: Performance monitoring CLI for Apple Silicon and Linux
5
5
  Home-page: https://github.com/visualcjy/macpm
6
6
  Author: Jinyu Chen
@@ -399,7 +399,7 @@ shows `n/a` and the reason stays in the data
399
399
 
400
400
  A single-GPU machine keeps the older layout: card summary on top, process table
401
401
  below. Every view's footer starts with the app name and version
402
- (`macpm v3.4.0 · q quit …`).
402
+ (`macpm v3.4.1 · q quit …`).
403
403
 
404
404
  ```text
405
405
  ┌ GPU INFO ────────────────────────────────────────────────────────────────────────────────┐
@@ -413,7 +413,7 @@ below. Every view's footer starts with the app name and version
413
413
  │ └ 222 Xorg 2.0G │
414
414
  │ 2 AMD GPU (amdgpu) ▉▉▉▉▏▏ 60% 1100/1750 12.0W ▉▉▉▉▏▏▏▏▏▏ 3.0G/8.0G 46°C │
415
415
  │ 3 AMD GPU (amdgpu) ▉▉▉▉▉▏ 85% 1200/1750 12.0W ▉▉▉▉▉▏▏▏▏▏ 4.0G/8.0G 49°C │
416
- └ macpm v3.4.0 · q quit 1-5 view s sort ↑/↓ page Space pause ←/→ colour ────────────────┘
416
+ └ macpm v3.4.1 · q quit 1-5 view s sort ↑/↓ page Space pause ←/→ colour ────────────────┘
417
417
  ```
418
418
 
419
419
  | Platform | What fills each row |
@@ -357,7 +357,7 @@ shows `n/a` and the reason stays in the data
357
357
 
358
358
  A single-GPU machine keeps the older layout: card summary on top, process table
359
359
  below. Every view's footer starts with the app name and version
360
- (`macpm v3.4.0 · q quit …`).
360
+ (`macpm v3.4.1 · q quit …`).
361
361
 
362
362
  ```text
363
363
  ┌ GPU INFO ────────────────────────────────────────────────────────────────────────────────┐
@@ -371,7 +371,7 @@ below. Every view's footer starts with the app name and version
371
371
  │ └ 222 Xorg 2.0G │
372
372
  │ 2 AMD GPU (amdgpu) ▉▉▉▉▏▏ 60% 1100/1750 12.0W ▉▉▉▉▏▏▏▏▏▏ 3.0G/8.0G 46°C │
373
373
  │ 3 AMD GPU (amdgpu) ▉▉▉▉▉▏ 85% 1200/1750 12.0W ▉▉▉▉▉▏▏▏▏▏ 4.0G/8.0G 49°C │
374
- └ macpm v3.4.0 · q quit 1-5 view s sort ↑/↓ page Space pause ←/→ colour ────────────────┘
374
+ └ macpm v3.4.1 · q quit 1-5 view s sort ↑/↓ page Space pause ←/→ colour ────────────────┘
375
375
  ```
376
376
 
377
377
  | Platform | What fills each row |
@@ -1,4 +1,4 @@
1
- # Releasing macpm 3.4.0
1
+ # Releasing macpm 3.4.1
2
2
 
3
3
  This checklist prepares a GitHub tag and a PyPI upload. It does not push or
4
4
  publish anything by itself.
@@ -7,11 +7,11 @@ publish anything by itself.
7
7
 
8
8
  - macOS Apple Silicon, Python 3.9+.
9
9
  - Clean working tree (`git status`), all tests passing.
10
- - Version is `3.4.0` in:
10
+ - Version is `3.4.1` in:
11
11
  - `setup.py`
12
12
  - `macpm/__init__.py` (`__version__`)
13
13
  - the banner and `--version` derive from it (`macpm/macpm.py`)
14
- - `CHANGELOG.md` has the `3.4.0` entry.
14
+ - `CHANGELOG.md` has the `3.4.1` entry.
15
15
 
16
16
  ## 2. Test from source
17
17
 
@@ -38,7 +38,7 @@ Test the wheel in a **clean** venv (this is the real "no source tree" test):
38
38
 
39
39
  ```sh
40
40
  python3 -m venv /tmp/macpm-wheel-test
41
- /tmp/macpm-wheel-test/bin/pip install dist/macpm-3.3.1-py3-none-any.whl
41
+ /tmp/macpm-wheel-test/bin/pip install dist/macpm-3.4.1-py3-none-any.whl
42
42
  /tmp/macpm-wheel-test/bin/macpm --help
43
43
  /tmp/macpm-wheel-test/bin/macpm-dump # Ctrl+C
44
44
  ```
@@ -78,13 +78,13 @@ Manual alternative (fallback, e.g. when OIDC is unavailable):
78
78
  ```sh
79
79
  # requires a PyPI API token in ~/.pypirc or TWINE_PASSWORD
80
80
  python3 -m twine upload --non-interactive \
81
- dist/macpm-3.3.1.tar.gz dist/macpm-3.3.1-py3-none-any.whl
81
+ dist/macpm-3.4.1.tar.gz dist/macpm-3.4.1-py3-none-any.whl
82
82
  ```
83
83
 
84
84
  Then verify:
85
85
 
86
86
  ```sh
87
- python3 -m pip install --upgrade macpm==3.4.0
87
+ python3 -m pip install --upgrade macpm==3.4.1
88
88
  macpm --version
89
89
  ```
90
90
 
@@ -93,10 +93,10 @@ macpm --version
93
93
  ```sh
94
94
  git add setup.py pyproject.toml MANIFEST.in README.md CHANGELOG.md RELEASE.md \
95
95
  macpm packaging tests .github bin
96
- git commit -m "Release macpm 3.4.0: macOS 27 power fallback and GPU sort fixes"
97
- git tag -a v3.3.1 -m "macpm 3.4.0"
96
+ git commit -m "Release macpm 3.4.1: model view polling and macOS discovery fixes"
97
+ git tag -a v3.4.1 -m "macpm 3.4.1"
98
98
  git push origin main
99
- git push origin v3.3.1
99
+ git push origin v3.4.1
100
100
  ```
101
101
 
102
102
  The `Release` workflow builds the sdist/wheel, checks metadata and attaches
@@ -122,7 +122,7 @@ PYTHON=python3 packaging/build.sh
122
122
  This produces:
123
123
 
124
124
  ```text
125
- dist/macpm-3.3.1-macos-arm64.tar.gz
125
+ dist/macpm-3.4.1-macos-arm64.tar.gz
126
126
  ```
127
127
 
128
128
  Attach it to the GitHub release. The binaries are ad-hoc signed, not
@@ -148,10 +148,10 @@ The first run downloads python-build-standalone (cached in
148
148
  `~/.cache/macpm-build/pbs`) and produces:
149
149
 
150
150
  ```text
151
- dist/macpm-3.3.1-linux-x86_64.tar.gz
152
- dist/macpm-3.3.1-linux-aarch64.tar.gz
153
- dist/macpm_3.3.1_amd64.deb
154
- dist/macpm_3.3.1_arm64.deb
151
+ dist/macpm-3.4.1-linux-x86_64.tar.gz
152
+ dist/macpm-3.4.1-linux-aarch64.tar.gz
153
+ dist/macpm_3.4.1_amd64.deb
154
+ dist/macpm_3.4.1_arm64.deb
155
155
  ```
156
156
 
157
157
  Both architectures keep a glibc 2.17 floor. Building x86_64 on an arm64 host
@@ -1,3 +1,3 @@
1
1
  """macpm: rootless performance monitor for Apple Silicon."""
2
2
 
3
- __version__ = "3.4.0"
3
+ __version__ = "3.4.1"
@@ -268,7 +268,6 @@ class ModelView:
268
268
  """Force a rescan (``r``)."""
269
269
  self._replace(self.registry.discover(force=True))
270
270
  self._last_scan = time.monotonic()
271
- self.feed.select(self.selected())
272
271
 
273
272
  def cycle_sort(self) -> None:
274
273
  index = (_SORTS.index(self.sort) + 1) % len(_SORTS) if self.sort in _SORTS else 0
@@ -308,6 +307,10 @@ class ModelView:
308
307
  self.index = position
309
308
  break
310
309
  self._clamp()
310
+ # A row that only appeared on this scan (a server that just started, or
311
+ # one that is being restarted) must be polled at once, otherwise the
312
+ # detail card stays "unverified" until the next keypress.
313
+ self._sync_feed()
311
314
 
312
315
  def _clamp(self) -> None:
313
316
  count = len(self.services)
@@ -110,6 +110,13 @@ def _basename_model(path: str) -> str:
110
110
  return base or "-"
111
111
 
112
112
 
113
+ def _prefer_named(current: str, candidate: str) -> str:
114
+ """Keep the first real model name; ``"-"`` is only a placeholder."""
115
+ if current and current != "-":
116
+ return current
117
+ return candidate or current
118
+
119
+
113
120
  def identify(argv: list) -> Optional[Backend]:
114
121
  """Backend named by one command line, or ``None``."""
115
122
  if not argv:
@@ -196,10 +203,12 @@ def parse_endpoint(text: str) -> Optional[tuple]:
196
203
 
197
204
 
198
205
  class ServiceRegistry:
199
- """Cached, HTTP-free service discovery.
206
+ """Cached service discovery that only names what a socket or API proves.
200
207
 
201
- ``process_source`` returns ``[(pid, argv), ...]``; ``prober`` decides
202
- whether ``host:port`` is listening. Both are injectable for tests.
208
+ ``process_source`` returns ``[(pid, argv), ...]``, ``prober`` decides
209
+ whether ``host:port`` is listening, ``listeners`` lists a process' own
210
+ listening sockets and ``identity`` reads ``/v1/models``. All four are
211
+ injectable for tests.
203
212
  """
204
213
 
205
214
  def __init__(
@@ -213,6 +222,8 @@ class ServiceRegistry:
213
222
  gpu_source: Optional[Callable[[], list]] = None,
214
223
  validate_api: bool = False,
215
224
  api_probe: Optional[Callable[[str, int], bool]] = None,
225
+ listeners: Optional[Callable[[int], list]] = None,
226
+ identity: Optional[Callable[[str, int], tuple]] = None,
216
227
  ):
217
228
  self.clock = clock
218
229
  self.ttl = max(0.0, float(ttl))
@@ -223,6 +234,8 @@ class ServiceRegistry:
223
234
  self._gpu_source = gpu_source
224
235
  self.validate_api = validate_api
225
236
  self._api_probe = api_probe or _api_probe
237
+ self._listeners = listeners or _listening_ports
238
+ self._identity = identity or _api_identity
226
239
  self._endpoints: dict = {}
227
240
  self._services: list = []
228
241
  self._cached_at = -1e9
@@ -254,9 +267,9 @@ class ServiceRegistry:
254
267
  service.family = _BY_KEY[backend].family
255
268
  return
256
269
  for pid in service.pids:
257
- for ip, port in _candidate_ports(pid):
270
+ for ip, port in _candidate_ports(pid, self._listeners):
258
271
  host = ip if ip != "0.0.0.0" else (netns_address(pid) or LOCAL_HOST)
259
- alive, identity, owner = _api_identity(host, port)
272
+ alive, identity, owner = self._identity(host, port)
260
273
  if not alive:
261
274
  continue
262
275
  # The API is the only authority for model and backend; the
@@ -272,8 +285,9 @@ class ServiceRegistry:
272
285
  return
273
286
 
274
287
  def _scan(self) -> list:
275
- """One service per network namespace; the API names it, the GPU table
276
- attributes its cards, and processes only prove it exists."""
288
+ """One service per network namespace — per process where ``/proc`` is
289
+ absent, as on macOS. Command lines name it, the API confirms the name,
290
+ the GPU table attributes its cards and processes only prove it exists."""
277
291
  entries: dict = {}
278
292
 
279
293
  def entry(key: str) -> dict:
@@ -297,7 +311,7 @@ class ServiceRegistry:
297
311
  item = entry(_pod_key(pid))
298
312
  item["pids"].add(pid)
299
313
  item["backend"] = item["backend"] or backend.key
300
- item["model"] = item["model"] or parse_model(argv, backend)
314
+ item["model"] = _prefer_named(item["model"], parse_model(argv, backend))
301
315
  item["port"] = item["port"] or parse_port(argv, backend)
302
316
 
303
317
  for service in gpu_services(self._gpu_source):
@@ -307,7 +321,7 @@ class ServiceRegistry:
307
321
  item = entry(_pod_key(pid))
308
322
  item["gpu"] = True
309
323
  item["pids"].update(service.pids)
310
- item["model"] = item["model"] or service.model
324
+ item["model"] = _prefer_named(item["model"], service.model)
311
325
  item["backend"] = item["backend"] or service.backend
312
326
 
313
327
  services = []
@@ -361,6 +375,9 @@ class ServiceRegistry:
361
375
  merged[key] = service
362
376
  else:
363
377
  existing.pids = tuple(sorted(set(existing.pids) | set(service.pids)))
378
+ # The launcher process often carries no ``--model`` at all, and
379
+ # it is seen first: let a sibling name the service.
380
+ existing.model = _prefer_named(existing.model, service.model)
364
381
 
365
382
  merged = {
366
383
  key: service for key, service in merged.items()
@@ -396,12 +413,12 @@ def _pod_key(pid: int) -> str:
396
413
  return "pid:%d" % pid
397
414
 
398
415
 
399
- def _candidate_ports(pid: int):
416
+ def _candidate_ports(pid: int, source=None) -> list:
400
417
  """Service ports first, then the lowest non-ephemeral ones."""
401
418
  preferred = {8000, 8001, 8002, 8010, 8080, 9931, 11434, 30000, 30001}
402
- listeners = netns_listeners(pid)
403
- ordered = [entry for entry in listeners if entry[1] in preferred]
404
- ordered += sorted((entry for entry in listeners if entry[1] < 32768
419
+ found = (source or _listening_ports)(pid)
420
+ ordered = [entry for entry in found if entry[1] in preferred]
421
+ ordered += sorted((entry for entry in found if entry[1] < 32768
405
422
  and entry[1] not in preferred),
406
423
  key=lambda entry: entry[1])
407
424
  return ordered
@@ -526,6 +543,53 @@ def netns_address(pid: int) -> str:
526
543
  return ""
527
544
 
528
545
 
546
+ def _listening_ports(pid: int) -> list:
547
+ """Listening ``(ip, port)`` pairs of one process.
548
+
549
+ Linux reads the process' own network namespace from ``/proc``; macOS and
550
+ the other BSDs have no ``/proc``, so the sockets psutil reports for that
551
+ process are used instead (no root needed for your own user's servers).
552
+ """
553
+ pairs = netns_listeners(pid)
554
+ if pairs or os.path.isdir(PROC):
555
+ return pairs
556
+ return _host_listeners(pid)
557
+
558
+
559
+ def _host_listeners(pid: int) -> list:
560
+ """``(ip, port)`` for the sockets one process listens on, host namespace."""
561
+ try:
562
+ process = psutil.Process(pid)
563
+ net_connections = getattr(process, "net_connections",
564
+ getattr(process, "connections", None))
565
+ connections = net_connections(kind="tcp") if net_connections else []
566
+ except (psutil.Error, OSError, TypeError):
567
+ return []
568
+ pairs = []
569
+ for connection in connections or []:
570
+ if connection.status != psutil.CONN_LISTEN:
571
+ continue
572
+ address = connection.laddr
573
+ ip = _normalise_ip(getattr(address, "ip", "") or "")
574
+ if ip:
575
+ pairs.append((ip, int(getattr(address, "port", 0) or 0)))
576
+ return pairs
577
+
578
+
579
+ def _normalise_ip(ip: str) -> str:
580
+ """A host usable in ``host:port``; wildcards stay ``0.0.0.0``.
581
+
582
+ IPv6 literals would need brackets in a URL, so anything other than
583
+ loopback or IPv4 is reported as no listener at all.
584
+ """
585
+ ip = (ip or "").strip().lstrip("[").rstrip("]")
586
+ if ip in ("", "::", "0.0.0.0", "*"):
587
+ return "0.0.0.0"
588
+ if ip in ("::1", "localhost"):
589
+ return LOCAL_HOST
590
+ return "" if ":" in ip else ip
591
+
592
+
529
593
  def _api_probe(host: str, port: int, timeout: float = 1.2) -> bool:
530
594
  """Does this endpoint answer an OpenAI-style API (or ask for a key)?"""
531
595
  import urllib.error
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: macpm
3
- Version: 3.4.0
3
+ Version: 3.4.1
4
4
  Summary: Performance monitoring CLI for Apple Silicon and Linux
5
5
  Home-page: https://github.com/visualcjy/macpm
6
6
  Author: Jinyu Chen
@@ -399,7 +399,7 @@ shows `n/a` and the reason stays in the data
399
399
 
400
400
  A single-GPU machine keeps the older layout: card summary on top, process table
401
401
  below. Every view's footer starts with the app name and version
402
- (`macpm v3.4.0 · q quit …`).
402
+ (`macpm v3.4.1 · q quit …`).
403
403
 
404
404
  ```text
405
405
  ┌ GPU INFO ────────────────────────────────────────────────────────────────────────────────┐
@@ -413,7 +413,7 @@ below. Every view's footer starts with the app name and version
413
413
  │ └ 222 Xorg 2.0G │
414
414
  │ 2 AMD GPU (amdgpu) ▉▉▉▉▏▏ 60% 1100/1750 12.0W ▉▉▉▉▏▏▏▏▏▏ 3.0G/8.0G 46°C │
415
415
  │ 3 AMD GPU (amdgpu) ▉▉▉▉▉▏ 85% 1200/1750 12.0W ▉▉▉▉▉▏▏▏▏▏ 4.0G/8.0G 49°C │
416
- └ macpm v3.4.0 · q quit 1-5 view s sort ↑/↓ page Space pause ←/→ colour ────────────────┘
416
+ └ macpm v3.4.1 · q quit 1-5 view s sort ↑/↓ page Space pause ←/→ colour ────────────────┘
417
417
  ```
418
418
 
419
419
  | Platform | What fills each row |
@@ -7,7 +7,7 @@ README = (ROOT / "README.md").read_text(encoding="utf-8")
7
7
 
8
8
  setup(
9
9
  name="macpm",
10
- version="3.4.0",
10
+ version="3.4.1",
11
11
  author="Jinyu Chen",
12
12
  author_email="visualcjy@mail.com",
13
13
  url="https://github.com/visualcjy/macpm",
@@ -37,23 +37,20 @@ GPU = [
37
37
 
38
38
  class RealFixtureTests(unittest.TestCase):
39
39
  def setUp(self):
40
- self.saved = (module._pod_key, module._candidate_ports,
41
- module.netns_address, module._api_identity)
40
+ self.saved = (module._pod_key, module.netns_address)
42
41
  module._pod_key = lambda pid: NETNS.get(pid, "pid:%d" % pid)
43
- module._candidate_ports = lambda pid: PORTS[NETNS[pid]]
44
42
  module.netns_address = lambda pid: ADDRESS[NETNS[pid]]
45
- module._api_identity = (lambda host, port: IDENTITY.get(
46
- (host, port), (False, "", "")))
47
43
  self.registry = ServiceRegistry(
48
44
  process_source=lambda: list(PROCESSES),
49
45
  prober=lambda host, port: True,
50
46
  gpu_source=lambda: list(GPU),
51
47
  validate_api=True,
48
+ listeners=lambda pid: PORTS[NETNS[pid]],
49
+ identity=lambda host, port: IDENTITY.get((host, port), (False, "", "")),
52
50
  )
53
51
 
54
52
  def tearDown(self):
55
- (module._pod_key, module._candidate_ports,
56
- module.netns_address, module._api_identity) = self.saved
53
+ module._pod_key, module.netns_address = self.saved
57
54
 
58
55
  def test_three_services_not_five_rows(self):
59
56
  services = self.registry.discover(force=True)
@@ -7,7 +7,7 @@ import types
7
7
  import unittest
8
8
 
9
9
  from macpm.modelview import ModelView
10
- from macpm.modelfeed import ModelStats, RequestRow
10
+ from macpm.modelfeed import ModelFeed, ModelStats, RequestRow
11
11
  from macpm.serviceregistry import Service
12
12
 
13
13
 
@@ -147,6 +147,42 @@ class RenderTests(unittest.TestCase):
147
147
  view._replace([llama(), vllm()])
148
148
  self.assertEqual(view.selected().backend, "llama.cpp")
149
149
 
150
+ def test_a_row_that_appears_later_is_polled_without_a_keypress(self):
151
+ """A server that starts (or restarts) after the first scan is polled."""
152
+ registry = FakeRegistry([])
153
+ feed = ModelFeed(clock=lambda: 0.0, fetcher=lambda service, key: ModelStats(
154
+ state="live", model="Qwen3-8B-Instruct", decode_tps=61.4))
155
+ view = ModelView(registry=registry, feed=feed, no_color=True)
156
+ view.prime()
157
+ self.assertIsNone(feed.snapshot())
158
+
159
+ registry.services = [vllm()]
160
+ view._last_scan = 0.0
161
+ view.sample()
162
+ feed._thread.join(2)
163
+
164
+ self.assertEqual(feed.snapshot().state, "live")
165
+ self.assertIn("61.4 tok/s", self.render(view))
166
+
167
+ def test_a_row_hidden_by_a_restart_is_polled_when_it_returns(self):
168
+ registry = FakeRegistry([vllm()])
169
+ feed = ModelFeed(clock=lambda: 0.0, fetcher=lambda service, key: ModelStats(
170
+ state="live", model="Qwen3-8B-Instruct"))
171
+ view = ModelView(registry=registry, feed=feed, no_color=True)
172
+ view.prime()
173
+
174
+ registry.services = [] # the backend is being upgraded
175
+ view.refresh()
176
+ self.assertEqual([], view.services)
177
+
178
+ # The periodic rescan, not a keypress, brings the row back.
179
+ registry.services = [vllm()]
180
+ view._last_scan = 0.0
181
+ view.sample()
182
+ feed._thread.join(2)
183
+
184
+ self.assertEqual(feed.snapshot().state, "live")
185
+
150
186
  def test_selected_row_shows_the_live_rate(self):
151
187
  stats = ModelStats(state="live", decode_tps=61.4)
152
188
  view, output = self.make([vllm(), llama()], stats=stats)
@@ -31,21 +31,15 @@ class NetnsTests(unittest.TestCase):
31
31
  self.assertNotIn(("127.0.0.1", 54321), pairs) # not LISTEN
32
32
 
33
33
  def test_a_gpu_service_gets_the_endpoint(self):
34
- import macpm.serviceregistry as module
35
-
36
- original_ports = module._candidate_ports
37
- original_identity = module._api_identity
38
- module._candidate_ports = lambda pid: [("172.0.0.81", 30000)]
39
- module._api_identity = lambda host, port: (True, "Qwen3.8-27B-FP8", "sglang")
40
- try:
41
- registry = ServiceRegistry(process_source=lambda: [],
42
- prober=lambda host, port: True)
43
- service = Service("sglang", "prometheus", "127.0.0.1", 0,
44
- "Qwen3.8-27B-FP8", (42,), source="gpu")
45
- registry._fill_endpoint(service)
46
- finally:
47
- module._candidate_ports = original_ports
48
- module._api_identity = original_identity
34
+ registry = ServiceRegistry(
35
+ process_source=lambda: [],
36
+ prober=lambda host, port: True,
37
+ listeners=lambda pid: [("172.0.0.81", 30000)],
38
+ identity=lambda host, port: (True, "Qwen3.8-27B-FP8", "sglang"),
39
+ )
40
+ service = Service("sglang", "prometheus", "127.0.0.1", 0,
41
+ "Qwen3.8-27B-FP8", (42,), source="gpu")
42
+ registry._fill_endpoint(service)
49
43
 
50
44
  self.assertEqual((service.host, service.port), ("172.0.0.81", 30000))
51
45
  self.assertEqual(service.backend, "sglang") # owned_by wins
@@ -1,9 +1,13 @@
1
1
  """Service discovery sees command lines and a TCP probe, never HTTP."""
2
2
 
3
+ import os
4
+ import socket
3
5
  import unittest
4
6
 
5
7
  from macpm.serviceregistry import (
6
8
  ServiceRegistry,
9
+ _host_listeners,
10
+ _normalise_ip,
7
11
  identify,
8
12
  parse_endpoint,
9
13
  parse_model,
@@ -23,6 +27,20 @@ OMLX = ["/Users/x/.omlx/bin/omlx", "serve", "--model-dir", "/models"]
23
27
  SPLASH = ["/opt/homebrew/bin/splash", "serve",
24
28
  "--model", "unsloth/Qwen3.8-27B-GGUF:UD-Q4_K_M", "--port", "8099"]
25
29
 
30
+ # The Splash desktop app, as macOS reports it: the bundle launcher first (no
31
+ # ``--model`` at all), the python server second, the engine last.
32
+ SPLASH_APP = ["/Applications/Splash.app/Contents/MacOS/Splash"]
33
+ SPLASH_SERVER = [
34
+ "/Applications/Splash.app/Contents/Resources/splash/python/bin/python3",
35
+ "-u", "-P", "-m", "server.server",
36
+ "/Users/x/Library/Application Support/Splash/models/unsloth/Qwen4-35B-A3B-GGUF",
37
+ "--model", "unsloth/Qwen4-35B-A3B-GGUF:UD-Q4_K_M", "--port", "8000",
38
+ ]
39
+ SPLASH_ENGINE = [
40
+ "/Applications/Splash.app/Contents/Resources/splash/engine/splash",
41
+ "serve-native", "/models/.resolved/x.gguf", "auto",
42
+ ]
43
+
26
44
 
27
45
  class IdentifyTests(unittest.TestCase):
28
46
  def test_vllm_api_server(self):
@@ -164,6 +182,83 @@ class RegistryTests(unittest.TestCase):
164
182
  self.assertEqual(first.identity, second.identity)
165
183
  self.assertNotEqual(first.pids, second.pids)
166
184
 
185
+ def test_a_launcher_without_a_model_does_not_hide_its_server(self):
186
+ """macOS has no /proc/<pid>/ns/net, so each process is its own entry;
187
+ the bundle launcher is seen first and carries no ``--model``."""
188
+ import macpm.serviceregistry as module
189
+
190
+ original = module._pod_key
191
+ module._pod_key = lambda pid: "pid:%d" % pid
192
+ try:
193
+ registry = self.make([(10, SPLASH_APP), (11, SPLASH_SERVER),
194
+ (12, SPLASH_ENGINE)])
195
+ services = registry.discover(force=True)
196
+ finally:
197
+ module._pod_key = original
198
+
199
+ self.assertEqual(len(services), 1)
200
+ self.assertEqual(services[0].model, "unsloth/Qwen4-35B-A3B-GGUF:UD-Q4_K_M")
201
+ self.assertEqual(services[0].pids, (10, 11, 12))
202
+
203
+ def test_the_api_names_a_service_without_a_model_flag(self):
204
+ import macpm.serviceregistry as module
205
+
206
+ original = module.netns_address
207
+ module.netns_address = lambda pid: ""
208
+ try:
209
+ registry = ServiceRegistry(
210
+ process_source=source((10, SPLASH_APP)),
211
+ prober=lambda host, port: True,
212
+ listeners=lambda pid: [("0.0.0.0", 8000)],
213
+ identity=lambda host, port: (
214
+ True, "unsloth/Qwen4-35B-A3B-GGUF:UD-Q4_K_M", "splash"),
215
+ )
216
+ service = registry.discover(force=True)[0]
217
+ finally:
218
+ module.netns_address = original
219
+
220
+ self.assertEqual(service.endpoint, "127.0.0.1:8000")
221
+ self.assertEqual(service.model, "unsloth/Qwen4-35B-A3B-GGUF:UD-Q4_K_M")
222
+ self.assertEqual(service.backend, "splash")
223
+
224
+
225
+ class ListenerTests(unittest.TestCase):
226
+ def setUp(self):
227
+ self.listener = socket.socket()
228
+ self.listener.bind(("127.0.0.1", 0))
229
+ self.listener.listen(1)
230
+ self.port = self.listener.getsockname()[1]
231
+
232
+ def tearDown(self):
233
+ self.listener.close()
234
+
235
+ def test_sockets_are_found_without_proc(self):
236
+ """The macOS fallback: psutil reports this process' own listener."""
237
+ self.assertIn(("127.0.0.1", self.port), _host_listeners(os.getpid()))
238
+
239
+ def test_the_host_table_is_used_when_proc_is_absent(self):
240
+ import macpm.serviceregistry as module
241
+
242
+ original = module.PROC
243
+ module.PROC = "/nonexistent/proc" # macOS and the BSDs
244
+ try:
245
+ pairs = module._listening_ports(os.getpid())
246
+ finally:
247
+ module.PROC = original
248
+
249
+ self.assertIn(("127.0.0.1", self.port), pairs)
250
+
251
+ def test_a_pid_we_cannot_read_has_no_listeners(self):
252
+ self.assertEqual(_host_listeners(0), [])
253
+
254
+ def test_ipv6_and_wildcard_addresses_are_normalised(self):
255
+ self.assertEqual(_normalise_ip("0.0.0.0"), "0.0.0.0")
256
+ self.assertEqual(_normalise_ip("::"), "0.0.0.0")
257
+ self.assertEqual(_normalise_ip("::1"), "127.0.0.1")
258
+ self.assertEqual(_normalise_ip("127.0.0.1"), "127.0.0.1")
259
+ self.assertEqual(_normalise_ip("fe80::1"), "") # needs brackets
260
+ self.assertEqual(_normalise_ip(""), "0.0.0.0")
261
+
167
262
 
168
263
  if __name__ == "__main__":
169
264
  unittest.main()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes