Files
amethyst/amethyst
Claude aa34f9cb0e feat: track PoW, Tor, calls, decrypts, remote signs, and battery drain in the resource ledger
New counters for the app's remaining heavy battery consumers, all
transition-based so tracking never adds work to the activities measured:

- pow.ms/sessions: NIP-13 mining time from the PoW queue's isMining flow —
  the largest attributable CPU burner, previously an unattributed cpu.ms
  mystery
- tor.ms/starts: in-app Arti uptime from the raw TorService status (not
  TorManager.status, whose WhileSubscribed upstream would keep Tor's
  control flow alive if the ledger subscribed to it)
- service.alwayson.ms, call.ms/sessions, nests.ms/sessions: foreground
  service lifecycles for the always-on relay service, calls, and NIP-53
  audio rooms
- crypto.decrypt/encrypt.count+us and sign.local/nip46/nip55.count via a
  MeteringNostrSigner decorator wrapped inside NostrSignerWithClientTag at
  account load; crypto durations only metered for local-key signers so
  IPC/relay waits never poison the CPU numbers
- location.ms: GPS listening segments around LocationFlow collection
- battery.drain.fg/bg: measured percent-while-discharging sampled at each
  flush — the ground truth to correlate the other counters against

Ledger infrastructure hardening the new counters build on:

- all duration math now uses SystemClock.elapsedRealtime; wall-clock jumps
  (NTP, timezone) no longer fabricate or delete accounted time
- pre-flush-hook adds are drained in place and no longer re-arm the
  debounced flush, killing a self-perpetuating 30s wake-and-write loop
- drain is now AtomicLong.getAndSet(0) instead of remove+sum, closing a
  lost-update race that undercounted the hottest counters
- shared TimeSegmentIntegrator base extracted; relay/foreground integrators
  and the new SessionTimeIntegrator all use it
- @Volatile on LocalCache.verifyMeter (matching the onchainBackend
  precedent)

New counters surface in the usage screen (zero rows hidden), the NIP-17
report tables, and the per-day dump. 9 new unit tests including a
regression test for the flush loop.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016RJ8EAsdkHx5WHHU2eQJ1P
2026-07-13 15:56:03 +00:00
..